From ebfe669ac2823323d519caa8a8c00cbb52c3e222 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Fri, 7 Jul 2023 13:37:41 -0600 Subject: [PATCH] Fix queues --- frigate/app.py | 9 +++++---- frigate/const.py | 4 ++++ frigate/util/builtin.py | 9 ++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/frigate/app.py b/frigate/app.py index 96c2f1d27..b72c6bcdd 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -26,6 +26,7 @@ from frigate.const import ( CLIPS_DIR, CONFIG_DIR, DEFAULT_DB_PATH, + DEFAULT_QUEUE_SIZE, EXPORT_DIR, MODEL_CACHE_DIR, RECORD_DIR, @@ -190,8 +191,8 @@ class FrigateApp: def init_queues(self) -> None: # Queues for clip processing - self.event_queue: Queue = ff.Queue() - self.event_processed_queue: Queue = ff.Queue() + self.event_queue: Queue = ff.Queue(DEFAULT_QUEUE_SIZE) + self.event_processed_queue: Queue = ff.Queue(DEFAULT_QUEUE_SIZE) self.video_output_queue: Queue = LQueue( maxsize=len(self.config.cameras.keys()) * 2 ) @@ -202,10 +203,10 @@ class FrigateApp: ) # Queue for recordings info - self.recordings_info_queue: Queue = ff.Queue() + self.recordings_info_queue: Queue = ff.Queue(DEFAULT_QUEUE_SIZE) # Queue for timeline events - self.timeline_queue: Queue = ff.Queue() + self.timeline_queue: Queue = ff.Queue(DEFAULT_QUEUE_SIZE) def init_database(self) -> None: def vacuum_db(db: SqliteExtDatabase) -> None: diff --git a/frigate/const.py b/frigate/const.py index b6b0e44bd..4565cb115 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -46,3 +46,7 @@ DRIVER_INTEL_iHD = "iHD" MAX_SEGMENT_DURATION = 600 MAX_PLAYLIST_SECONDS = 7200 # support 2 hour segments for a single playlist to account for cameras with inconsistent segment times + +# Queue Values + +DEFAULT_QUEUE_SIZE = 2000 * 1000 # 2MB \ No newline at end of file diff --git a/frigate/util/builtin.py b/frigate/util/builtin.py index 2f623567c..d85b6aca5 100644 --- a/frigate/util/builtin.py +++ b/frigate/util/builtin.py @@ -17,11 +17,10 @@ from typing import Any, Tuple import numpy as np import pytz import yaml -from faster_fifo import DEFAULT_CIRCULAR_BUFFER_SIZE, DEFAULT_TIMEOUT from faster_fifo import Queue as FFQueue from ruamel.yaml import YAML -from frigate.const import REGEX_HTTP_CAMERA_USER_PASS, REGEX_RTSP_CAMERA_USER_PASS +from frigate.const import DEFAULT_QUEUE_SIZE, REGEX_HTTP_CAMERA_USER_PASS, REGEX_RTSP_CAMERA_USER_PASS logger = logging.getLogger(__name__) @@ -69,7 +68,7 @@ class LimitedQueue(FFQueue): def __init__( self, maxsize=0, - max_size_bytes=DEFAULT_CIRCULAR_BUFFER_SIZE, + max_size_bytes=DEFAULT_QUEUE_SIZE, loads=None, dumps=None, ): @@ -80,7 +79,7 @@ class LimitedQueue(FFQueue): ) # Add a counter for the number of items in the queue self.lock = multiprocessing.Lock() # Add a lock for thread-safety - def put(self, x, block=True, timeout=DEFAULT_TIMEOUT): + def put(self, x, block=True, timeout=None): with self.lock: # Ensure thread-safety if self.maxsize > 0 and self.size.value >= self.maxsize: if block: @@ -95,7 +94,7 @@ class LimitedQueue(FFQueue): self.size.value += 1 return super().put(x, block=block, timeout=timeout) - def get(self, block=True, timeout=DEFAULT_TIMEOUT): + def get(self, block=True, timeout=None): item = super().get(block=block, timeout=timeout) with self.lock: # Ensure thread-safety if self.size.value <= 0 and not block: