Bläddra i källkod

[conf] Make Gunicorn worker timeout and graceful timeout configurable (#3753)

Ying Chen 1 år sedan
förälder
incheckning
c8e07e3dfd

+ 7 - 0
desktop/conf.dist/hue.ini

@@ -68,6 +68,13 @@ http_500_debug_mode=false
 # The number of Gunicorn worker processes. If not specified, it uses: (number of CPU * 2) + 1.
 ## gunicorn_number_of_workers=1
 
+# Workers silent for more than this many seconds are killed and restarted.
+# gunicorn_worker_timeout=900
+
+# After receiving a restart signal, workers have this much time to finish serving requests.
+# Workers still alive after the timeout (starting from the receipt of the restart signal) are force killed.
+# gunicorn_worker_graceful_timeout=900
+
 # Webserver runs as this user
 ## server_user=hue
 ## server_group=hue

+ 7 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -73,6 +73,13 @@
   # The number of Gunicorn worker processes. If not specified, it uses: (number of CPU * 2) + 1.
   ## gunicorn_number_of_workers=1
 
+  # Workers silent for more than this many seconds are killed and restarted.
+  # gunicorn_worker_timeout=900
+
+  # After receiving a restart signal, workers have this much time to finish serving requests.
+  # Workers still alive after the timeout (starting from the receipt of the restart signal) are force killed.
+  # gunicorn_worker_graceful_timeout=900
+
   # Webserver runs as this user
   ## server_user=hue
   ## server_group=hue

+ 13 - 0
desktop/core/src/desktop/conf.py

@@ -196,6 +196,19 @@ GUNICORN_NUMBER_OF_WORKERS = Config(
   type=int,
   default=1)
 
+GUNICORN_WORKER_TIMEOUT = Config(
+  key="gunicorn_worker_timeout",
+  help=_("Workers silent for more than this many seconds are killed and restarted."),
+  type=int,
+  default=900)
+
+GUNICORN_WORKER_GRACEFUL_TIMEOUT = Config(
+  key="gunicorn_worker_graceful_timeout",
+  help=_("After receiving a restart signal, workers have this much time to finish serving requests. "
+         "Workers still alive after the timeout (starting from the receipt of the restart signal) are force killed."),
+  type=int,
+  default=900)
+
 HTTP_HOST = Config(
   key="http_host",
   help=_("HTTP host to bind to."),

+ 2 - 2
desktop/core/src/desktop/management/commands/rungunicornserver.py

@@ -221,7 +221,7 @@ def rungunicornserver(args=[], options={}):
       'enable_stdio_inheritance': None,
       'errorlog': "-",
       'forwarded_allow_ips': None,
-      'graceful_timeout': 900,                # Timeout for graceful workers restart.
+      'graceful_timeout': conf.GUNICORN_WORKER_GRACEFUL_TIMEOUT.get(),
       'group': conf.SERVER_GROUP.get(),
       'initgroups': None,
       'keepalive': 120,                       # seconds to wait for requests on a keep-alive connection.
@@ -254,7 +254,7 @@ def rungunicornserver(args=[], options={}):
       'syslog_facility': None,
       'syslog_prefix': None,
       'threads': conf.CHERRYPY_SERVER_THREADS.get(),
-      'timeout': 900,                         # Workers silent for more than this many seconds are killed and restarted.
+      'timeout': conf.GUNICORN_WORKER_TIMEOUT.get(),
       'umask': None,
       'user': conf.SERVER_USER.get(),
       'worker_class': conf.GUNICORN_WORKER_CLASS.get(),