Could someone please tell me what I'm missing here?

polaris · · 159 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve taken to trying to write out the load balancer in <a href="" rel="nofollow">Rob Pike&#39;s talk</a> but I&#39;m unable to get it to push the workers to the <code>done</code> channel.</p> <p><a href="" 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&#39;s packed with debug junk.</p> <hr/>**评论:**<br/><br/>djherbis: <pre><p>You&#39;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&#39;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&#39;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&#39;s a mess. I&#39;ll try what you suggested and make an update/edit. </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

159 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传