From e640981cc4fca80405376d4453325fa0622f64d1 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Wed, 28 Jun 2023 13:39:39 +0300 Subject: [PATCH] Performance: multiprocessing improvement (#6936) * Add faster-fifo dependency for improved performance * isort --- Dockerfile | 4 +++- frigate/app.py | 2 +- frigate/events/external.py | 2 +- frigate/events/maintainer.py | 3 ++- frigate/log.py | 2 +- frigate/timeline.py | 3 ++- frigate/types.py | 3 ++- requirements-wheels.txt | 1 + 8 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0c244f901..058bb6ad7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -127,7 +127,9 @@ RUN apt-get -qq update \ libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \ libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev \ # scipy dependencies - gcc gfortran libopenblas-dev liblapack-dev && \ + gcc gfortran libopenblas-dev liblapack-dev \ + # faster-fifo dependencies + g++ cython3 && \ rm -rf /var/lib/apt/lists/* RUN wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py \ diff --git a/frigate/app.py b/frigate/app.py index 9d85f461e..8d3972343 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -6,12 +6,12 @@ import shutil import signal import sys import traceback -from multiprocessing.queues import Queue from multiprocessing.synchronize import Event as MpEvent from types import FrameType from typing import Optional import psutil +from faster_fifo import Queue from peewee_migrate import Router from playhouse.sqlite_ext import SqliteExtDatabase from playhouse.sqliteq import SqliteQueueDatabase diff --git a/frigate/events/external.py b/frigate/events/external.py index 5422de260..910aee35f 100644 --- a/frigate/events/external.py +++ b/frigate/events/external.py @@ -6,10 +6,10 @@ import logging import os import random import string -from multiprocessing.queues import Queue from typing import Optional import cv2 +from faster_fifo import Queue from frigate.config import CameraConfig, FrigateConfig from frigate.const import CLIPS_DIR diff --git a/frigate/events/maintainer.py b/frigate/events/maintainer.py index 264ab1142..28fb4646b 100644 --- a/frigate/events/maintainer.py +++ b/frigate/events/maintainer.py @@ -3,10 +3,11 @@ import logging import queue import threading from enum import Enum -from multiprocessing.queues import Queue from multiprocessing.synchronize import Event as MpEvent from typing import Dict +from faster_fifo import Queue + from frigate.config import EventsConfig, FrigateConfig from frigate.models import Event from frigate.types import CameraMetricsTypes diff --git a/frigate/log.py b/frigate/log.py index 5dbf4eed0..ac51fc3da 100644 --- a/frigate/log.py +++ b/frigate/log.py @@ -7,10 +7,10 @@ import signal import threading from collections import deque from logging import handlers -from multiprocessing.queues import Queue from types import FrameType from typing import Deque, Optional +from faster_fifo import Queue from setproctitle import setproctitle from frigate.util import clean_camera_user_pass diff --git a/frigate/timeline.py b/frigate/timeline.py index 9ca617ba9..6cfcbe928 100644 --- a/frigate/timeline.py +++ b/frigate/timeline.py @@ -3,9 +3,10 @@ import logging import queue import threading -from multiprocessing.queues import Queue from multiprocessing.synchronize import Event as MpEvent +from faster_fifo import Queue + from frigate.config import FrigateConfig from frigate.events.maintainer import EventTypeEnum from frigate.models import Timeline diff --git a/frigate/types.py b/frigate/types.py index 8c3e54654..23751d499 100644 --- a/frigate/types.py +++ b/frigate/types.py @@ -1,8 +1,9 @@ from multiprocessing.context import Process -from multiprocessing.queues import Queue from multiprocessing.sharedctypes import Synchronized from typing import Optional, TypedDict +from faster_fifo import Queue + from frigate.object_detection import ObjectDetectProcess diff --git a/requirements-wheels.txt b/requirements-wheels.txt index f02317e41..19bd1077c 100644 --- a/requirements-wheels.txt +++ b/requirements-wheels.txt @@ -1,5 +1,6 @@ click == 8.1.* Flask == 2.3.* +faster-fifo == 1.4.* imutils == 0.5.* matplotlib == 3.7.* mypy == 0.942