Re:Gadget: A smallish web framework for Go
by continuations on Tuesday November 26, 2013 @09:04PM
(#6805742)
Your benchmark results look very different from that of the web framework benchmark:
http://www.techempower.com/benchmarks/#section=data-r7&hw=i7...
In that benchmark Go's JSON performance is almost 3x higher than that of Node.
Any reasons why there's such a big difference?
Re:Gadget: A smallish web framework for Go
by optymizer on Wednesday November 27, 2013 @08:14AM
(#6807841)
I think it's because they're measuring the rate at which Node.js and Go receive requests, process json, and reply as a single metric.
I measured the speed with which Go and Node.js decode/encode JSON, i.e. there is no network and web server involved, just json.Marshal()/json.Unmarshal() vs JSON.parse()/JSON.stringify()
I benchmarked the web server speed separately.
Re:Gadget: A smallish web framework for Go
by DecemberWaltz on Tuesday November 26, 2013 @08:26PM
(#6805595)
Do you have the source code for your benchmarks? Thank you.
That's where I say NO. go's reflect package is slow and a nightmare to use. Go's JSON parser, which uses reflect, is 2.5x slower than Node.js (in my own benchmarks [1]). And Go 1.1 was 3.5x worse that Node.js at parsing JSON. Again, those are my benchmarks, but they seem consistent with what other people are finding (from my Googling around).
I would not make this trade off, I would not use reflect on EVERY request, just so that my request handlers are compatible with http.HandleFunc. It almost seems silly to do that. That's why other frameworks (like Revel) are using custom Request objects.
However, I do understand why the author is emphasizing this feature. If your handlers are incompatible with http.HandleFunc (i.e. if they take a custom Request object), you need your own Router which invokes the handlers, and you need your own ServeMux, so you end up giving up on a lot of functionality from net/http. That's why Revel has a ton of custom objects that mirror what net/http has and it proxies method calls.
So you keep wondering: "why the hell am I writing so much seemingly unrelated code? I just want to add a 'user' property to each request, but now I've coded so many struct's and created so many files". It makes you feel unproductive and it bloats the code.
Again, I've made my choice, but you should be aware of such caveats and, of course, benchmark things yourself.
1) My benchmark results. For some charts, higher is better, for others, lower is better. Use your judgement. http://goo.gl/xfWFXo