summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Dumpleton <Graham.Dumpleton@gmail.com>2015-01-26 16:40:43 +1100
committerGraham Dumpleton <Graham.Dumpleton@gmail.com>2015-01-26 16:40:43 +1100
commit02ce3d0ddb786ac4da97667ef7378ecd7c1047dc (patch)
tree183b70e2ec14ec1dab2ca013a6c528e7c60933bc
parent8efb8120d502f8c4b9c6c972a89a2516200b7c00 (diff)
downloadmod_wsgi-02ce3d0ddb786ac4da97667ef7378ecd7c1047dc.tar.gz
Add eviction-timeout option to allow graceful period for process restart on signals to be set separately.
-rw-r--r--docs/release-notes/version-4.4.7.rst18
-rw-r--r--src/server/__init__.py16
-rw-r--r--src/server/mod_wsgi.c24
-rw-r--r--src/server/wsgi_daemon.h1
4 files changed, 52 insertions, 7 deletions
diff --git a/docs/release-notes/version-4.4.7.rst b/docs/release-notes/version-4.4.7.rst
index a9b8de2..346cf5e 100644
--- a/docs/release-notes/version-4.4.7.rst
+++ b/docs/release-notes/version-4.4.7.rst
@@ -39,3 +39,21 @@ up proxying of a sub URL of the site to a remote URL.
3. Added ``--proxy-virtual-host`` option to ``mod_wsgi-express`` for setting
up proxying of a whole virtual host to a remote URL. Only supports proxying
of HTTP requests and not HTTPS requests.
+
+4. Added ``eviction-timeout`` option to ``WSGIDaemonProcess`` directive.
+For the case where the graceful restart signal, usually ``SIGUSR1``, is
+sent to a daemon process to evict the WSGI application and restart the
+process, this controls how many seconds the process will wait, while still
+accepting new requests, before it reaches an idle state with no active
+requests and shuts down.
+
+The ``graceful-timeout`` option previously performed this exact role in
+this case previously, but a separate option is being added to allow a
+different timeout period to be specified for the case for forced eviction.
+The existing ``graceful-timeout`` option is still used when a maximum
+requests option or CPU usage limit is set. For backwards compatibility,
+if ``eviction-timeout`` isn't set, it will fall back to using any value
+specified using the ``graceful-timeout`` option.
+
+The ``--eviction-timeout`` option has also been added to
+``mod_wsgi-express`` and behaves in a similar fashion.
diff --git a/src/server/__init__.py b/src/server/__init__.py
index 0f4fc27..2bb59ec 100644
--- a/src/server/__init__.py
+++ b/src/server/__init__.py
@@ -267,6 +267,7 @@ WSGIDaemonProcess %(host)s:%(port)s \\
inactivity-timeout=%(inactivity_timeout)s \\
deadlock-timeout=%(deadlock_timeout)s \\
graceful-timeout=%(graceful_timeout)s \\
+ eviction-timeout=%(eviction_timeout)s \\
shutdown-timeout=%(shutdown_timeout)s \\
send-buffer-size=%(send_buffer_size)s \\
receive-buffer-size=%(receive_buffer_size)s \\
@@ -291,6 +292,7 @@ WSGIDaemonProcess %(host)s:%(port)s \\
inactivity-timeout=%(inactivity_timeout)s \\
deadlock-timeout=%(deadlock_timeout)s \\
graceful-timeout=%(graceful_timeout)s \\
+ eviction-timeout=%(eviction_timeout)s \\
shutdown-timeout=%(shutdown_timeout)s \\
send-buffer-size=%(send_buffer_size)s \\
receive-buffer-size=%(receive_buffer_size)s \\
@@ -1606,10 +1608,16 @@ option_list = (
optparse.make_option('--graceful-timeout', type='int', default=15,
metavar='SECONDS', help='Grace period for requests to complete '
- 'normally, without accepting new requests, when worker processes '
- 'are being shutdown and restarted due to maximum requests being '
- 'reached or due to graceful restart signal. Defaults to 15 '
- 'seconds.'),
+ 'normally, while still accepting new requests, when worker '
+ 'processes are being shutdown and restarted due to maximum '
+ 'requests being reached. Defaults to 15 seconds.'),
+ optparse.make_option('--eviction-timeout', type='int', default=0,
+ metavar='SECONDS', help='Grace period for requests to complete '
+ 'normally, while still accepting new requests, when the WSGI '
+ 'application is being evicted from the worker processes, and '
+ 'the process restarted, due to forced graceful restart signal. '
+ 'Defaults to timeout specified by \'--graceful-timeout\' '
+ 'option.'),
optparse.make_option('--deadlock-timeout', type='int', default=60,
metavar='SECONDS', help='Maximum number of seconds allowed '
diff --git a/src/server/mod_wsgi.c b/src/server/mod_wsgi.c
index f601cb8..30ddbe5 100644
--- a/src/server/mod_wsgi.c
+++ b/src/server/mod_wsgi.c
@@ -85,6 +85,7 @@ static apr_interval_time_t wsgi_deadlock_timeout = 0;
static apr_interval_time_t wsgi_idle_timeout = 0;
static apr_interval_time_t wsgi_request_timeout = 0;
static apr_interval_time_t wsgi_graceful_timeout = 0;
+static apr_interval_time_t wsgi_eviction_timeout = 0;
static apr_time_t volatile wsgi_deadlock_shutdown_time = 0;
static apr_time_t volatile wsgi_idle_shutdown_time = 0;
static apr_time_t volatile wsgi_graceful_shutdown_time = 0;
@@ -6596,6 +6597,7 @@ static const char *wsgi_add_daemon_process(cmd_parms *cmd, void *mconfig,
int inactivity_timeout = 0;
int request_timeout = 0;
int graceful_timeout = 0;
+ int eviction_timeout = 0;
int connect_timeout = 15;
int socket_timeout = 0;
int queue_timeout = 0;
@@ -6808,6 +6810,14 @@ static const char *wsgi_add_daemon_process(cmd_parms *cmd, void *mconfig,
if (graceful_timeout < 0)
return "Invalid graceful timeout for WSGI daemon process.";
}
+ else if (!strcmp(option, "eviction-timeout")) {
+ if (!*value)
+ return "Invalid eviction timeout for WSGI daemon process.";
+
+ eviction_timeout = atoi(value);
+ if (eviction_timeout < 0)
+ return "Invalid eviction timeout for WSGI daemon process.";
+ }
else if (!strcmp(option, "connect-timeout")) {
if (!*value)
return "Invalid connect timeout for WSGI daemon process.";
@@ -7077,6 +7087,7 @@ static const char *wsgi_add_daemon_process(cmd_parms *cmd, void *mconfig,
entry->inactivity_timeout = apr_time_from_sec(inactivity_timeout);
entry->request_timeout = apr_time_from_sec(request_timeout);
entry->graceful_timeout = apr_time_from_sec(graceful_timeout);
+ entry->eviction_timeout = apr_time_from_sec(eviction_timeout);
entry->connect_timeout = apr_time_from_sec(connect_timeout);
entry->socket_timeout = apr_time_from_sec(socket_timeout);
entry->queue_timeout = apr_time_from_sec(queue_timeout);
@@ -8288,6 +8299,9 @@ static void *wsgi_monitor_thread(apr_thread_t *thd, void *data)
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, wsgi_server,
"mod_wsgi (pid=%d): Graceful timeout is %d.",
getpid(), (int)(apr_time_sec(wsgi_graceful_timeout)));
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, wsgi_server,
+ "mod_wsgi (pid=%d): Eviction timeout is %d.",
+ getpid(), (int)(apr_time_sec(wsgi_eviction_timeout)));
}
while (1) {
@@ -8579,6 +8593,7 @@ static void wsgi_daemon_main(apr_pool_t *p, WSGIDaemonProcess *daemon)
wsgi_idle_timeout = daemon->group->inactivity_timeout;
wsgi_request_timeout = daemon->group->request_timeout;
wsgi_graceful_timeout = daemon->group->graceful_timeout;
+ wsgi_eviction_timeout = daemon->group->eviction_timeout;
if (wsgi_deadlock_timeout || wsgi_idle_timeout) {
rv = apr_thread_create(&reaper, thread_attr, wsgi_monitor_thread,
@@ -8751,17 +8766,20 @@ static void wsgi_daemon_main(apr_pool_t *p, WSGIDaemonProcess *daemon)
apr_thread_mutex_lock(wsgi_monitor_lock);
wsgi_graceful_shutdown_time = apr_time_now();
- wsgi_graceful_shutdown_time += wsgi_graceful_timeout;
+ if (wsgi_eviction_timeout)
+ wsgi_graceful_shutdown_time += wsgi_eviction_timeout;
+ else
+ wsgi_graceful_shutdown_time += wsgi_graceful_timeout;
apr_thread_mutex_unlock(wsgi_monitor_lock);
ap_log_error(APLOG_MARK, APLOG_INFO, 0, wsgi_server,
- "mod_wsgi (pid=%d): Graceful shutdown "
+ "mod_wsgi (pid=%d): Process eviction "
"requested, waiting for requests to complete "
"'%s'.", getpid(), daemon->group->name);
}
else {
ap_log_error(APLOG_MARK, APLOG_INFO, 0, wsgi_server,
- "mod_wsgi (pid=%d): Graceful shutdown "
+ "mod_wsgi (pid=%d): Process eviction "
"requested, triggering immediate shutdown "
"'%s'.", getpid(), daemon->group->name);
diff --git a/src/server/wsgi_daemon.h b/src/server/wsgi_daemon.h
index c6ba8a9..999fca2 100644
--- a/src/server/wsgi_daemon.h
+++ b/src/server/wsgi_daemon.h
@@ -113,6 +113,7 @@ typedef struct {
apr_time_t inactivity_timeout;
apr_time_t request_timeout;
apr_time_t graceful_timeout;
+ apr_time_t eviction_timeout;
apr_time_t connect_timeout;
apr_time_t socket_timeout;
apr_time_t queue_timeout;