From 51a904aaa2ac79e8e528488a6323086d308c6aa7 Mon Sep 17 00:00:00 2001 From: Marcello Costagliola Date: Sat, 24 Oct 2026 01:13:56 +0200 Subject: [PATCH] Size workers by the CPUs the container may use Puma and the Resque pool count their workers from Concurrent.processor_count, which sees every CPU of the host. A container started with a CPU limit (ONCE's CPU setting, docker run --cpus) still gets a worker for every host core: on a 16-CPU host with a 2-CPU limit, 11 web workers and 8 job workers share two CPUs' worth of time, and the memory of all of them. Concurrent.available_processor_count is the container's CPU quota when it has one and processor_count otherwise. It is never more than processor_count, so a host without a limit keeps the counts it has today. Co-Authored-By: Claude Opus 5.5 --- config/puma.rb | 4 +++- config/resque-pool.yml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index 06220b8e5..1e5638a67 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -32,7 +32,9 @@ # Workers do not work on JRuby or Windows (both of which do not support # processes). # -worker_count = (Concurrent.processor_count * 0.666).ceil +# Count the CPUs this container may use: its CPU quota when it has one (ONCE's +# CPU limit, `docker run --cpus`), otherwise every CPU it can see. +worker_count = (Concurrent.available_processor_count * 0.666).ceil workers ENV.fetch("WEB_CONCURRENCY") { worker_count } ENV["JOB_CONCURRENCY"] ||= worker_count.to_s diff --git a/config/resque-pool.yml b/config/resque-pool.yml index 64f569bde..3b782064e 100644 --- a/config/resque-pool.yml +++ b/config/resque-pool.yml @@ -1 +1 @@ -default: <%= (Concurrent.processor_count * 0.5).ceil %> +default: <%= (Concurrent.available_processor_count * 0.5).ceil %>