frigate/frigate
Daniel d982b3a782
Some checks failed
CI / AMD64 Build (push) Has been cancelled
CI / ARM Build (push) Has been cancelled
CI / Jetson Jetpack 6 (push) Has been cancelled
CI / AMD64 Extra Build (push) Has been cancelled
CI / ARM Extra Build (push) Has been cancelled
CI / Synaptics Build (push) Has been cancelled
CI / Assemble and push default build (push) Has been cancelled
perf(util): use monotonic clock and bounded deque in EventsPerSecond (#23520)
* perf(util): use monotonic clock and bounded deque in EventsPerSecond

EventsPerSecond is updated on every captured frame, every detection and
every processed frame across all cameras and detectors. The previous
implementation derived timestamps from datetime.now().timestamp() (wall
clock), so an NTP or manual clock adjustment could skew the rolling-window
expiry; it also stored timestamps in a list and expired them with
del self._timestamps[0] (O(n) per removal) plus a periodic slice-copy to
cap growth.

Switch to time.monotonic() for the interval math (correct by construction
and immune to wall-clock jumps) and a collections.deque(maxlen=...) so
expiry is O(1) (popleft) and retention is bounded automatically. This
mirrors the deque-based expiry already used in video/ffmpeg.py and
watchdog.py. Observable output is unchanged.

Adds frigate/test/test_builtin.py covering rate calculation, window
expiry and the memory bound.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test: drop test_timestamps_are_memory_bounded

It only asserted that deque(maxlen=) caps length, which is stdlib behavior
rather than something this change needs to verify.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 07:38:41 -06:00
..
api cache the preview_frames directory listing so concurrent per-camera frame requests share one scan instead of each re-listing the whole directory (#23526) 2026-06-20 14:56:05 -05:00
camera Debug replay resolution (#23287) 2026-05-22 08:39:52 -06:00
comms Restore runtime state on startup (#23326) 2026-05-27 12:03:09 -06:00
config UI tweaks (#23492) 2026-06-16 08:56:52 -05:00
data_processing Miscellaneous fixes (#23177) 2026-05-12 10:20:39 -06:00
db More mypy cleanup (#22658) 2026-03-26 12:54:12 -06:00
detectors Miscellaneous fixes (#23394) 2026-06-04 12:48:58 -06:00
embeddings Debug replay fixes (#23276) 2026-05-21 08:12:53 -06:00
events Miscellaneous fixes (#23335) 2026-05-29 06:53:17 -06:00
genai Allow GenAI providers to be initialized lazily (#23482) 2026-06-14 11:40:33 -05:00
images Replace green screen with error message and force camera_fps to 0 (#4544) 2022-11-28 21:47:20 -06:00
jobs Refactor motion search (#23378) 2026-06-01 12:08:46 -05:00
motion Optimize more mypy classes (#22637) 2026-03-25 12:53:19 -06:00
object_detection Miscellaneous fixes (#23279) 2026-05-22 07:52:01 -06:00
output Refactor move_preview_frames function (#23264) 2026-05-20 10:52:47 -06:00
ptz guard norfair distance against non-finite and zero-area boxes that could crash autotracking cameras (#23475) 2026-06-13 16:23:30 -05:00
record Replace export ffmpeg argument blocklist with a structural allowlist (#23478) 2026-06-13 16:43:22 -06:00
review Inverse mypy and more mypy fixes (#22645) 2026-03-25 19:30:59 -05:00
service_manager Add metrics page for embeddings and face / license plate processing times (#15818) 2025-02-08 12:47:01 -06:00
stats Miscellaneous fixes (#23317) 2026-05-27 09:19:11 -06:00
test perf(util): use monotonic clock and bounded deque in EventsPerSecond (#23520) 2026-06-21 07:38:41 -06:00
track guard norfair distance against non-finite and zero-area boxes that could crash autotracking cameras (#23475) 2026-06-13 16:23:30 -05:00
util perf(util): use monotonic clock and bounded deque in EventsPerSecond (#23520) 2026-06-21 07:38:41 -06:00
video Add recording keyframe analysis to camera probe dialog (#23453) 2026-06-11 14:16:41 -06:00
__init__.py app container and config schema 2021-01-26 21:40:33 -06:00
__main__.py Handle SIGINT with forkserver (#18860) 2025-08-16 10:20:33 -05:00
app.py Miscellaneous fixes (#23358) 2026-05-30 21:35:03 -06:00
const.py Improve credential redaction handling (#23265) 2026-05-20 15:59:01 -06:00
debug_replay.py Miscellaneous fixes (#23317) 2026-05-27 09:19:11 -06:00
ffmpeg_presets.py Upgrade ffmpeg to 8 by default (#23393) 2026-06-03 12:28:28 -05:00
log.py Add languages (#21870) 2026-02-03 13:29:52 -06:00
models.py Improve motion review and add motion search (#22253) 2026-03-05 17:53:48 -06:00
mypy.ini More mypy cleanup (#22658) 2026-03-26 12:54:12 -06:00
plus.py fix: upload_image parses response body before checking HTTP status (#22475) 2026-03-16 17:34:30 -06:00
storage.py Improve readability by removing trailing digits caused by floating number conversion (#22934) 2026-04-20 06:35:48 -06:00
timeline.py Display more scores in Tracking Details (#22799) 2026-04-07 10:06:22 -06:00
types.py Media sync API refactor and UI (#21542) 2026-02-26 21:27:56 -07:00
watchdog.py Miscellaneous fixes (#23032) 2026-04-29 16:20:19 -06:00