Troubleshooting
How do I fix Django reporting an ImproperlyConfigured
error?
With asynchronous workers, creating URLs with the reverse
function of django.core.urlresolvers
may fail. Use reverse_lazy
instead.
How do I avoid Gunicorn excessively blocking in os.fchmod
?
The current heartbeat system involves calling os.fchmod
on temporary file handlers and may block a worker for arbitrary time if the directory is on a disk-backed filesystem. For example, by default /tmp
is not mounted as tmpfs
in Ubuntu; in AWS an EBS root instance volume may sometimes hang for half a minute and during this time Gunicorn workers may completely block in os.fchmod
. os.fchmod
may introduce extra delays if the disk gets full. Also Gunicorn may refuse to start if it can’t create the files when the disk is full.
Currently to avoid these problems you can use a tmpfs
mount (for a new directory or for /tmp
) and pass its path to --worker-tmp-dir
. First, check whether your /tmp
is disk-backed or RAM-backed:
$ df /tmp
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 ... ... ... ... /
No luck. If you are using Fedora or Ubuntu, you should already have a tmpfs
mount at /dev/shm
:
$ df /dev/shm
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs ... ... ... ... /dev/shm
In this case you can set --worker-tmp-dir /dev/shm
, otherwise you can create a new tmpfs
mount:
sudo cp /etc/fstab /etc/fstab.orig
sudo mkdir /mem
echo 'tmpfs /mem tmpfs defaults,size=64m,mode=1777,noatime,comment=for-gunicorn 0 0' | sudo tee -a /etc/fstab
sudo mount /mem
Check the result:
$ df /mem
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 65536 0 65536 0% /mem
Now you can set --worker-tmp-dir /mem
.