Herramientas de usuario

Herramientas del sitio


wiki2:gunicorn

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:gunicorn [2019/05/23 08:17]
alfred [Execute]
wiki2:gunicorn [2020/05/09 09:25] (actual)
Línea 20: Línea 20:
 ===== In docker containers ===== ===== In docker containers =====
  
 +Gunicorn’s main process starts one or more worker processes, and restarts them if they die. To ensure the workers are still alive, Gunicorn has a heartbeat system. The default directory for the heartbeat file is in /tmp, which in some Linux distributions is stored in memory via tmpfs filesystem. Docker containers, however, do not have /tmp on tmpfs.
 +
 +One option is to mount a tmpfs or ramfs in-memory filesystem onto /tmp, using Docker’s volume support. This will work, but not everywhere: not all environments that run Docker containers support arbitrary volumes.
 +
 +A more general solution is to tell Gunicorn to store its temporary file elsewhere.
 +
 +<​code>​
 +gunicorn --worker-tmp-dir /dev/shm
 +</​code>​
 +
 +If you only have one worker, and it’s stuck handling a slow query, the heartbeat query will timeout. Start at least two workers, and probably also start a number of threads using the gthread worker backend.
 +
 +<​code>​
 +gunicorn --workers=2 --threads=4 --worker-class=gthread
 +</​code>​
 +
 +Speaking of nginx, you don’t always nedd nginx or another proxy in front Gunicorn. Many container deployment systems already have a HTTP load balancer/​reverse proxy built-in, in which case Gunicorn isn’t being exposed directly to HTTP clients anyway.
 +
 +==== An example of gunicorn app in Docker ====
 +
 +<​code>​
 +gunicorn rema.wsgi:​application --bind 0.0.0.0:​8000 --worker-tmp-dir ~ --workers=2 --threads=4 --worker-class=gthread
 +</​code>​
wiki2/gunicorn.1558599423.txt.gz · Última modificación: 2020/05/09 09:25 (editor externo)