Files
SMANAGE/gunicorn.conf.py
T

56 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Gunicorn 生产部署配置
启动:gunicorn -c gunicorn.conf.py gvsds.wsgi:application
参数可通过环境变量覆盖:
GUNICORN_BIND 监听地址(默认 127.0.0.1:8000)
GUNICORN_WORKERS worker 数(默认 CPU*2+1)
GUNICORN_TIMEOUT 请求超时秒(默认 60)
GUNICORN_MAX_REQUESTS 单 worker 最大请求数(防内存泄漏,默认 1000)
"""
import os
import multiprocessing
Bind = os.environ.get('GUNICORN_BIND', '127.0.0.1:8000')
# worker 数:默认 CPU*2+1,可环境变量覆盖
Workers = int(os.environ.get('GUNICORN_WORKERS', multiprocessing.cpu_count() * 2 + 1))
# 同步 worker 模式(WSGI 标准,适合 Django)
WorkerClass = 'sync'
# 请求超时(秒)——长任务应卸载到 Celery
Timeout = int(os.environ.get('GUNICORN_TIMEOUT', 60))
# 优雅关闭超时
GracefulTimeout = 30
# 保持连接
Keepalive = 5
# 单 worker 最大请求数后重启,防止内存泄漏
MaxRequests = int(os.environ.get('GUNICORN_MAX_REQUESTS', 1000))
MaxRequestsJitter = 50
# 预加载应用(共享连接池,节省内存,加快启动)
PreloadApp = True
# 限制请求行/字段大小,防大文件攻击
LimitRequestLine = 8190
LimitRequestField = 8190
LimitRequestFieldSize = 8190
# 日志
Accesslog = '-'
Errorlog = '-'
Loglevel = os.environ.get('GUNICORN_LOG_LEVEL', 'info')
# 优雅重启:收到 SIGTERM 时等待请求完成
CaptureOutput = True
# 进程名(便于 ps/top 识别)
ProcName = 'gvsds-gunicorn'
# 当 SIGTERM 时,先停止接受新请求,等待 GracefulTimeout 后强杀
GracefulExist = True