<p>I've taken to trying to write out the load balancer in <a href="https://youtu.be/cN_DpYBzKso?list=LLJ85NIbMtBgxcJ5AZoL47EQ" rel="nofollow">Rob Pike's talk</a> but I'm unable to get it to push the workers to the <code>done</code> channel.</p>
<p><a href="https://gist.github.com/crwgregory/e5a9c4a039358c3d1c1ef26a35318451" rel="nofollow">Created a gist</a></p>
<p>I feel like this should be pushing the worker to the done channel of the balancer but there is obviously something I am missing. Sorry that the code is a mess, it's packed with debug junk.</p>
<hr/>**评论:**<br/><br/>djherbis: <pre><p>You've commented out the line in your requestor where you wait for the answer by recv on Request.c.</p>
<p>Notice that c is an unbuffered channel, and therefore you can't send without a recv call. This makes your workers send on req.c block forever.</p>
<p>Either make the request channel buffered (size 1 will be fine), or uncomment that wait for answer line.</p>
<p>(Note you will have to recv on that channel eventually, or else the buffer will fill after 1 worker has done its job, and you'll be right back where you started).</p></pre>justinisrael: <pre><p>Also it looks like a new work loop goroutine is spawned every time a request comes in. But by the look of the for loop, it would seem the workers would want to be spawned once during construction of the pool, so that they can continuously handle requests and signal when each one is done. </p></pre>pm_me_ur_disk_image: <pre><p>Thanks for looking at it. I had tried putting the channel creation in the loop where I instantiated the the work functions, but I think I had a similar issue.</p></pre>pm_me_ur_disk_image: <pre><p>Thank you for taking the time to look at it. :) :) I know it's a mess. I'll try what you suggested and make an update/edit. </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传