Skip to content

Size the worker pool from the CPU allocation - #110

Merged
beetlebugorg merged 2 commits into
mainfrom
soak/apache-tuning
Aug 28, 2026
Merged

Size the worker pool from the CPU allocation#110
beetlebugorg merged 2 commits into
mainfrom
soak/apache-tuning

Conversation

@beetlebugorg

Copy link
Copy Markdown
Owner

What

The container sizes the httpd worker pool from its CPU allocation at start. An entrypoint reads the cgroup CPU quota and sets ServerLimit, ThreadsPerChild, and MaxRequestWorkers, so a larger container scales without a configuration change. A child is recycled after a number of connections, so its memory returns to the system. A soak test under a fixed CPU and memory limit sets the rule and the numbers, and ships as a tool under test/soak/.

Why

The image ran with the unconfigured httpd worker defaults, which allow hundreds of concurrent workers. Image work is CPU-bound and memory-heavy, so a large pool lowers throughput and raises memory. A soak test on 2, 4, and 6 vCPU containers found that throughput peaks near one worker per vCPU, and drops with more. Two threads per child, split across processes, give the lowest tail latency, because two processes share less ImageMagick lock state than one process with more threads. So auto sets ThreadsPerChild to 2 and ServerLimit to half the vCPU count, at least 2.

Verify

Auto-size: run the image at --cpus=2, 4, 6, and 8. The startup log reads ServerLimit=2/2/3/4. Set DIMS_SERVER_LIMIT to a number to pin it.

Soak: bash test/soak/run.sh. It runs the production image under a hard CPU and memory limit, drives a mixed resize, crop, format, and watermark load, and reports throughput, tail latency, errors, peak memory, and the OOM-kill count for each configuration. CPUS, MEM, and SOAK_GRID change the envelope and the sweep.

make test is unchanged. No C changed, and the test harness uses its own configuration.

- Read the cgroup CPU quota at start and set ServerLimit, ThreadsPerChild, and
  MaxRequestWorkers, so a larger container scales without a change.
- Recycle a child after DIMS_MAX_CONNECTIONS_PER_CHILD connections, so its
  memory returns to the system.
@beetlebugorg
beetlebugorg merged commit 7c30e03 into main Aug 28, 2026
6 checks passed
@beetlebugorg
beetlebugorg deleted the soak/apache-tuning branch August 28, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant