mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-07-26 13:47:03 +02:00
Require setting process priority for FrigateProcess (#19207)
This commit is contained in:
parent
b88fa9ece6
commit
21d3476bd9
@ -113,6 +113,12 @@ UPDATE_EMBEDDINGS_REINDEX_PROGRESS = "handle_embeddings_reindex_progress"
|
||||
UPDATE_BIRDSEYE_LAYOUT = "update_birdseye_layout"
|
||||
NOTIFICATION_TEST = "notification_test"
|
||||
|
||||
# IO Nice Values
|
||||
|
||||
PROCESS_PRIORITY_HIGH = 0
|
||||
PROCESS_PRIORITY_MED = 10
|
||||
PROCESS_PRIORITY_LOW = 19
|
||||
|
||||
# Stats Values
|
||||
|
||||
FREQUENCY_STATS_POINTS = 15
|
||||
|
@ -13,7 +13,7 @@ from pathvalidate import ValidationError, sanitize_filename
|
||||
|
||||
from frigate.comms.embeddings_updater import EmbeddingsRequestEnum, EmbeddingsRequestor
|
||||
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.db.sqlitevecq import SqliteVecQueueDatabase
|
||||
from frigate.models import Event
|
||||
@ -34,7 +34,12 @@ class EmbeddingProcess(FrigateProcess):
|
||||
metrics: DataProcessorMetrics | None,
|
||||
stop_event: MpEvent,
|
||||
) -> 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.metrics = metrics
|
||||
|
||||
|
@ -29,6 +29,7 @@ from frigate.const import (
|
||||
AUDIO_MAX_BIT_RANGE,
|
||||
AUDIO_MIN_CONFIDENCE,
|
||||
AUDIO_SAMPLE_RATE,
|
||||
PROCESS_PRIORITY_HIGH,
|
||||
)
|
||||
from frigate.data_processing.common.audio_transcription.model import (
|
||||
AudioTranscriptionModelRunner,
|
||||
@ -90,7 +91,9 @@ class AudioProcessor(FrigateProcess):
|
||||
camera_metrics: DictProxy,
|
||||
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.cameras = cameras
|
||||
|
@ -12,6 +12,7 @@ from frigate.comms.object_detector_signaler import (
|
||||
ObjectDetectorSubscriber,
|
||||
)
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import PROCESS_PRIORITY_HIGH
|
||||
from frigate.detectors import create_detector
|
||||
from frigate.detectors.detector_config import (
|
||||
BaseDetectorConfig,
|
||||
@ -97,7 +98,7 @@ class DetectorRunner(FrigateProcess):
|
||||
detector_config: BaseDetectorConfig,
|
||||
stop_event: MpEvent,
|
||||
) -> 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.cameras = cameras
|
||||
self.avg_speed = avg_speed
|
||||
|
@ -22,7 +22,7 @@ from frigate.config.camera.updater import (
|
||||
CameraConfigUpdateEnum,
|
||||
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.camera import JsmpegCamera
|
||||
from frigate.output.preview import PreviewRecorder
|
||||
@ -74,7 +74,9 @@ def check_disabled_camera_update(
|
||||
|
||||
class OutputProcess(FrigateProcess):
|
||||
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
|
||||
|
||||
def run(self) -> None:
|
||||
|
@ -21,6 +21,7 @@ from frigate.const import (
|
||||
EXPORT_DIR,
|
||||
MAX_PLAYLIST_SECONDS,
|
||||
PREVIEW_FRAME_TYPE,
|
||||
PROCESS_PRIORITY_LOW,
|
||||
)
|
||||
from frigate.ffmpeg_presets import (
|
||||
EncodeTypeEnum,
|
||||
@ -36,7 +37,7 @@ TIMELAPSE_DATA_INPUT_ARGS = "-an -skip_frame nokey"
|
||||
|
||||
|
||||
def lower_priority():
|
||||
os.nice(10)
|
||||
os.nice(PROCESS_PRIORITY_LOW)
|
||||
|
||||
|
||||
class PlaybackFactorEnum(str, Enum):
|
||||
|
@ -6,6 +6,7 @@ from multiprocessing.synchronize import Event as MpEvent
|
||||
from playhouse.sqliteq import SqliteQueueDatabase
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import PROCESS_PRIORITY_HIGH
|
||||
from frigate.models import Recordings, ReviewSegment
|
||||
from frigate.record.maintainer import RecordingMaintainer
|
||||
from frigate.util.process import FrigateProcess
|
||||
@ -15,7 +16,12 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class RecordProcess(FrigateProcess):
|
||||
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
|
||||
|
||||
def run(self) -> None:
|
||||
|
@ -4,6 +4,7 @@ import logging
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import PROCESS_PRIORITY_MED
|
||||
from frigate.review.maintainer import ReviewSegmentMaintainer
|
||||
from frigate.util.process import FrigateProcess
|
||||
|
||||
@ -12,7 +13,12 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class ReviewProcess(FrigateProcess):
|
||||
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
|
||||
|
||||
def run(self) -> None:
|
||||
|
@ -8,7 +8,12 @@ import numpy as np
|
||||
|
||||
from frigate.comms.embeddings_updater import EmbeddingsRequestEnum, EmbeddingsRequestor
|
||||
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.types import ModelStatusTypesEnum
|
||||
from frigate.util.process import FrigateProcess
|
||||
@ -24,6 +29,7 @@ class ClassificationTrainingProcess(FrigateProcess):
|
||||
def __init__(self, model_name: str) -> None:
|
||||
super().__init__(
|
||||
stop_event=None,
|
||||
priority=PROCESS_PRIORITY_LOW,
|
||||
name=f"model_training:{model_name}",
|
||||
)
|
||||
self.model_name = model_name
|
||||
|
@ -1,6 +1,7 @@
|
||||
import faulthandler
|
||||
import logging
|
||||
import multiprocessing as mp
|
||||
import os
|
||||
import threading
|
||||
from logging.handlers import QueueHandler
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
@ -16,6 +17,7 @@ class BaseProcess(mp.Process):
|
||||
def __init__(
|
||||
self,
|
||||
stop_event: MpEvent,
|
||||
priority: int,
|
||||
*,
|
||||
name: Optional[str] = None,
|
||||
target: Optional[Callable] = None,
|
||||
@ -23,6 +25,7 @@ class BaseProcess(mp.Process):
|
||||
kwargs: dict = {},
|
||||
daemon: Optional[bool] = None,
|
||||
):
|
||||
self.priority = priority
|
||||
self.stop_event = stop_event
|
||||
super().__init__(
|
||||
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
|
||||
|
||||
def pre_run_setup(self, logConfig: LoggerConfig | None = None) -> None:
|
||||
os.nice(self.priority)
|
||||
setproctitle(self.name)
|
||||
threading.current_thread().name = f"process:{self.name}"
|
||||
faulthandler.enable()
|
||||
|
@ -23,6 +23,7 @@ from frigate.const import (
|
||||
CACHE_DIR,
|
||||
CACHE_SEGMENT_FORMAT,
|
||||
REQUEST_REGION_GRID,
|
||||
PROCESS_PRIORITY_HIGH,
|
||||
)
|
||||
from frigate.log import LogPipe
|
||||
from frigate.motion import MotionDetector
|
||||
@ -445,7 +446,12 @@ class CameraCapture(FrigateProcess):
|
||||
camera_metrics: CameraMetrics,
|
||||
stop_event: MpEvent,
|
||||
) -> 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.shm_frame_count = shm_frame_count
|
||||
self.camera_metrics = camera_metrics
|
||||
@ -478,7 +484,12 @@ class CameraTracker(FrigateProcess):
|
||||
region_grid: list[list[dict[str, Any]]],
|
||||
stop_event: MpEvent,
|
||||
) -> 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.model_config = model_config
|
||||
self.labelmap = labelmap
|
||||
|
Loading…
Reference in New Issue
Block a user