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:
0xjnml:You're going to have to post the code if you want any meaningful discussion.
dlsniper: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.
quirinux: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?
dlsniper: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
tuxlinuxien: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.
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:p7r:Thanks, this was helpful, Ill check them
quirinux: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.
tty5:Ya, I know that, Ill push this code on github soon and update this thread
tmornini: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
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.
