Yet another golang nodejs comparison SPOILER #GOFAILS

blov · · 467 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi Lads, I&#39;ve passed last few days with a problem hammering my head and came here to ask a hand.</p> <p>I&#39;m plying around golang, yes I&#39;m loving it, but there is one test case scenario that it&#39;s not doing well and am trying ti guess what&#39;s wrong.</p> <p>Running both, go and nodejs, application as a http server with few routes to handle requesting and both querying for a collection on mongo and responding back to client, node performs three time over go in a stress test.</p> <p>Setup: GO - native net/http handler using mgo to query mongo, it converts the bson array via json.Marshal and then converts to a string. Mondo db connection is persistent via global var and before quety this connection is cloned or copied, it really doesn&#39;t make any difference in this case </p> <p>NODEJS - using restify to handle the requests and official mongodb driver which does a basic convert from dataset brought from mongo do an array and send back to client.</p> <p>I intent to publish my tests on github for better understanding, but for now I&#39;m looking forward suggestions of how to get it performing better or a guess of what could be happening.</p> <p>And yes, an answer saying why go doesn&#39;t excel on this scenario would be appreciate.</p> <hr/>**评论:**<br/><br/>bschwind: <pre><p>You&#39;re going to have to post the code if you want any meaningful discussion.</p></pre>0xjnml: <pre><blockquote> <p>And yes, an answer saying why go doesn&#39;t excel on this scenario would be appreciate.</p> </blockquote> <p>Quite probably because of your bad code/wrong design of the same. That&#39;s not an insult. That&#39;s exactly what I think about my code whenever it runs slower than expected. Not always true, but most often it is.</p></pre>dlsniper: <pre><blockquote> <p>for now I&#39;m looking forward suggestions of how to get it performing better or a guess of what could be happening.</p> </blockquote> <p>I can guess a dozen of reasons of why it would this happen but would guessing be of any help to anyone? As <a href="/u/bschwind" rel="nofollow">/u/bschwind</a> said: show me the code.</p> <p>I would at least expect Go to be on par with node on this, if not better.</p> <p>Also, which version of Go are you using?</p></pre>quirinux: <pre><p>So do I</p> <p>GO - go version go1.8.3 linux/amd64 NODE - v6.10.2</p> <p>PS: Ill post on github, just don&#39;t have this time now, need to get the things tidy first</p> <p>But the debate is open, if there is a guess, just write it down</p></pre>dlsniper: <pre><p>No, that&#39;s not how it works. Post the code and we&#39;ll help you figure out, I&#39;m not going to waste my time on this.</p> <p>You can profile your Go solution by following this: <a href="https://blog.golang.org/profiling-go-programs" rel="nofollow">https://blog.golang.org/profiling-go-programs</a></p></pre>dlsniper: <pre><p>More than a day passed, are you going to allow us to actually help you? If it&#39;s as simple as you describe it you should be able to just publish it in a gist, it can&#39;t be more than 100 lines, with all the spaces included.</p></pre>tuxlinuxien: <pre><p>You are trying to compare 2 different things and most of the application tests that I have seen between nodejs and Go are wrong.</p> <p>Don&#39;t benchmark your app but your functionalities like:</p> <ul> <li><p>HTTP server benchmark</p></li> <li><p>MongoDB querying benchmark</p></li> <li><p>JSON marshaling benchmark</p></li> </ul> <p>like this, you will see what&#39;s your problem and where it might come from.</p> <p>Make sure:</p> <ul> <li>your MongoDB driver settings are exactly the same.</li> <li>Nodejs doesn&#39;t have any cache activated.</li> <li>your go app is running on ONE single core.</li> </ul> <p>PS: change the title of your post because it looks like you are a troll.</p></pre>quirinux: <pre><p>Thanks, this was helpful, Ill check them </p></pre>p7r: <pre><p>Show us code.</p> <p>Until then, we&#39;re just going to assume it&#39;s bad code.</p> <p>If your results were generally what we found elsewhere, we would not be doing Go, we&#39;d be doing nodejs.</p> <p>If I can <code>go get</code> your code, and run it, I can profile it, improve it, etc. To be honest if that&#39;s slow I can probably eyeball it and tell you what you&#39;re doing wrong.</p> <p>There is absolutely 100% no way that nodejs is 3x faster than Go for this use case.</p></pre>quirinux: <pre><p>Ya, I know that, Ill push this code on github soon and update this thread</p></pre>tty5: <pre><p>Make sure you&#39;re comparing apples to apples: <a href="http://godoc.org/gopkg.in/mgo.v2#Session.SetSafe" rel="nofollow">http://godoc.org/gopkg.in/mgo.v2#Session.SetSafe</a> <a href="http://godoc.org/gopkg.in/mgo.v2#Session.SetPrefetch" rel="nofollow">http://godoc.org/gopkg.in/mgo.v2#Session.SetPrefetch</a> <a href="http://godoc.org/gopkg.in/mgo.v2#Session.SetBatch" rel="nofollow">http://godoc.org/gopkg.in/mgo.v2#Session.SetBatch</a></p></pre>tmornini: <pre><p>Make certain you&#39;re not opening a MongoDB connection per request.</p> <p>When you get the code right, go should blow away nodejs in terms latency, total throughput, memory consumption, etc.</p></pre>

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

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