Merge pull request #9139 from jumpserver/pr@v3@perf_gunicorn

perf: 控制 gunicorn 启动进程
pull/9150/head
老广 2 years ago committed by GitHub
commit a6b1052767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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):

@ -16,11 +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}'
cmd = [
'gunicorn', 'jumpserver.asgi:application',
'-b', bind,
'-k', 'uvicorn.workers.UvicornWorker',
'--threads', '10',
'--threads', str(self.worker * 2),
'-w', str(self.worker),
'--max-requests', '4096',
'--access-logformat', log_format,

2
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()

Loading…
Cancel
Save