<p>Hi Lads, I've passed last few days with a problem hammering my head and came here to ask a hand.</p>
<p>I'm plying around golang, yes I'm loving it, but there is one test case scenario that it's not doing well and am trying ti guess what'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'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'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't excel on this scenario would be appreciate.</p>
<hr/>**评论:**<br/><br/>bschwind: <pre><p>You'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't excel on this scenario would be appreciate.</p>
</blockquote>
<p>Quite probably because of your bad code/wrong design of the same. That's not an insult. That'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'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'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's not how it works. Post the code and we'll help you figure out, I'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's as simple as you describe it you should be able to just publish it in a gist, it can'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'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'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'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're just going to assume it's bad code.</p>
<p>If your results were generally what we found elsewhere, we would not be doing Go, we'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's slow I can probably eyeball it and tell you what you'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'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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传