<p>Forgive the silly question, but, I am coming from a node background because quite frankly I am really sick of spinning up multiple instances and handling shared data with Redis. I just want to run one instance of my game per server and I heard GoLang can do that. I also heard Go blows node out of water doing it. And I've seen the benchmarks and it's really intriguing.</p>
<p>For example, a simple websocket server utilizing: <a href="https://godoc.org/golang.org/x/net/websocket" rel="nofollow">https://godoc.org/golang.org/x/net/websocket</a></p>
<p>Let's say, a player is in a game and 5 other players are in his same game. I will need to send movement signals to all other 5 players when player 1 moves. Would that have to be done through a go channel, or not because it's not really a cpu power hungry thing to do. But, when let's say there are hundrends of players online each sending data around... It probably would be a good idea, right? I'm kind of new and still learning channels and reading the Go documentation / tutorials, but that's the gist of that. Thanks for any advice ~</p>
<hr/>**评论:**<br/><br/>hayzeus: <pre><p>Channels are just used for communications. Goroutines are used for concurrency. By default (with go 1.5 and up), these will be multiplexed over as many os threads as you have cores. This number can be adjusted up or down depending on the setting of GOMAXPROCS. </p></pre>Fwippy: <pre><p>You don't need to use channels to communicate between goroutines, but it's a good idea up until the point that your server is too slow <em>and</em> CPU profiling shows that channel communication is a significant bottleneck.</p>
<p>Channels might not be the best solution to the "everyone broadcasts to everyone" setup you're envisioning, but the overhead isn't as much as you'd think.</p></pre>BillOReillyYUPokeMe: <pre><blockquote>
<p>Channels might not be the best solution to the "everyone broadcasts to everyone"</p>
</blockquote>
<p>When a player logs in, I usually send a message to all their friends on their friend list (that are online). I'm just not sure if I need to pass this through a goroutine. I got channels and goroutines mixed up in my title I think. </p></pre>xsolarwindx: <pre><p>Think of goroutines as threads. Channels are just queues. That's all they are underneath and that's exactly how they behave: thread safe first in first out queues. </p></pre>dinkumator: <pre><p>presumably you'll have 6 goroutines for each of the players' connections, so you'd probably want some channels or other way of distributing the movement signal to each of the other goroutines.</p></pre>TheDukeOfAnkh: <pre><p>From what I gathered about your use case, using go routines isn't the solution, since scalability will be a problem. What would happen when you have 100, 1000, 10000 players logged in? I think you should consider some of the pub-sub solutions that are out there.</p></pre>
[Question] - Do we always need to use go channels to take advantage of multiple cores?
agolangf · · 440 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传