2022-06-05 22:56:52 +00:00
|
|
|
"""Gunicorn configuration for InvenTree."""
|
|
|
|
|
2022-05-20 15:24:51 +00:00
|
|
|
import logging
|
2021-04-01 09:38:18 +00:00
|
|
|
import multiprocessing
|
2021-07-29 06:37:34 +00:00
|
|
|
import os
|
|
|
|
|
2022-12-08 12:06:02 +00:00
|
|
|
# Logger configuration
|
2021-07-29 13:44:52 +00:00
|
|
|
logger = logging.getLogger('inventree')
|
2022-12-08 12:06:02 +00:00
|
|
|
accesslog = '-'
|
|
|
|
errorlog = '-'
|
|
|
|
loglevel = os.environ.get('INVENTREE_LOG_LEVEL', 'warning').lower()
|
|
|
|
capture_output = True
|
|
|
|
|
|
|
|
# Worker configuration
|
2022-12-09 05:51:58 +00:00
|
|
|
# TODO: Implement support for gevent
|
|
|
|
# worker_class = 'gevent' # Allow multi-threading support
|
2022-12-08 12:06:02 +00:00
|
|
|
worker_tmp_dir = '/dev/shm' # Write temp file to RAM (faster)
|
|
|
|
threads = 4
|
2021-07-29 06:37:34 +00:00
|
|
|
|
2023-01-09 20:53:57 +00:00
|
|
|
|
2023-01-31 23:25:10 +00:00
|
|
|
# Worker timeout (default = 90 seconds)
|
|
|
|
timeout = os.environ.get('INVENTREE_GUNICORN_TIMEOUT', 90)
|
2023-01-09 20:53:57 +00:00
|
|
|
|
|
|
|
# Number of worker processes
|
2021-07-29 06:37:34 +00:00
|
|
|
workers = os.environ.get('INVENTREE_GUNICORN_WORKERS', None)
|
|
|
|
|
|
|
|
if workers is not None:
|
|
|
|
try:
|
|
|
|
workers = int(workers)
|
|
|
|
except ValueError:
|
|
|
|
workers = None
|
|
|
|
|
|
|
|
if workers is None:
|
|
|
|
workers = multiprocessing.cpu_count() * 2 + 1
|
|
|
|
|
2024-01-11 00:28:58 +00:00
|
|
|
logger.info('Starting gunicorn server with %s workers', workers)
|
2021-04-01 09:38:18 +00:00
|
|
|
|
|
|
|
max_requests = 1000
|
|
|
|
max_requests_jitter = 50
|
2023-07-25 22:33:13 +00:00
|
|
|
|
|
|
|
# preload app so that the ready functions are only executed once
|
|
|
|
preload_app = True
|