Yet another golang nodejs comparison SPOILER #GOFAILS

blov · 2017-08-03 10:00:14 · 686 次点击    
这是一个分享于 2017-08-03 10:00:14 的资源,其中的信息可能已经有所发展或是发生改变。

Hi Lads, I've passed last few days with a problem hammering my head and came here to ask a hand.

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.

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.

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

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.

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.

And yes, an answer saying why go doesn't excel on this scenario would be appreciate.


评论:

bschwind:

You're going to have to post the code if you want any meaningful discussion.

0xjnml:

And yes, an answer saying why go doesn't excel on this scenario would be appreciate.

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.

dlsniper:

for now I'm looking forward suggestions of how to get it performing better or a guess of what could be happening.

I can guess a dozen of reasons of why it would this happen but would guessing be of any help to anyone? As /u/bschwind said: show me the code.

I would at least expect Go to be on par with node on this, if not better.

Also, which version of Go are you using?

quirinux:

So do I

GO - go version go1.8.3 linux/amd64 NODE - v6.10.2

PS: Ill post on github, just don't have this time now, need to get the things tidy first

But the debate is open, if there is a guess, just write it down

dlsniper:

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.

You can profile your Go solution by following this: https://blog.golang.org/profiling-go-programs

dlsniper:

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.

tuxlinuxien:

You are trying to compare 2 different things and most of the application tests that I have seen between nodejs and Go are wrong.

Don't benchmark your app but your functionalities like:

  • HTTP server benchmark

  • MongoDB querying benchmark

  • JSON marshaling benchmark

like this, you will see what's your problem and where it might come from.

Make sure:

  • your MongoDB driver settings are exactly the same.
  • Nodejs doesn't have any cache activated.
  • your go app is running on ONE single core.

PS: change the title of your post because it looks like you are a troll.

quirinux:

Thanks, this was helpful, Ill check them

p7r:

Show us code.

Until then, we're just going to assume it's bad code.

If your results were generally what we found elsewhere, we would not be doing Go, we'd be doing nodejs.

If I can go get 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.

There is absolutely 100% no way that nodejs is 3x faster than Go for this use case.

quirinux:

Ya, I know that, Ill push this code on github soon and update this thread

tty5:

Make sure you're comparing apples to apples: http://godoc.org/gopkg.in/mgo.v2#Session.SetSafe http://godoc.org/gopkg.in/mgo.v2#Session.SetPrefetch http://godoc.org/gopkg.in/mgo.v2#Session.SetBatch

tmornini:

Make certain you're not opening a MongoDB connection per request.

When you get the code right, go should blow away nodejs in terms latency, total throughput, memory consumption, etc.


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

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