mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-05-03 09:43:55 +00:00
perf: support gunicorn-gthread & use daphne-websocket (#16703)
* perf: support gunicorn-gthread & use daphne-websocket * perf: support gunicorn-wsgi & gunicorn-asgi --------- Co-authored-by: Bai <baijiangjie@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ if SERVER_SIZE == 'auto':
|
||||
|
||||
class Services(TextChoices):
|
||||
gunicorn = 'gunicorn', 'gunicorn'
|
||||
gunicorn_wsgi = 'gunicorn_wsgi', 'gunicorn_wsgi'
|
||||
celery_ansible = 'celery_ansible', 'celery_ansible'
|
||||
celery_default = 'celery_default', 'celery_default'
|
||||
celery_combine = 'celery_combine', 'celery_combine'
|
||||
@@ -36,7 +37,8 @@ class Services(TextChoices):
|
||||
def get_service_object_class(cls, name):
|
||||
from . import services
|
||||
services_map = {
|
||||
cls.gunicorn.value: services.GunicornService,
|
||||
cls.gunicorn: services.GunicornService,
|
||||
cls.gunicorn_wsgi: services.GunicornWSGIService,
|
||||
cls.flower: services.FlowerService,
|
||||
cls.celery_default: services.CeleryDefaultService,
|
||||
cls.celery_ansible: services.CeleryAnsibleService,
|
||||
@@ -47,10 +49,15 @@ class Services(TextChoices):
|
||||
|
||||
@classmethod
|
||||
def web_services(cls):
|
||||
services = [cls.gunicorn]
|
||||
if GUNICORN_WSGI_ENABLED:
|
||||
services.append(cls.gunicorn_wsgi)
|
||||
|
||||
if SERVER_SIZE == 'small' or os.environ.get('FLOWER_ENABLED', '1') == '0':
|
||||
return [cls.gunicorn]
|
||||
return services
|
||||
else:
|
||||
return [cls.gunicorn, cls.flower]
|
||||
services.append(cls.flower)
|
||||
return services
|
||||
|
||||
@classmethod
|
||||
def celery_services(cls):
|
||||
@@ -123,16 +130,28 @@ class BaseActionCommand(BaseCommand):
|
||||
parser.add_argument('-f', '--force', nargs="?", const=True)
|
||||
|
||||
def get_services_kwargs(self, options):
|
||||
worker = options.get('worker', 4)
|
||||
|
||||
if SERVER_SIZE == 'small':
|
||||
worker = 1
|
||||
else:
|
||||
worker = options.get('worker', 4)
|
||||
|
||||
return {
|
||||
'gunicorn': {
|
||||
'worker': worker
|
||||
if GUNICORN_WSGI_ENABLED:
|
||||
kwargs = {
|
||||
'gunicorn': {
|
||||
'worker': 1,
|
||||
'bind_port': WS_PORT,
|
||||
},
|
||||
'gunicorn_wsgi': {
|
||||
'worker': worker,
|
||||
}
|
||||
}
|
||||
}
|
||||
else:
|
||||
kwargs = {
|
||||
'gunicorn': {
|
||||
'worker': worker,
|
||||
},
|
||||
}
|
||||
return kwargs
|
||||
|
||||
def initial_util(self, *args, **options):
|
||||
service_names = options.get('services')
|
||||
|
||||
@@ -26,3 +26,4 @@ LOG_DIR = os.path.join(BASE_DIR, 'data', 'logs')
|
||||
APPS_DIR = os.path.join(BASE_DIR, 'apps')
|
||||
TMP_DIR = os.path.join(BASE_DIR, 'tmp')
|
||||
CELERY_WORKER_COUNT = CONFIG.CELERY_WORKER_COUNT or 10
|
||||
GUNICORN_WSGI_ENABLED = CONFIG.GUNICORN_WSGI_ENABLED or False
|
||||
@@ -4,3 +4,4 @@ from .celery_default import *
|
||||
from .celery_combine import *
|
||||
from .flower import *
|
||||
from .gunicorn import *
|
||||
from .gunicorn_wsgi import *
|
||||
|
||||
@@ -8,6 +8,7 @@ class GunicornService(BaseService):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.worker = kwargs.get('worker', 2)
|
||||
self.bind_port = kwargs.get('bind_port', HTTP_PORT)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
@property
|
||||
@@ -15,7 +16,7 @@ class GunicornService(BaseService):
|
||||
print("\n- Start Gunicorn WSGI HTTP Server")
|
||||
|
||||
log_format = '%(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s '
|
||||
bind = f'{HTTP_HOST}:{HTTP_PORT}'
|
||||
bind = f'{HTTP_HOST}:{self.bind_port}'
|
||||
|
||||
cmd = [
|
||||
'gunicorn', 'jumpserver.asgi:application',
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
from ..hands import *
|
||||
from .base import BaseService
|
||||
|
||||
__all__ = ['GunicornWSGIService']
|
||||
|
||||
|
||||
class GunicornWSGIService(BaseService):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.worker = kwargs.get('worker', 2)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
@property
|
||||
def cmd(self):
|
||||
print("\n- Start Gunicorn WSGI HTTP Server")
|
||||
|
||||
log_format = '%(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s '
|
||||
bind = f'{HTTP_HOST}:{HTTP_PORT}'
|
||||
cmd = [
|
||||
'gunicorn', 'jumpserver.wsgi',
|
||||
'-b', bind,
|
||||
'-k', 'gthread',
|
||||
'--threads', '10',
|
||||
'-w', str(self.worker),
|
||||
'--max-requests', '4096',
|
||||
'--access-logformat', log_format,
|
||||
'--access-logfile', '-'
|
||||
]
|
||||
if DEBUG:
|
||||
cmd.append('--reload')
|
||||
return cmd
|
||||
|
||||
@property
|
||||
def cwd(self):
|
||||
return APPS_DIR
|
||||
|
||||
def start_other(self):
|
||||
from terminal.startup import CoreTerminal
|
||||
core_terminal = CoreTerminal()
|
||||
core_terminal.start_heartbeat_thread()
|
||||
@@ -641,6 +641,8 @@ class Config(dict):
|
||||
'WS_LISTEN_PORT': 8070,
|
||||
'CELERY_WORKER_COUNT': 10,
|
||||
|
||||
'GUNICORN_WSGI_ENABLED': False,
|
||||
|
||||
'SYSLOG_ADDR': '', # '192.168.0.1:514'
|
||||
'SYSLOG_FACILITY': 'user',
|
||||
'SYSLOG_SOCKTYPE': 2,
|
||||
|
||||
@@ -298,3 +298,5 @@ JDMC_BASE_URL = f"http+unix://{quote(JDMC_SOCK_PATH, safe='')}"
|
||||
# WebHook
|
||||
WEBHOOK_ENABLED = CONFIG.WEBHOOK_ENABLED
|
||||
WEBHOOK_TOKEN = CONFIG.WEBHOOK_TOKEN
|
||||
|
||||
GUNICORN_WSGI_ENABLED = CONFIG.GUNICORN_WSGI_ENABLED
|
||||
Reference in New Issue
Block a user