Merge pull request #1449 from meeb/tcely-gunicorn-configuration

chore(gunicorn): review and update configuration
This commit is contained in:
tcely
2026-04-22 09:38:00 -04:00
committed by GitHub
2 changed files with 50 additions and 26 deletions

View File

@@ -21,4 +21,4 @@ then
fi
exec s6-setuidgid app \
/usr/local/bin/gunicorn -c /app/tubesync/gunicorn.py --capture-output tubesync.wsgi:application
/usr/local/bin/gunicorn --config /app/tubesync/gunicorn.py

View File

@@ -2,37 +2,61 @@ import os
import multiprocessing
def get_num_workers():
# Sane max workers to allow to be spawned
cpu_workers = multiprocessing.cpu_count() * 2 + 1
# But default to 3
try:
num_workers = int(os.getenv('GUNICORN_WORKERS', 3))
except ValueError:
num_workers = cpu_workers
if 0 < num_workers < cpu_workers:
return num_workers
else:
return cpu_workers
def get_bind():
host = os.getenv('LISTEN_HOST', '127.0.0.1')
port = os.getenv('LISTEN_PORT', '8080')
return '{}:{}'.format(host, port)
return f'{host}:{port}'
def get_num_workers():
# Sane max workers to allow to be spawned
cpu_workers = multiprocessing.cpu_count() * 2 + 1
# But default to 3
num_workers = 3
try:
gunicorn_workers = os.getenv('GUNICORN_WORKERS')
web_concurrency = os.getenv('WEB_CONCURRENCY')
if gunicorn_workers is not None:
try:
num_workers = int(gunicorn_workers)
except:
pass
elif web_concurrency is not None:
try:
num_workers = int(web_concurrency)
except:
pass
except:
pass
return max(1, min(num_workers, cpu_workers))
workers = get_num_workers()
timeout = 90
chdir = '/app'
### Configuration
wsgi_app = 'tubesync.wsgi:application'
##### Logging
# Access logs are printed to stdout from nginx
accesslog = None
errorlog = '-'
loglevel = 'info'
capture_output = True
##### Process
proc_name = 'gunicorn'
daemon = False
control_socket_disable = True
control_socket = '/run/app/gunicorn.ctl'
pidfile = '/run/app/gunicorn.pid'
user = 'app'
group = 'app'
loglevel = 'info'
errorlog = '-'
accesslog = '/dev/null' # Access logs are printed to stdout from nginx
django_settings = 'django.settings'
chdir = '/app'
control_socket = '/run/app/gunicorn.ctl'
control_socket_disable = True
pidfile = '/run/app/gunicorn.pid'
##### Server
bind = get_bind()
django_settings = 'django.settings'
graceful_timeout = 120
keepalive = 60
max_requests = 1000
max_requests_jitter = 100
timeout = 90
worker_class = 'sync'
workers = get_num_workers()