Benchmarking Nginx with Go
gist.github.com
gist.github.com
In the upstream block add:
keepalive 60;
In the server (or location) block add: proxy_http_version 1.1;
proxy_set_header Connection "";Since this server always prints hello world it would stand to reason that Ngnix should be caching the result.
The initial purpose of this test is to compare the different ways of connecting Nginx to Go.
It doesn't makes sense to test against a heavy task in Go instead of this single static string. Nginx in front of Go will not perform better under this circumstances. It will only perform better if static content is being served directly by Nginx or if caching is enabled, which is not the purpose of this test.
Following what some folks suggested, I also made some recent changes, like swapping ab for wrk and tuning nginx to disable gzip and enable keep-alive connections.
The results are very different now.
comparison of nginx and boxcars: https://gist.github.com/azer/5955772
If you must use an ApacheBench-style tool, at least use the multi-threaded clone named WeigHTTP [2].
With high-performance servers, ApacheBench is a limiting factor.
This is the core problem with such benchmarks - that 'overhead' quickly becomes proportionally irrelevant when you're actually doing something worth doing. But with Nginx in front, suddenly you have so much flexibility without reinventing the wheel, including load balancing, mixing server technologies with ease, not dealing with static junk in your go code, proxy caching (recently used this to really good effect with a Go service, putting zero caching in the Go code and instead using standard http expiration headers to allow Nginx to do the magic), anti-DOS, streaming compression, security, SPDY, and on and on.
As fair disclosure, I have written on this before - http://dennisforbes.ca/index.php/2013/08/07/ten-reasons-you-...
Using Nginx or another webserver in front of your app means that you won't have to deal with privilege seperation yourself. Just run the Go binary in a chroot as an restricted user and let Nginx deal with the binding on port 80/443.