perf(pools): size image/rayon pools to the CFS quota (effective_parallelism)

The thumbnail decode semaphore, the transcode rayon pool, and the ffmpeg
video-thumbnail fan-out all sized from std::thread::available_parallelism(),
which honours CPU affinity but ignores the CFS bandwidth quota (--cpus /
cgroup cpu.max). Under a container quota they therefore permit one CPU-heavy
task per *host* core onto cores the scheduler can't grant — the same
over-subscription the runtime worker pool had.

Switch all three to common::runtime::effective_parallelism() (= min(affinity,
CFS quota)), and fix the doc comments that wrongly claimed available_parallelism
respects cgroup quotas. No change off-quota (effective == available there); the
env overrides (OXICLOUD_THUMBNAIL_DECODE_CONCURRENCY,
OXICLOUD_VIDEO_THUMBNAIL_CONCURRENCY) are unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JG5yYZ9s868mJwqT2Qz7ez
This commit is contained in:
Claude
2026-06-22 08:46:24 +00:00
parent 7b26ff014c
commit 5629ba6200
3 changed files with 16 additions and 15 deletions
@@ -31,13 +31,14 @@ pub const MAX_TRANSCODE_SIZE: u64 = 5 * 1024 * 1024;
/// Minimum number of threads in the dedicated transcoding pool
const MIN_TRANSCODE_THREADS: usize = 2;
/// Compute the number of transcoding threads: half the available CPUs,
/// with a floor of `MIN_TRANSCODE_THREADS`. `available_parallelism()`
/// respects cgroup limits (Docker/K8s) and CPU affinity masks.
/// Compute the number of transcoding threads: half the available CPUs, with a
/// floor of `MIN_TRANSCODE_THREADS`. Sized by
/// [`effective_parallelism`](crate::common::runtime::effective_parallelism),
/// which respects CPU affinity **and** the CFS quota (Docker/K8s `--cpus`) —
/// unlike bare `available_parallelism()`, which ignores the quota and would
/// over-size this CPU-bound pool under a container limit.
fn transcode_thread_count() -> usize {
let cpus = std::thread::available_parallelism()
.map(|n| n.get())
.unwrap_or(MIN_TRANSCODE_THREADS);
let cpus = crate::common::runtime::effective_parallelism();
(cpus / 2).max(MIN_TRANSCODE_THREADS)
}