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 1/3] =?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, From 2bc47c87d1077ff70721f9a5d4edbf9202c35341 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 16:12:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?perf:=20=E4=BF=AE=E6=AD=A3=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/management/commands/services/command.py | 7 ++++++- .../management/commands/services/services/gunicorn.py | 6 +----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/common/management/commands/services/command.py b/apps/common/management/commands/services/command.py index 1fb28fd3a..2ee11385d 100644 --- a/apps/common/management/commands/services/command.py +++ b/apps/common/management/commands/services/command.py @@ -1,3 +1,4 @@ +import multiprocessing from django.core.management.base import BaseCommand, CommandError from django.db.models import TextChoices from .utils import ServicesUtil @@ -91,11 +92,15 @@ class BaseActionCommand(BaseCommand): super().__init__(*args, **kwargs) def add_arguments(self, parser): + cores = 10 + if (multiprocessing.cpu_count() + 1) < cores: + cores = multiprocessing.cpu_count() + 1 + parser.add_argument( 'services', nargs='+', choices=Services.export_services_values(), help='Service', ) parser.add_argument('-d', '--daemon', nargs="?", const=True) - parser.add_argument('-w', '--worker', type=int, nargs="?", default=4) + parser.add_argument('-w', '--worker', type=int, nargs="?", default=cores) parser.add_argument('-f', '--force', nargs="?", const=True) def initial_util(self, *args, **options): diff --git a/apps/common/management/commands/services/services/gunicorn.py b/apps/common/management/commands/services/services/gunicorn.py index 97db306a7..495ace6c7 100644 --- a/apps/common/management/commands/services/services/gunicorn.py +++ b/apps/common/management/commands/services/services/gunicorn.py @@ -1,4 +1,3 @@ -import multiprocessing from ..hands import * from .base import BaseService @@ -17,15 +16,12 @@ 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', str(cores), + '--threads', str(self.worker * 2), '-w', str(self.worker), '--max-requests', '4096', '--access-logformat', log_format, From ce3ec851477d6de6d054b27a4b9c422afa40b46d 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 16:22:26 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jms | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jms b/jms index 5d5b5c433..57410c933 100755 --- a/jms +++ b/jms @@ -177,7 +177,7 @@ if __name__ == '__main__': help="The service to start", ) parser.add_argument('-d', '--daemon', nargs="?", const=True) - parser.add_argument('-w', '--worker', type=int, nargs="?", default=4) + parser.add_argument('-w', '--worker', type=int, nargs="?") parser.add_argument('-f', '--force', nargs="?", const=True) args = parser.parse_args()