What performance degradation to expect with Nginx over raw Gunicorn+Gevent?
Posted
by
bouke
on Server Fault
See other posts from Server Fault
or by bouke
Published on 2012-02-16T07:47:06Z
Indexed on
2012/08/29
15:40 UTC
Read the original article
Hit count: 282
I'm trying to get a very high performing webserver setup for handling long-polling, websockets etc. I have a VM running (Rackspace) with 1GB RAM / 4 cores. I've setup a very simple gunicorn 'hello world' application with (async) gevent workers. In front of gunicorn, I put Nginx with a simple proxy to Gunicorn. Using ab
, Gunicorn spits out 7700 requests/sec, where Nginx only does a 5000 request/sec. Is such a performance degradation expected?
Hello world:
#!/usr/bin/env python
def application(environ, start_response):
start_response("200 OK", [("Content-type", "text/plain")])
return [ "Hello World!" ]
Gunicorn:
gunicorn -w8 -k gevent --keep-alive 60 application:application
Nginx (stripped):
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
upstream app_server {
server 127.0.0.1:8000 fail_timeout=0;
}
server {
listen 8080 default;
keepalive_timeout 5;
root /home/app/app/static;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
}
Benchmark: (results: nginx TCP, nginx UNIX, gunicorn)
ab -c 32 -n 12000 -k http://localhost:[8000|8080]/
Running gunicorn over a unix socket gives somewhat higher throughput (5500 r/s), but it still does't match raw gunicorn's performance.
© Server Fault or respective owner