Revert "perf: gunicorn 改用 gthread 并关闭 preload,提升小程序并发承载"
This reverts commit 9ad98fa255.
This commit is contained in:
@@ -1,34 +1,52 @@
|
|||||||
# /opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django/gunicorn.conf.py
|
# /opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django/gunicorn.conf.py
|
||||||
import multiprocessing
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
# 绑定的IP和端口(根据你的Nginx配置,后端在8001端口)
|
||||||
bind = "127.0.0.1:8001"
|
bind = "127.0.0.1:8001"
|
||||||
|
|
||||||
# 并发 = workers × threads(gthread 比纯 sync 更抗小程序一进页多接口并发)
|
# 工作进程数(根据CPU核心数调整,建议:CPU核心数*2+1)
|
||||||
cpu_count = multiprocessing.cpu_count()
|
# 查看CPU核心数:cat /proc/cpuinfo | grep "processor" | wc -l
|
||||||
workers = int(os.environ.get("GUNICORN_WORKERS", max(cpu_count * 2 + 1, 4)))
|
workers = 4
|
||||||
threads = int(os.environ.get("GUNICORN_THREADS", 2))
|
|
||||||
worker_class = "gthread"
|
|
||||||
|
|
||||||
max_requests = 2000
|
# 工作模式(使用gevent支持异步,更高效)
|
||||||
max_requests_jitter = 100
|
#worker_class = "gevent"
|
||||||
|
worker_class = "sync" # 改成这个
|
||||||
|
|
||||||
timeout = 60
|
# 每个worker的最大请求数(防止内存泄漏)
|
||||||
graceful_timeout = 30
|
max_requests = 1000
|
||||||
keepalive = 5
|
max_requests_jitter = 50 # 随机抖动,避免所有worker同时重启
|
||||||
|
|
||||||
# Django + MySQL 建议关闭 preload,避免 worker 共享陈旧 DB 连接
|
# 超时时间(秒)
|
||||||
preload_app = False
|
timeout = 30
|
||||||
|
keepalive = 2
|
||||||
|
|
||||||
|
# 预加载应用(减少内存占用,加快请求处理)
|
||||||
|
preload_app = True
|
||||||
|
|
||||||
|
# 日志配置
|
||||||
|
# 访问日志:输出到标准输出,便于OnePanel查看
|
||||||
accesslog = "-"
|
accesslog = "-"
|
||||||
|
# 错误日志:输出到标准错误
|
||||||
errorlog = "-"
|
errorlog = "-"
|
||||||
|
# 日志级别
|
||||||
loglevel = "info"
|
loglevel = "info"
|
||||||
|
|
||||||
|
# 进程名称(便于识别)
|
||||||
proc_name = "a_long_dianjing_gunicorn"
|
proc_name = "a_long_dianjing_gunicorn"
|
||||||
|
|
||||||
|
# 工作进程的用户/组(安全考虑,用非root用户运行)
|
||||||
|
# user = "www-data"
|
||||||
|
# group = "www-data"
|
||||||
|
|
||||||
|
# 工作进程临时目录(避免权限问题)
|
||||||
worker_tmp_dir = "/dev/shm"
|
worker_tmp_dir = "/dev/shm"
|
||||||
|
|
||||||
|
# 限制请求数据大小(防止大文件攻击)
|
||||||
limit_request_line = 4094
|
limit_request_line = 4094
|
||||||
limit_request_fields = 100
|
limit_request_fields = 100
|
||||||
limit_request_field_size = 8190
|
limit_request_field_size = 8190
|
||||||
|
|
||||||
|
# 优雅退出时间
|
||||||
|
graceful_timeout = 30
|
||||||
|
|
||||||
|
# 进程守护(如果用systemd管理,这里设为False)
|
||||||
daemon = False
|
daemon = False
|
||||||
Reference in New Issue
Block a user