GunicornNGINX

Memory swapping causes slow response times and Nginx 504 timeouts

critical
Resource ContentionUpdated May 1, 2012(via Exa)
How to detect:

When hosting multiple Gunicorn sites on a server with insufficient RAM, heavy swap usage (828 MB swap on 1024 MB total RAM) causes response times up to 16 seconds and Nginx 504 gateway timeout errors. Sites intermittently timeout on first request but load quickly on reload.

Recommended action:

Monitor swap usage with 'free -m' and 'top'. If swap usage exceeds 20-30% of total RAM, either add more RAM to the server, reduce the number of hosted sites, or decrease Gunicorn workers per site. The issue was resolved by upgrading RAM on the app server.