Simple Gunicorn fix to blocking problem?


How do I avoid Gunicorn excessively blocking in os.fchmod ?

Gunicorn FAQ - Trouble Shooting

Gunicorn’s heartbeat system call os.fchmod on temporary file handlers, which on Ubuntu systems is a disk-backed filesystem.

$ df /tmp
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       65876900 14405276  51455240  22% /

This causes Gunicorn workers to sometimes hang for half a minute.

Fortunately, Ubuntu already has tmpfs mount at /dev/shm

$ df /dev/shm
Filesystem     1K-blocks  Used Available Use% Mounted on
tmpfs            4076240     0   4076240   0% /dev/shm

To solve this problem, we must set the parameter --worker-tmp-dir /dev/shm on the supervisor.conf

command=/home/frappe/bench/env/bin/gunicorn -b -w 4 -t 120 --preload --worker-tmp-dir /dev/shm

Would it be good to have worker-tmp-dir parameter in the common_site_config.json file to set this temporary directory parameter of gunicorn?

1 Like

Hi Joseph,

Any significant increase in gunicorn performances ?

Any suggestion the size for tmpfs ?


The system is much more responsive.

tmpfs grows and shrinks no need to set anything. It is already there.
Only tmpfs in Ubuntu is set to disk-based.
Gunicorn assumes it is memory based.
This is why in Ubuntu systems, Gunicorn has a heartbeat problem of workers timing out and taking up to 30 seconds to reactivate.

Hi Joseph,

In my Ubuntu 18.04, the tmpfs that mounted on dev/shm that is set to 2GB. Will this auto grows when needed ?

Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 2019556 0 2019556 0% /dev/shm

I don’t think so.

Thanks Joseph