Repository navigation
Conversation
|
I've deployed this for testing as v0.3.1. Once testing evaluation is done I'll merge the pull request. |
There was a problem hiding this comment.
Pull request overview
This PR bounds ffmpeg/ffprobe resource usage in the beholder frame-grab server to stop CPU/thread saturation (issue #10). It replaces the unbounded ExecutionContext.global used for captures with a fixed, bounded BoundedExecutor that sheds load, adds hard timeouts around subprocesses via a new ProcessRunner, coalesces concurrent requests for the same frame, and returns jittered 503 Retry-After responses when the pool is saturated.
Changes:
- New concurrency primitives:
BoundedExecutor(bounded pool + queue,maxWaitstale-drop,submit/execute) andProcessRunner(timed subprocess execution that force-kills overruns and cleans up partial output). - Request coalescing (single-flight) in
ImageCapturekeyed on the target frame path, plus configurable ffmpeg/ffprobe timeouts and-threads 2on ffmpeg commands. - Load shedding in
CaptureEndpointswith a newServiceUnavailableerror type (jitteredRetry-After), health endpoint moved off the EC, and newAppConfig/reference.confsettings withBEHOLDER_*overrides.
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
etc/jdk/BoundedExecutor.scala |
New bounded pool with backpressure, stale-work deadline, and StaleWorkException. |
etc/jdk/ProcessRunner.scala |
New timed subprocess runner that kills overruns and captures output via temp files. |
ImageCapture.scala |
Single-flight coalescing of concurrent captures; FrameGrabber injection seam. |
api/CaptureEndpoints.scala |
Submits captures to the bounded pool; 503s on saturation/stale, key check before slot claim. |
api/ErrorMsg.scala |
Adds ServiceUnavailable + jittered busy factory. |
api/Endpoints.scala |
Wires Retry-After header + JSON body as a tapir oneOfVariant. |
api/HealthEndpoints.scala |
Uses Future.successful so /health never schedules work. |
etc/ffmpeg/FfmpegUtil.scala |
Timeout on ffmpeg, deletes partial output on failure, -threads 2. |
etc/ffmpeg/FfprobeUtil.scala |
Object→class refactor with configurable timeout via ProcessRunner. |
etc/ffmpeg/FfprobeService.scala |
Doc-only clarification (runs on calling thread). |
AppConfig.scala / reference.conf |
New capture/ffmpeg/ffprobe tunables with env overrides. |
Main.scala |
Builds the shared capture executor and logs the capture policy. |
ImageType.scala, ImageCacheImpl.scala, CaptureRequest.scala, etc/xml/Converters.scala, etc/circe/CirceCodecs.scala |
Formatting/scaladoc reflow and codec registration for ServiceUnavailable. |
Test suites (BoundedExecutorSuite, ProcessRunnerSuite, ServiceUnavailableSuite, HealthEndpointsSuite, AppConfigSuite, ImageCaptureSuite, CaptureEndpointsSuite, FfmpegUtilSuite, FfprobeUtilSuite, others) |
New coverage for coalescing, timeouts, load shedding, and reformatting of existing suites. |
I did not find concrete, objective defects to flag: the coalescing leader/waiter/failure paths, the overflow-safe deadline check, the tapir error-variant wiring, the object→class FfprobeUtil refactor, and the config/env defaults are all consistent and backed by tests. That said, this is a substantial, subtle concurrency change (a hand-rolled bounded pool, forced process termination, single-flight coalescing where waiters block worker threads, and load-shedding semantics) whose correctness depends on runtime behavior that static review cannot fully validate, so it warrants human sign-off.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
task: add support for deinterlace
Change to improve performance related to #10 and mbari-org/vars-feedback#335
This PR adds CPU and time bounds to ffmpeg calls. I removed the use of Scala's
ExecutionContext.globalfor running ffmpeg processes and add aBoundedExecutorwhich applies a concurrency limit, back pressure and a mechanism for killing stalled ffmpeg processes.Concurrency and back pressure
BEHOLDER_CAPTURE_MAXWAIT.Retry-Afteron both 503 paths now returns a variable jitter (2–8s). A constant value would cause every client to burst back simultaneously, refiling the BoundedExecutor again. BAD!Process handling
Correctness
New configuration