add the graceful timeout option. close #352

This change add gtraceful timeout option. This timeout is different than
the worker timeout and can be extended to handled a longer delay before
closing a running connection.

Patch based on the one given by @sirkonst with some edit + support of
the eventlet worker.
This commit is contained in:
benoitc 2012-06-01 09:07:43 +02:00
parent a42daa03ed
commit 188fa3e109
4 changed files with 19 additions and 3 deletions

View File

@ -320,7 +320,7 @@ class Arbiter(object):
sig = signal.SIGQUIT
if not graceful:
sig = signal.SIGTERM
limit = time.time() + self.timeout
limit = time.time() + self.cfg.graceful_timeout
while self.WORKERS and time.time() < limit:
self.kill_workers(sig)
time.sleep(0.1)

View File

@ -418,6 +418,22 @@ class Timeout(Setting):
is not tied to the length of time required to handle a single request.
"""
class GracefulTimeout(Setting):
name = "graceful_timeout"
section = "Worker Processes"
cli = ["--graceful-timeout"]
meta = "INT"
validator = validate_pos_int
type = "int"
default = 30
desc = """\
Timeout for graceful workers restart.
Generally set to thirty seconds. How max time worker can handle
request after got restart signal. If the time is up worker will
be force killed.
"""
class Keepalive(Setting):
name = "keepalive"
section = "Worker Processes"

View File

@ -47,5 +47,5 @@ class EventletWorker(AsyncWorker):
eventlet.sleep(1.0)
self.notify()
with eventlet.Timeout(self.timeout, False):
with eventlet.Timeout(self.cfg.graceful_timeout, False):
eventlet.kill(self.acceptor, eventlet.StopServe)

View File

@ -77,7 +77,7 @@ class GeventWorker(AsyncWorker):
try:
# Try to stop connections until timeout
self.notify()
server.stop(timeout=self.timeout)
server.stop(timeout=self.cfg.graceful_timeout)
except:
pass