From 481dbd5cbf44d93bcb393cc3dedbcfef16554ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ko=C5=82akowski?= Date: Tue, 23 Sep 2025 11:18:52 +0200 Subject: [PATCH] Make gunicorn max_requests configurable --- desktop/conf.dist/hue.ini | 6 ++++++ desktop/conf/pseudo-distributed.ini.tmpl | 6 ++++++ desktop/core/src/desktop/conf.py | 12 ++++++++++++ .../core/src/desktop/lib/gunicorn_server_utils.py | 5 +++-- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/desktop/conf.dist/hue.ini b/desktop/conf.dist/hue.ini index aa15ddf0970..8459fd40e96 100644 --- a/desktop/conf.dist/hue.ini +++ b/desktop/conf.dist/hue.ini @@ -78,6 +78,12 @@ http_500_debug_mode=false # Workers still alive after the timeout (starting from the receipt of the restart signal) are force killed. # gunicorn_worker_graceful_timeout=900 +# The maximum number of requests a worker will process before restarting. +# gunicorn_max_requests=1200 + +# The maximum jitter to add to the max_requests setting. +# gunicorn_max_requests_jitter=0 + # Name of the Unix Domain Socket file for log listener communication. ## log_listener_socket_name=hue.uds diff --git a/desktop/conf/pseudo-distributed.ini.tmpl b/desktop/conf/pseudo-distributed.ini.tmpl index 27a4dd91b3d..6af18724b53 100644 --- a/desktop/conf/pseudo-distributed.ini.tmpl +++ b/desktop/conf/pseudo-distributed.ini.tmpl @@ -83,6 +83,12 @@ # Workers still alive after the timeout (starting from the receipt of the restart signal) are force killed. # gunicorn_worker_graceful_timeout=900 + # The maximum number of requests a worker will process before restarting. + # gunicorn_max_requests=1200 + + # The maximum jitter to add to the max_requests setting. + # gunicorn_max_requests_jitter=0 + # Name of the Unix Domain Socket file for log listener communication. ## log_listener_socket_name=hue.uds diff --git a/desktop/core/src/desktop/conf.py b/desktop/core/src/desktop/conf.py index b2c259b73cb..541a2e5661d 100644 --- a/desktop/core/src/desktop/conf.py +++ b/desktop/core/src/desktop/conf.py @@ -170,6 +170,18 @@ def is_custom_jwt_auth_enabled(): return bool(AUTH.JWT.KEY_SERVER_URL.get()) +GUNICORN_MAX_REQUESTS = Config( + key="gunicorn_max_requests", + help=_("The maximum number of requests a worker will process before restarting."), + type=int, + default=1200) + +GUNICORN_MAX_REQUESTS_JITTER = Config( + key="gunicorn_max_requests_jitter", + help=_("The maximum jitter to add to the max_requests setting."), + type=int, + default=0) + USE_CHERRYPY_SERVER = Config( key="use_cherrypy_server", help=_("If set to true, CherryPy will be used. Otherwise, Gunicorn will be used as the webserver."), diff --git a/desktop/core/src/desktop/lib/gunicorn_server_utils.py b/desktop/core/src/desktop/lib/gunicorn_server_utils.py index 8979ae8939c..f43aef7bee5 100644 --- a/desktop/core/src/desktop/lib/gunicorn_server_utils.py +++ b/desktop/core/src/desktop/lib/gunicorn_server_utils.py @@ -318,8 +318,9 @@ def gunicorn_ssl_context(conf, default_ssl_context_factory): 'limit_request_fields': conf.LIMIT_REQUEST_FIELDS.get(), 'limit_request_line': conf.LIMIT_REQUEST_LINE.get(), 'loglevel': 'DEBUG' if conf.DJANGO_DEBUG_MODE.get() else 'INFO', - 'max_requests': 1200, # The maximum number of requests a worker will process before restarting. - 'max_requests_jitter': 0, + # The maximum number of requests a worker will process before restarting. + 'max_requests': conf.GUNICORN_MAX_REQUESTS.get(), + 'max_requests_jitter': conf.GUNICORN_MAX_REQUESTS_JITTER.get(), 'paste': None, 'pidfile': None, 'preload_app': False,