Switching from Flup to Gunicorn

I have read nice posts of Gunicorn and decided to try it out. Until now I this blog was running top of Flup and from very beginning I had some bad feelings about it. This Django based blog is running on small VPS and that’s why I’m really interested of low memory footprint. I read that Gunicorn has small memory footprint and high performance so I installed it on my VPS. Setting up Gunicorn was really easy and straightforward process which took only few minutes and released almost 40 Mb memory. I will explain the installation and configuration process shortly.

Gunicorn can be installed with easy_install. You need call only one command:

easy_install gunicorn

After that you have to do few changes on your webserver configuration. I use NginX so following configurations are for NginX. First we have define new upstream (I will call mine as app_server)

upstream app_server {
    server unix:/tmp/gunicorn.sock fail_timeout=0;
}

After that I replaced server’s root location’s fastcgi configuration:

location / {
        fastcgi_pass unix:/path/to/blog.sock;
        fastcgi_read_timeout 5m;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_pass_header Authorization;
        fastcgi_intercept_errors off;
 }

to use newly defined upstream:

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;
}

That was all installation and configuration I needed to do. Only step which is left is to shutdown fcgi process, start new Gunicorn process and restart NginX.

kill {pid-number-of-fcgi-process}
gunicorn_django -D -b unix:/tmp/gunicorn.sock
/etc/init.d/nginx restart

And these few steps really saved almost 40 Mb memory which is quite much from 256 Mb. Only future will show how mature Gunicorn is but at the moment everything is working very well and I can really recommend Gunicorn for everyone.

Add post to: Delicious Reddit Slashdot Digg Technorati Google
(already: 1) Comment post

Comments

No comments for this post

Required. 30 chars of fewer.

Required.

Login

login