perf: 控制 gunicorn 启动进程

pull/9139/head
吴小白 2022-12-01 14:54:57 +08:00
parent d1461b33c5
commit 7a475fc029
1 changed files with 6 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import multiprocessing
from ..hands import *
from .base import BaseService
@ -16,11 +17,15 @@ class GunicornService(BaseService):
log_format = '%(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s '
bind = f'{HTTP_HOST}:{HTTP_PORT}'
cores = 10
if (multiprocessing.cpu_count() * 2 + 1) < cores:
cores = multiprocessing.cpu_count() * 2 + 1
cmd = [
'gunicorn', 'jumpserver.asgi:application',
'-b', bind,
'-k', 'uvicorn.workers.UvicornWorker',
'--threads', '10',
'--threads', str(cores),
'-w', str(self.worker),
'--max-requests', '4096',
'--access-logformat', log_format,