From 7a475fc029609f84049e514c75274631a20b80a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=B0=8F=E7=99=BD?= <296015668@qq.com> Date: Thu, 1 Dec 2022 14:54:57 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=8E=A7=E5=88=B6=20gunicorn=20?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/services/services/gunicorn.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/common/management/commands/services/services/gunicorn.py b/apps/common/management/commands/services/services/gunicorn.py index 5cc67b45c..97db306a7 100644 --- a/apps/common/management/commands/services/services/gunicorn.py +++ b/apps/common/management/commands/services/services/gunicorn.py @@ -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,