Go HTTP performance (vs. NGINX)

4,247 views
Skip to first unread message

Alex Koch

unread,
Jun 22, 2014, 11:44:32 PM6/22/14
to golan...@googlegroups.com
Hi,

This is purely for educational purpose, please do not hate me...

I posted this on Reddit http://www.reddit.com/r/golang/comments/28so0e/go_networking_performance_vs_nginx/

All my "micro-bench" tests show that Go is 2 times slowed than NGINX, when I look under the hood (as much as I am capable of), it looks to me that the networking implementation share the same basis (EPOLL in edge-triggered mode etc.), so I am tempted to believe the overhead is somewhere else.

I am aware Go will be "natively" slower than an optimized C code but 2x time slower for a "hello world" type code was not something I expected.

Is NGINX doing something Go is not? something for Go to learn from?

Your thoughts are appreciated.

Alex

Dmitry Vyukov

unread,
Jun 23, 2014, 12:11:34 AM6/23/14
to Alex Koch, golan...@googlegroups.com
Go code generation is not as good as gcc -O3. Currently it's closer to
gcc -O1. This well explains 2x speed difference.
Go code generation will become better over time.

Matt Silverlock

unread,
Jun 23, 2014, 12:26:26 AM6/23/14
to golan...@googlegroups.com, alex.k...@outlook.com
> Is NGINX doing something Go is not? something for Go to learn from?

As someone else stated in that thread: yes, Go could also use thousand of man-hours towards optimisation like nginx has had. I would have been surprised if Go was faster than nginx in such a simple test, given the maturity of the nginx project.

Naoki INADA

unread,
Jun 23, 2014, 2:05:53 AM6/23/14
to golan...@googlegroups.com, alex.k...@outlook.com
http.Fileserver opens file per request.
Nginx caches opened fd.
Nginx also uses sendfile if possible.

a.val...@smartweb.com.ua

unread,
Jun 23, 2014, 8:22:31 AM6/23/14
to golan...@googlegroups.com, alex.k...@outlook.com
Half a year ago I noticed the default http sever implementation in go has not so very good performance in certain cases (which I didn't investigate yet :) ) compared to nginx. But this can be fixed by implementing your own specialized http server on top of well-defined http.Reqest and http.Response objects. Of course, in this case your own http server won't support all http bits, but it will beat nginx :) Below are performance numbers for my own specialized http caching proxy written in go (go-cdn-booster) vs nginx in the role of caching proxy. Performance is measured with go-cdn-booster-bench:

Nginx configs related to the test:

access_log off;
proxy_cache_path  /var/www/cache levels=1:2 keys_zone=my-cache:100k max_size=100m inactive=600m;
proxy_temp_path /var/www/cache/tmp;
proxy_cache my-cache;
proxy_cache_valid 200 60m;

go-cdn-booster configs:

./go-cdn-booster -upstreamHost=www.google.com

Performance numbers for nginx from the second test run. The first test run is inapplicable, since the nginx fetches the given image filesCount=500 times from www.google.com . During the second run nginx obtains the image contents from cache:

filesCount=500
goMaxProcs=4
requestsCount=100000
requestsPerConnectionCount=100
workersCount=16
2014/06/23 15:11:35 Test started
2014/06/23 15:11:37 Done
2014/06/23 15:11:37 100000 requests from 16 workers in 1.566374866s
2014/06/23 15:11:37 242400 Kbytes read, 63842 qps, 154752 Kbps


Performance numbers for go-cdn-booster from the second run:

filesCount=500
goMaxProcs=4
requestsCount=100000
requestsPerConnectionCount=100
workersCount=16
2014/06/23 15:16:36 Test started
2014/06/23 15:16:37 Done
2014/06/23 15:16:37 100000 requests from 16 workers in 1.088171327s
2014/06/23 15:16:37 242400 Kbytes read, 91897 qps, 222759 Kbps

As you can see, specialized http servers written in go may easily beat nginx in performance comparisons.
Reply all
Reply to author
Forward
0 new messages