mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-19 16:03:00 +00:00
variables for exponential falloff
This commit is contained in:
@@ -27,7 +27,7 @@ from traitlets import (
|
||||
)
|
||||
|
||||
from .traitlets import Command, ByteSpecification
|
||||
from .utils import random_port, url_path_join
|
||||
from .utils import random_port, url_path_join, DT_MIN, DT_MAX, DT_SCALE
|
||||
|
||||
|
||||
class Spawner(LoggingConfigurable):
|
||||
@@ -630,7 +630,7 @@ class Spawner(LoggingConfigurable):
|
||||
self.log.exception("Unhandled error in poll callback for %s", self)
|
||||
return status
|
||||
|
||||
death_interval = Float(0.1)
|
||||
death_interval = Float(DT_MIN)
|
||||
|
||||
@gen.coroutine
|
||||
def wait_for_death(self, timeout=10):
|
||||
@@ -644,7 +644,7 @@ class Spawner(LoggingConfigurable):
|
||||
break
|
||||
else:
|
||||
yield gen.sleep(dt)
|
||||
dt = min(dt * 2, timeout - (loop.time() - tic))
|
||||
dt = min(dt * DT_SCALE, DT_MAX, timeout - (loop.time() - tic))
|
||||
|
||||
|
||||
def _try_setcwd(path):
|
||||
|
@@ -48,6 +48,12 @@ def can_connect(ip, port):
|
||||
else:
|
||||
return True
|
||||
|
||||
# exponential falloff factors:
|
||||
# start at 100ms, falloff by 2x
|
||||
# never longer than 5s
|
||||
DT_MIN = 0.1
|
||||
DT_SCALE = 2
|
||||
DT_MAX = 5
|
||||
|
||||
@gen.coroutine
|
||||
def wait_for_server(ip, port, timeout=10):
|
||||
@@ -56,13 +62,13 @@ def wait_for_server(ip, port, timeout=10):
|
||||
ip = '127.0.0.1'
|
||||
loop = ioloop.IOLoop.current()
|
||||
tic = loop.time()
|
||||
dt = 0.1
|
||||
dt = DT_MIN
|
||||
while dt > 0:
|
||||
if can_connect(ip, port):
|
||||
return
|
||||
else:
|
||||
yield gen.sleep(dt)
|
||||
dt = min(dt * 2, timeout - (loop.time() - tic))
|
||||
dt = min(dt * DT_SCALE, DT_MAX, timeout - (loop.time() - tic))
|
||||
raise TimeoutError(
|
||||
"Server at {ip}:{port} didn't respond in {timeout} seconds".format(**locals())
|
||||
)
|
||||
@@ -77,7 +83,7 @@ def wait_for_http_server(url, timeout=10):
|
||||
loop = ioloop.IOLoop.current()
|
||||
tic = loop.time()
|
||||
client = AsyncHTTPClient()
|
||||
dt = 0.1
|
||||
dt = DT_MIN
|
||||
while dt > 0:
|
||||
try:
|
||||
r = yield client.fetch(url, follow_redirects=False)
|
||||
@@ -99,7 +105,7 @@ def wait_for_http_server(url, timeout=10):
|
||||
yield gen.sleep(dt)
|
||||
else:
|
||||
return r
|
||||
dt = min(dt * 2, timeout - (loop.time() - tic))
|
||||
dt = min(dt * DT_SCALE, DT_MAX, timeout - (loop.time() - tic))
|
||||
|
||||
raise TimeoutError(
|
||||
"Server at {url} didn't respond in {timeout} seconds".format(**locals())
|
||||
|
Reference in New Issue
Block a user