Is it useful to run multiple processes of the same app in Golang?

agolangf · · 682 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>In Python, a common way to improve throughput is to start multiple processes on the same machine. Think Tornado + supervisord + nginx.</p> <p>Nginx acts as a loadbalancer between the multiple processes spawned by supervisord. This is useful because Python is single threaded and this helps being in &#34;true&#34; concurrency from multiple processes.</p> <p>Does a similar setup help with Golang?</p> <hr/>**评论:**<br/><br/>hobbified: <pre><p>Test it and see. The go scheduler is far from perfect, so you might find that having two processes, each dealing with half as many goroutines, overcomes some bottleneck. Or you might not. You might also want to do it for non-performance-related reasons, such as zero-downtime upgrades or (hopefully not, but just in case) lowering the impact of crashes.</p></pre>cakehunter5000: <pre><p>I think you would almost always be better off using a single go process and running multiple goroutines (which the net/http server implementation will do without any extra work from you). Make sure you experiment with either the GOMAXPROCS env variable or using runtime.GOMAXPROCS to change number of real threads allocated. See <a href="http://golang.org/pkg/runtime/" rel="nofollow">http://golang.org/pkg/runtime/</a> for details.</p> <p>If you are just using nginx for load balancing among processes, you could likely also ditch that component for this type of setup. Of course, if you are using other features of nginx, feel free to leave it in place.</p> <p>In experiments last year, I was able to get about 750k requests/sec on a large EC2 instance with a single golang webserver and running wrk against it for simple responses.</p></pre>mwholt: <pre><p>Off topic, but I&#39;m curious how you pulled off 3/4 million requests per second.</p></pre>cakehunter5000: <pre><p>Sorry, I just checked my notes and the correct number was about 600k request/second. I just verified again using a simple &#39;hello world&#39; golang webapp with no custom settings besides changing GOMAXPROCS to 24 and see results from ./wrk -c 1000 -d 10 -t 10 http://localhost:8080/</p> <pre><code>Running 10s test @ http://localhost:8080/ 10 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 7.71ms 51.31ms 816.88ms 98.07% Req/Sec 60.89k 10.04k 84.01k 70.30% 6089332 requests in 10.07s, 1.40GB read Requests/sec: 604525.60 Transfer/sec: 141.82MB </code></pre> <p>This was on a c4.8xlarge, but I think I could have used smaller and gotten similar results. This is clearly a &#34;benchmark special&#34; result since I am running queries against localhost and doing no significant processing. The response above was primarily to answer the question about whether you need to run multiple golang processes compared to python based servers.</p></pre>

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

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