From 11ea8f40d57730b96d5bb0d95f60f4ceddbc433d Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 30 Nov 2023 09:43:35 +0100 Subject: [PATCH] add Spawner.poll_jitter to avoid alignment of poll callbacks, e.g. after Hub restart --- jupyterhub/spawner.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/jupyterhub/spawner.py b/jupyterhub/spawner.py index 369d3d7d..3ee9485d 100644 --- a/jupyterhub/spawner.py +++ b/jupyterhub/spawner.py @@ -490,6 +490,20 @@ class Spawner(LoggingConfigurable): """, ).tag(config=True) + poll_jitter = Float( + 0.1, + min=0, + max=1, + help=""" + Jitter fraction for poll_interval. + + Avoids alignment of poll calls for many Spawners, + e.g. when restarting JupyterHub, which restarts all polls for running Spawners. + + `poll_jitter=0` means no jitter, 0.1 means 10%, etc. + """, + ).tag(config=True) + _callbacks = List() _poll_callback = Any() @@ -1405,7 +1419,9 @@ class Spawner(LoggingConfigurable): self.stop_polling() self._poll_callback = PeriodicCallback( - self.poll_and_notify, 1e3 * self.poll_interval + self.poll_and_notify, + 1e3 * self.poll_interval, + jitter=self.poll_jitter, ) self._poll_callback.start()