Require setting process priority for FrigateProcess (#19207)

This commit is contained in:
Nicolas Mowen 2025-07-18 11:23:06 -06:00 committed by GitHub
parent b88fa9ece6
commit 21d3476bd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 63 additions and 12 deletions

View File

@ -113,6 +113,12 @@ UPDATE_EMBEDDINGS_REINDEX_PROGRESS = "handle_embeddings_reindex_progress"
UPDATE_BIRDSEYE_LAYOUT = "update_birdseye_layout" UPDATE_BIRDSEYE_LAYOUT = "update_birdseye_layout"
NOTIFICATION_TEST = "notification_test" NOTIFICATION_TEST = "notification_test"
# IO Nice Values
PROCESS_PRIORITY_HIGH = 0
PROCESS_PRIORITY_MED = 10
PROCESS_PRIORITY_LOW = 19
# Stats Values # Stats Values
FREQUENCY_STATS_POINTS = 15 FREQUENCY_STATS_POINTS = 15

View File

@ -13,7 +13,7 @@ from pathvalidate import ValidationError, sanitize_filename
from frigate.comms.embeddings_updater import EmbeddingsRequestEnum, EmbeddingsRequestor from frigate.comms.embeddings_updater import EmbeddingsRequestEnum, EmbeddingsRequestor
from frigate.config import FrigateConfig from frigate.config import FrigateConfig
from frigate.const import CONFIG_DIR, FACE_DIR from frigate.const import CONFIG_DIR, FACE_DIR, PROCESS_PRIORITY_HIGH
from frigate.data_processing.types import DataProcessorMetrics from frigate.data_processing.types import DataProcessorMetrics
from frigate.db.sqlitevecq import SqliteVecQueueDatabase from frigate.db.sqlitevecq import SqliteVecQueueDatabase
from frigate.models import Event from frigate.models import Event
@ -34,7 +34,12 @@ class EmbeddingProcess(FrigateProcess):
metrics: DataProcessorMetrics | None, metrics: DataProcessorMetrics | None,
stop_event: MpEvent, stop_event: MpEvent,
) -> None: ) -> None:
super().__init__(stop_event, name="frigate.embeddings_manager", daemon=True) super().__init__(
stop_event,
PROCESS_PRIORITY_HIGH,
name="frigate.embeddings_manager",
daemon=True,
)
self.config = config self.config = config
self.metrics = metrics self.metrics = metrics

View File

@ -29,6 +29,7 @@ from frigate.const import (
AUDIO_MAX_BIT_RANGE, AUDIO_MAX_BIT_RANGE,
AUDIO_MIN_CONFIDENCE, AUDIO_MIN_CONFIDENCE,
AUDIO_SAMPLE_RATE, AUDIO_SAMPLE_RATE,
PROCESS_PRIORITY_HIGH,
) )
from frigate.data_processing.common.audio_transcription.model import ( from frigate.data_processing.common.audio_transcription.model import (
AudioTranscriptionModelRunner, AudioTranscriptionModelRunner,
@ -90,7 +91,9 @@ class AudioProcessor(FrigateProcess):
camera_metrics: DictProxy, camera_metrics: DictProxy,
stop_event: MpEvent, stop_event: MpEvent,
): ):
super().__init__(stop_event, name="frigate.audio_manager", daemon=True) super().__init__(
stop_event, PROCESS_PRIORITY_HIGH, name="frigate.audio_manager", daemon=True
)
self.camera_metrics = camera_metrics self.camera_metrics = camera_metrics
self.cameras = cameras self.cameras = cameras

View File

@ -12,6 +12,7 @@ from frigate.comms.object_detector_signaler import (
ObjectDetectorSubscriber, ObjectDetectorSubscriber,
) )
from frigate.config import FrigateConfig from frigate.config import FrigateConfig
from frigate.const import PROCESS_PRIORITY_HIGH
from frigate.detectors import create_detector from frigate.detectors import create_detector
from frigate.detectors.detector_config import ( from frigate.detectors.detector_config import (
BaseDetectorConfig, BaseDetectorConfig,
@ -97,7 +98,7 @@ class DetectorRunner(FrigateProcess):
detector_config: BaseDetectorConfig, detector_config: BaseDetectorConfig,
stop_event: MpEvent, stop_event: MpEvent,
) -> None: ) -> None:
super().__init__(stop_event, name=name, daemon=True) super().__init__(stop_event, PROCESS_PRIORITY_HIGH, name=name, daemon=True)
self.detection_queue = detection_queue self.detection_queue = detection_queue
self.cameras = cameras self.cameras = cameras
self.avg_speed = avg_speed self.avg_speed = avg_speed

