Add short delay to reduce CPU usage when the queue is empty in frigate object detection, output, and video modules

This commit is contained in:
Sergey Krashevich 2023-06-23 02:45:40 +03:00
parent 9e531b0b5b
commit e72a315893
No known key found for this signature in database
GPG Key ID: 625171324E7D3856
3 changed files with 5 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import queue
import signal import signal
import threading import threading
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
import time
import numpy as np import numpy as np
from setproctitle import setproctitle from setproctitle import setproctitle
@ -106,6 +107,7 @@ def run_detector(
try: try:
connection_id = detection_queue.get(timeout=1) connection_id = detection_queue.get(timeout=1)
except queue.Empty: except queue.Empty:
time.sleep(0.01) # short delay to reduce CPU usage when the queue is empty
continue continue
input_frame = frame_manager.get( input_frame = frame_manager.get(
connection_id, connection_id,

View File

@ -8,6 +8,7 @@ import queue
import signal import signal
import subprocess as sp import subprocess as sp
import threading import threading
import time
import traceback import traceback
from wsgiref.simple_server import make_server from wsgiref.simple_server import make_server
@ -598,6 +599,7 @@ def output_frames(config: FrigateConfig, video_output_queue):
regions, regions,
) = video_output_queue.get(True, 1) ) = video_output_queue.get(True, 1)
except queue.Empty: except queue.Empty:
time.sleep(0.01) # short delay to reduce CPU usage when the queue is empty
continue continue
frame_id = f"{camera}{frame_time}" frame_id = f"{camera}{frame_time}"

View File

@ -750,6 +750,7 @@ def process_frames(
try: try:
frame_time = frame_queue.get(True, 1) frame_time = frame_queue.get(True, 1)
except queue.Empty: except queue.Empty:
time.sleep(0.01) # short delay to reduce CPU usage when the queue is empty
continue continue
current_frame_time.value = frame_time current_frame_time.value = frame_time