From 2fead92dc5a0d3703edeb9388f122463b7e42eee Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Wed, 24 Dec 2025 08:57:38 +0000 Subject: [PATCH] SSE updates every 5 seconds is probably fine, we don't really need every second. #3 --- server/handlers/api/alerts.py | 7 +++++-- server/handlers/api/spots.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/server/handlers/api/alerts.py b/server/handlers/api/alerts.py index cd8cf38..99ed286 100644 --- a/server/handlers/api/alerts.py +++ b/server/handlers/api/alerts.py @@ -10,6 +10,9 @@ import tornado_eventsource.handler from core.prometheus_metrics_handler import api_requests_counter from core.utils import serialize_everything +SSE_HANDLER_MAX_QUEUE_SIZE = 100 +SSE_HANDLER_QUEUE_CHECK_INTERVAL = 5000 + # API request handler for /api/v1/alerts class APIAlertsHandler(tornado.web.RequestHandler): @@ -63,11 +66,11 @@ class APIAlertsStreamHandler(tornado_eventsource.handler.EventSourceHandler): self.query_params = {k: v[0].decode("utf-8") for k, v in self.request.arguments.items()} # Create a alert queue and add it to the web server's list. The web server will fill this when alerts arrive - self.alert_queue = Queue(maxsize=100) + self.alert_queue = Queue(maxsize=SSE_HANDLER_MAX_QUEUE_SIZE) self.sse_alert_queues.append(self.alert_queue) # Set up a timed callback to check if anything is in the queue - self.heartbeat = tornado.ioloop.PeriodicCallback(self._callback, 1000) + self.heartbeat = tornado.ioloop.PeriodicCallback(self._callback, SSE_HANDLER_QUEUE_CHECK_INTERVAL) self.heartbeat.start() except Exception as e: diff --git a/server/handlers/api/spots.py b/server/handlers/api/spots.py index 81a4e31..37b8423 100644 --- a/server/handlers/api/spots.py +++ b/server/handlers/api/spots.py @@ -10,6 +10,9 @@ import tornado_eventsource.handler from core.prometheus_metrics_handler import api_requests_counter from core.utils import serialize_everything +SSE_HANDLER_MAX_QUEUE_SIZE = 1000 +SSE_HANDLER_QUEUE_CHECK_INTERVAL = 5000 + # API request handler for /api/v1/spots class APISpotsHandler(tornado.web.RequestHandler): @@ -65,11 +68,11 @@ class APISpotsStreamHandler(tornado_eventsource.handler.EventSourceHandler): self.query_params = {k: v[0].decode("utf-8") for k, v in self.request.arguments.items()} # Create a spot queue and add it to the web server's list. The web server will fill this when spots arrive - self.spot_queue = Queue(maxsize=1000) + self.spot_queue = Queue(maxsize=SSE_HANDLER_MAX_QUEUE_SIZE) self.sse_spot_queues.append(self.spot_queue) # Set up a timed callback to check if anything is in the queue - self.heartbeat = tornado.ioloop.PeriodicCallback(self._callback, 1000) + self.heartbeat = tornado.ioloop.PeriodicCallback(self._callback, SSE_HANDLER_QUEUE_CHECK_INTERVAL) self.heartbeat.start() except Exception as e: