Files
syops/backend/deploy/gunicorn_config.py
T

43 lines
1011 B
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_config.py
Gunicorn 生产环境配置文件
"""
import multiprocessing
import os
# 绑定地址
bind = "0.0.0.0:5000"
# 工作模式
# 使用 gevent 处理高并发和长连接 (SSE)
worker_class = "gevent"
# 进程数
# 公式: 2 * CPU核心数 + 1;GUNICORN_WORKERS 可覆盖,且不超过 CPU 公式上限
workers = min(int(os.getenv("GUNICORN_WORKERS", "9")), multiprocessing.cpu_count() * 2 + 1)
# 每个 Worker 的最大并发连接数
worker_connections = 1000
# 超时设置 (秒)
# SSE 流式响应通常需要较长的超时时间
timeout = 120
keepalive = 5
# 日志
# 在 Docker 环境中,推荐输出到 stdout/stderr
accesslog = "-"
errorlog = "-"
loglevel = "info"
# 守护进程模式 (由 Supervisor 管理时通常设为 False)
daemon = False
# 进程名称
proc_name = "hxops_backend"
# 应用启动时会访问数据库加载持久化配置;预加载会让主进程先建立连接再 fork,
# 导致 worker 继承损坏的数据库连接。
preload_app = False