From 96d89eb50c049269f4ce06e4277d0f5270699fec Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 30 Apr 2025 08:42:53 -0500 Subject: [PATCH] Lower timeout in object processing (#17970) On startup, the object processing pipeline would be delayed for 10ms every iteration through the loop while the end event subscriber blocked. For users with large numbers of cameras and a fair amount of detected objects, this would cause the detected objects queue length to rise and frames to be eventually dropped, leading to processing delays, incorrect frame times applied to thumbnail_data, and other seemingly unexplainable things. --- frigate/const.py | 4 ++++ frigate/record/maintainer.py | 5 ++--- frigate/track/object_processing.py | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/frigate/const.py b/frigate/const.py index cf04ce7b2..183506a04 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -129,3 +129,7 @@ AUTOTRACKING_ZOOM_EDGE_THRESHOLD = 0.05 JWT_SECRET_ENV_VAR = "FRIGATE_JWT_SECRET" PASSWORD_HASH_ALGORITHM = "pbkdf2_sha256" + +# Queues + +FAST_QUEUE_TIMEOUT = 0.00001 # seconds diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py index 9f08f88a9..25783965c 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -27,6 +27,7 @@ from frigate.config import FrigateConfig, RetainModeEnum from frigate.const import ( CACHE_DIR, CACHE_SEGMENT_FORMAT, + FAST_QUEUE_TIMEOUT, INSERT_MANY_RECORDINGS, MAX_SEGMENT_DURATION, MAX_SEGMENTS_IN_CACHE, @@ -38,8 +39,6 @@ from frigate.util.services import get_video_properties logger = logging.getLogger(__name__) -QUEUE_READ_TIMEOUT = 0.00001 # seconds - class SegmentInfo: def __init__( @@ -536,7 +535,7 @@ class RecordingMaintainer(threading.Thread): # empty the object recordings info queue while True: (topic, data) = self.detection_subscriber.check_for_update( - timeout=QUEUE_READ_TIMEOUT + timeout=FAST_QUEUE_TIMEOUT ) if not topic: diff --git a/frigate/track/object_processing.py b/frigate/track/object_processing.py index 35bca4d5e..702df32bd 100644 --- a/frigate/track/object_processing.py +++ b/frigate/track/object_processing.py @@ -28,7 +28,7 @@ from frigate.config import ( RecordConfig, SnapshotsConfig, ) -from frigate.const import UPDATE_CAMERA_ACTIVITY +from frigate.const import FAST_QUEUE_TIMEOUT, UPDATE_CAMERA_ACTIVITY from frigate.events.types import EventStateEnum, EventTypeEnum from frigate.models import Event, Timeline from frigate.track.tracked_object import TrackedObject @@ -682,7 +682,9 @@ class TrackedObjectProcessor(threading.Thread): # cleanup event finished queue while not self.stop_event.is_set(): - update = self.event_end_subscriber.check_for_update(timeout=0.01) + update = self.event_end_subscriber.check_for_update( + timeout=FAST_QUEUE_TIMEOUT + ) if not update: break