View File

@ -22,7 +22,7 @@ from frigate.config.camera.updater import (
CameraConfigUpdateEnum, CameraConfigUpdateEnum,
CameraConfigUpdateSubscriber, CameraConfigUpdateSubscriber,
) )
from frigate.const import CACHE_DIR, CLIPS_DIR from frigate.const import CACHE_DIR, CLIPS_DIR, PROCESS_PRIORITY_MED
from frigate.output.birdseye import Birdseye from frigate.output.birdseye import Birdseye
from frigate.output.camera import JsmpegCamera from frigate.output.camera import JsmpegCamera
from frigate.output.preview import PreviewRecorder from frigate.output.preview import PreviewRecorder
@ -74,7 +74,9 @@ def check_disabled_camera_update(
class OutputProcess(FrigateProcess): class OutputProcess(FrigateProcess):
def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None: def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None:
super().__init__(stop_event, name="frigate.output", daemon=True) super().__init__(
stop_event, PROCESS_PRIORITY_MED, name="frigate.output", daemon=True
)
self.config = config self.config = config
def run(self) -> None: def run(self) -> None:

View File

@ -21,6 +21,7 @@ from frigate.const import (
EXPORT_DIR, EXPORT_DIR,
MAX_PLAYLIST_SECONDS, MAX_PLAYLIST_SECONDS,
PREVIEW_FRAME_TYPE, PREVIEW_FRAME_TYPE,
PROCESS_PRIORITY_LOW,
) )
from frigate.ffmpeg_presets import ( from frigate.ffmpeg_presets import (
EncodeTypeEnum, EncodeTypeEnum,
@ -36,7 +37,7 @@ TIMELAPSE_DATA_INPUT_ARGS = "-an -skip_frame nokey"
def lower_priority(): def lower_priority():
os.nice(10) os.nice(PROCESS_PRIORITY_LOW)
class PlaybackFactorEnum(str, Enum): class PlaybackFactorEnum(str, Enum):

View File

@ -6,6 +6,7 @@ from multiprocessing.synchronize import Event as MpEvent
from playhouse.sqliteq import SqliteQueueDatabase from playhouse.sqliteq import SqliteQueueDatabase
from frigate.config import FrigateConfig from frigate.config import FrigateConfig
from frigate.const import PROCESS_PRIORITY_HIGH
from frigate.models import Recordings, ReviewSegment from frigate.models import Recordings, ReviewSegment
from frigate.record.maintainer import RecordingMaintainer from frigate.record.maintainer import RecordingMaintainer
from frigate.util.process import FrigateProcess from frigate.util.process import FrigateProcess
@ -15,7 +16,12 @@ logger = logging.getLogger(__name__)
class RecordProcess(FrigateProcess): class RecordProcess(FrigateProcess):
def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None: def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None:
super().__init__(stop_event, name="frigate.recording_manager", daemon=True) super().__init__(
stop_event,
PROCESS_PRIORITY_HIGH,
name="frigate.recording_manager",
daemon=True,
)
self.config = config self.config = config
def run(self) -> None: def run(self) -> None:

View File

@ -4,6 +4,7 @@ import logging
from multiprocessing.synchronize import Event as MpEvent from multiprocessing.synchronize import Event as MpEvent
from frigate.config import FrigateConfig from frigate.config import FrigateConfig
from frigate.const import PROCESS_PRIORITY_MED
from frigate.review.maintainer import ReviewSegmentMaintainer from frigate.review.maintainer import ReviewSegmentMaintainer
from frigate.util.process import FrigateProcess from frigate.util.process import FrigateProcess
@ -12,7 +13,12 @@ logger = logging.getLogger(__name__)
class ReviewProcess(FrigateProcess): class ReviewProcess(FrigateProcess):
def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None: def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None:
super().__init__(stop_event, name="frigate.review_segment_manager", daemon=True) super().__init__(
stop_event,
PROCESS_PRIORITY_MED,
name="frigate.review_segment_manager",
daemon=True,
)
self.config = config self.config = config
def run(self) -> None: def run(self) -> None:

View File

@ -8,7 +8,12 @@ import numpy as np
from frigate.comms.embeddings_updater import EmbeddingsRequestEnum, EmbeddingsRequestor from frigate.comms.embeddings_updater import EmbeddingsRequestEnum, EmbeddingsRequestor
from frigate.comms.inter_process import InterProcessRequestor from frigate.comms.inter_process import InterProcessRequestor
from frigate.const import CLIPS_DIR, MODEL_CACHE_DIR, UPDATE_MODEL_STATE from frigate.const import (
CLIPS_DIR,
MODEL_CACHE_DIR,
UPDATE_MODEL_STATE,
PROCESS_PRIORITY_LOW,
)
from frigate.log import redirect_output_to_logger from frigate.log import redirect_output_to_logger
from frigate.types import ModelStatusTypesEnum from frigate.types import ModelStatusTypesEnum
from frigate.util.process import FrigateProcess from frigate.util.process import FrigateProcess
@ -24,6 +29,7 @@ class ClassificationTrainingProcess(FrigateProcess):
def __init__(self, model_name: str) -> None: def __init__(self, model_name: str) -> None:
super().__init__( super().__init__(
stop_event=None, stop_event=None,
priority=PROCESS_PRIORITY_LOW,
name=f"model_training:{model_name}", name=f"model_training:{model_name}",
) )
self.model_name = model_name self.model_name = model_name

View File

@ -1,6 +1,7 @@
import faulthandler import faulthandler
import logging import logging
import multiprocessing as mp import multiprocessing as mp
import os
import threading import threading
from logging.handlers import QueueHandler from logging.handlers import QueueHandler
from multiprocessing.synchronize import Event as MpEvent from multiprocessing.synchronize import Event as MpEvent
@ -16,6 +17,7 @@ class BaseProcess(mp.Process):
def __init__( def __init__(
self, self,
stop_event: MpEvent, stop_event: MpEvent,
priority: int,
*, *,
name: Optional[str] = None, name: Optional[str] = None,
target: Optional[Callable] = None, target: Optional[Callable] = None,
@ -23,6 +25,7 @@ class BaseProcess(mp.Process):
kwargs: dict = {}, kwargs: dict = {},
daemon: Optional[bool] = None, daemon: Optional[bool] = None,
): ):
self.priority = priority
self.stop_event = stop_event self.stop_event = stop_event
super().__init__( super().__init__(
name=name, target=target, args=args, kwargs=kwargs, daemon=daemon name=name, target=target, args=args, kwargs=kwargs, daemon=daemon
@ -47,6 +50,7 @@ class FrigateProcess(BaseProcess):
self.__log_queue = frigate.log.log_listener.queue self.__log_queue = frigate.log.log_listener.queue
def pre_run_setup(self, logConfig: LoggerConfig | None = None) -> None: def pre_run_setup(self, logConfig: LoggerConfig | None = None) -> None:
os.nice(self.priority)
setproctitle(self.name) setproctitle(self.name)
threading.current_thread().name = f"process:{self.name}" threading.current_thread().name = f"process:{self.name}"
faulthandler.enable() faulthandler.enable()

View File

@ -23,6 +23,7 @@ from frigate.const import (
CACHE_DIR, CACHE_DIR,
CACHE_SEGMENT_FORMAT, CACHE_SEGMENT_FORMAT,
REQUEST_REGION_GRID, REQUEST_REGION_GRID,
PROCESS_PRIORITY_HIGH,
) )
from frigate.log import LogPipe from frigate.log import LogPipe
from frigate.motion import MotionDetector from frigate.motion import MotionDetector
@ -445,7 +446,12 @@ class CameraCapture(FrigateProcess):
camera_metrics: CameraMetrics, camera_metrics: CameraMetrics,
stop_event: MpEvent, stop_event: MpEvent,
) -> None: ) -> None:
super().__init__(stop_event, name=f"frigate.capture:{config.name}", daemon=True) super().__init__(
stop_event,
PROCESS_PRIORITY_HIGH,
name=f"frigate.capture:{config.name}",
daemon=True,
)
self.config = config self.config = config
self.shm_frame_count = shm_frame_count self.shm_frame_count = shm_frame_count
self.camera_metrics = camera_metrics self.camera_metrics = camera_metrics
@ -478,7 +484,12 @@ class CameraTracker(FrigateProcess):
region_grid: list[list[dict[str, Any]]], region_grid: list[list[dict[str, Any]]],
stop_event: MpEvent, stop_event: MpEvent,
) -> None: ) -> None:
super().__init__(stop_event, name=f"frigate.process:{config.name}", daemon=True) super().__init__(
stop_event,
PROCESS_PRIORITY_HIGH,
name=f"frigate.process:{config.name}",
daemon=True,
)
self.config = config self.config = config
self.model_config = model_config self.model_config = model_config
self.labelmap = labelmap self.labelmap = labelmap