Skip to content

Gunicorn

Gunicorn Logo

Gunicorn (https://gunicorn.org/) is a common choice for many Python-based WSGI applications as it offers impressive concurrency and works better under high loads. It is also easy to configure and setup - making it a great choice for easy setups with lower maintenance burden.

To use Gunicorn, it needs to be installed in the virtual-environments of the appropriate component it is being used for. It would be useful for the components that host WSGI Applications like:

  • Web Application Server
  • API Server

Installation

# For the Web Application Server:
INSTALL_DIR/venv-app/bin/pip install gunicorn

# For the API Server:
INSTALL_DIR/venv-api/bin/pip install gunicorn

Configurations

Once installed, the gunicorn process can be started with the gunicorn CLI command.

This is described in https://docs.gunicorn.org/en/stable/run.html

Note: It is recommended to use Gunicorn behind a proxy server like Nginx: https://docs.gunicorn.org/en/stable/deploy.html#deploying-gunicorn

Some useful configurations for Gunicorn are:

  • workers: The number of concurrent requests that can be handled at a time
  • bind: The Host/Port to listen to for incoming requests
  • timeout: The time limit after which a request will be cancelled (in seconds)
  • capture-output: Whether the logs of the application should be captured and sent as part of the gunicorn logs
  • access-logfile / error-logfile: The logs for access/errors

Here is an example gunicorn call for the Corridor components:

Web Application server:

gunicorn \
  corridor_app.wsgi:app \
  --workers=10 \
  --bind=0.0.0.0:5002 \
  --timeout=600 \
  --capture-output --access-logfile - --error-logfile -

API server:

gunicorn \
  corridor_api.wsgi:app \
  --workers=10 \
  --bind=0.0.0.0:5001 \
  --timeout=600 \
  --capture-output --access-logfile - --error-logfile -