|
@@ -1,31 +1,9 @@
|
|
# -*- coding:utf-8 -*-
|
|
# -*- coding:utf-8 -*-
|
|
-"""
|
|
|
|
- gunicorn 配置项
|
|
|
|
-"""
|
|
|
|
-# Gunicorn的配置可以参考:
|
|
|
|
|
|
|
|
|
|
+# 参考:
|
|
# https://blog.csdn.net/y472360651/article/details/78538188
|
|
# https://blog.csdn.net/y472360651/article/details/78538188
|
|
-
|
|
|
|
# https://docs.gunicorn.org/en/stable/settings.html#server-mechanics
|
|
# https://docs.gunicorn.org/en/stable/settings.html#server-mechanics
|
|
-
|
|
|
|
-"""
|
|
|
|
-if __name__ == '__main__':
|
|
|
|
- uvicorn.run(app='main:app', host="127.0.0.1", port=8000, reload=True, debug=True)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-requirements:
|
|
|
|
- httptooles, uvloop, gunicorn, uvicorn
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-shell:
|
|
|
|
- uvicorn:
|
|
|
|
- uvicorn local:app --reload --port 5000
|
|
|
|
-
|
|
|
|
- gunicorn:
|
|
|
|
- gunicorn api_main:app -b 0.0.0.0:8001 -w 4 -k uvicorn.workers.UvicornWorker # -D 守护启动 -c 配置文件
|
|
|
|
-"""
|
|
|
|
-
|
|
|
|
|
|
+import multiprocessing
|
|
import os
|
|
import os
|
|
|
|
|
|
from config import CfgBaseInit
|
|
from config import CfgBaseInit
|
|
@@ -37,8 +15,8 @@ project_name = CfgBaseInit.project_name
|
|
debug = True
|
|
debug = True
|
|
|
|
|
|
# 后台守护模式
|
|
# 后台守护模式
|
|
-# daemon = True
|
|
|
|
-daemon = False # 如果考虑使用 supervisor 的话,将此关闭较为稳妥
|
|
|
|
|
|
+daemon = True
|
|
|
|
+# daemon = False # 如果考虑使用 supervisor 的话,将此关闭较为稳妥
|
|
|
|
|
|
# 更改代码后台重新加载
|
|
# 更改代码后台重新加载
|
|
# reload = True
|
|
# reload = True
|
|
@@ -58,32 +36,12 @@ worker_connections = 10000
|
|
# 长链接保持时间 1-5s, 默认 2
|
|
# 长链接保持时间 1-5s, 默认 2
|
|
keepalive = 180
|
|
keepalive = 180
|
|
|
|
|
|
-# workers = multiprocessing.cpu_count() * 2 + 1 # 进程数
|
|
|
|
-workers = 3 # 进程数
|
|
|
|
|
|
+workers = multiprocessing.cpu_count() * 2 + 1 # 进程数
|
|
threads = min(32, (os.cpu_count() or 1) + 4) # if "uvicorn" not in worker_class else 1 # 指定每个进程开启的线程数
|
|
threads = min(32, (os.cpu_count() or 1) + 4) # if "uvicorn" not in worker_class else 1 # 指定每个进程开启的线程数
|
|
loglevel = 'debug' # 日志级别,这个日志级别指的是错误日志的级别,而访问日志的级别无法设置
|
|
loglevel = 'debug' # 日志级别,这个日志级别指的是错误日志的级别,而访问日志的级别无法设置
|
|
access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"' # 设置gunicorn访问日志格式,错误日志无法设置
|
|
access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"' # 设置gunicorn访问日志格式,错误日志无法设置
|
|
|
|
|
|
-"""
|
|
|
|
-其每个选项的含义如下:
|
|
|
|
-h remote address
|
|
|
|
-l '-'
|
|
|
|
-u currently '-', may be user name in future releases
|
|
|
|
-t date of the request
|
|
|
|
-r status line (e.g. ``GET / HTTP/1.1``)
|
|
|
|
-s status
|
|
|
|
-b response length or '-'
|
|
|
|
-f referer
|
|
|
|
-a user agent
|
|
|
|
-T request time in seconds
|
|
|
|
-D request time in microseconds
|
|
|
|
-L request time in decimal seconds
|
|
|
|
-p process ID
|
|
|
|
-"""
|
|
|
|
-
|
|
|
|
-# 如果使用service启动,这里的pid路径应与service的pid路径保持一致,否则无法启动
|
|
|
|
-# pidfile = "./log/fast.pid"
|
|
|
|
-pidfile = "{}/../logs/{}/pid.pid".format(project_path, project_name)
|
|
|
|
|
|
|
|
-accesslog = "{}/../logs/{}/gunicorn_access.log".format(project_path, project_name) # 访问日志文件
|
|
|
|
-errorlog = "{}/../logs/{}/gunicorn_error.log".format(project_path, project_name) # 错误日志文件
|
|
|
|
|
|
+pidfile = "{}/logs/pid.pid".format(project_path)
|
|
|
|
+accesslog = "{}/logs/gunicorn_access.log".format(project_path) # 访问日志文件
|
|
|
|
+errorlog = "{}/logs/gunicorn_error.log".format(project_path) # 错误日志文件
|