Two quick question about performance

agolangf · · 431 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<h1>1) n Goroutines <em>or</em> JobQueue</h1> <p>I have 1000 jobs that can be parallelized (http requests). Should I use 1000 Goroutines, or 10 Goroutines and a JobQueue? I&#39;m assuming the first one would be extremely expensive or am I wrong?</p> <h1>2) reuse 1 <code>http.Client</code> <em>or</em> create new</h1> <p>Should I reuse a single instance of <code>http.Client</code> for all 1000 jobs? Does creating a new Client have a big overhead?</p> <p>The problem is that worker <strong>plugins</strong> finish the jobs, so if I go with a single client, I&#39;d have to burden the interface and pass the client to the workers from the master. <em>I&#39;d prefer not to</em> unless creating multiple client has a big performance penalty.</p> <p>Thanks! :)</p> <hr/>**评论:**<br/><br/>recurrency: <pre><p>Write the code, measure it, profile it :)</p></pre>tmornini: <pre><p>1) either approach will work, but goroutine-per-request is either unbounded in memory use, or you’ll need to write limiter code, which would be harder to understand than the job queue approach.</p> <p>2) I don’t know the answer precisely, but <a href="https://awmanoj.github.io/tech/2016/12/16/keep-alive-http-requests-in-golang/" rel="nofollow">this article</a> seems to indicate that it’s ideal to reuse the same client as much as possible.</p></pre>

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

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