ANDREW/
MenuWriting
← Back to writing

SYSTEMS / CPU / REQUEST LATENCY

The CPU Had Headroom. What Was the Service Waiting For?

I wanted to know what would justify adding background work to a machine that still looked underused.

In a four-vCPU Linux VM, one view of the test said there was plenty of room. Around 75% of aggregate CPU time was idle. The vCPU running the HTTP service was fully busy. Even on that small machine, the resource available to the service depended on where the work could run.

That observation left a second question. If a request was slow, how much could I explain from CPU measurements? I ran a separate diagnostic to follow the response beyond the computation. Here is what each comparison established, and what I would still need to know before making a service commitment.

Two experiment summaries. Four vCPU blocks illustrate the original PSI setup, and four TCP_NODELAY columns show the separate diagnostic.
The four vCPU blocks illustrate placement. The panels summarize separate runs. The TCP panel uses the nearest-rank p50 described below.

Follow the service to the CPU it can use

I pinned a small HTTP service to one vCPU and its client to another. Every request performed the same computation, and the client waited for the entire response before issuing another request. Across three blocks I compared a baseline without a competing process, contention on the service’s vCPU, the same competing process moved to a different vCPU, and a final run with that process removed. The service stayed where it was.

During contention, the service’s vCPU was 100% busy in all three measurement windows. Aggregate idle time ranged from 74.85% to 74.87%. The service’s cgroup CPU pressure stall information, or PSI, put some at 24.16% to 24.33%. That measures the share of the window during which at least one task in the group was stalled for CPU. It describes the group over time, so it cannot tell me what fraction of a particular request was spent waiting.

When I moved or removed the competing work, the service’s CPU pressure returned to near baseline. Per-CPU utilization showed where the workload was concentrated. The cgroup measurement gave me evidence that the service itself had to wait.

Keep the result that missed the bar

Before the run, I set a demonstration criterion: in each block, request p95 under contention had to reach at least 1.25 times that block’s uncontended baseline. Request p95 covers the full response as observed by the client. These are the three comparisons, calculated from the recorded requests.

Original experiment: request p95 with and without same-vCPU contention
BlockBaseline (ms)Contended (ms)Ratio1.25× rule
168.01585.9351.263477×Met
268.85583.9271.218894×Missed
367.61184.9271.256116×Met

The experiment missed its joint criteria because block two fell short. The placement comparison still showed CPU waiting under contention. The 1.25× rule was set for this demonstration, and a production service would need acceptance criteria tied to its own workload and commitments.

One measurement kept me looking. For each request, I subtracted the elapsed time inside the server’s computation region from the client’s elapsed time for the full response. Across the original phases, the median of that remainder ranged from about 41 to 45 ms. It was also present in the uncontended baseline. Several things can happen outside that region, including scheduling and HTTP reads and writes. The remainder showed me where to look next.

Trace the response after the application writes it

I ran the next diagnostic without the competing process. The computation and response format stayed the same, with separate writes for the HTTP headers and body. I changed TCP_NODELAY on the accepted server socket in an off, on, on, off sequence and verified the setting for each segment. Enabling it disables the Nagle algorithm on that socket.

Separate diagnostic without competing CPU load
SegmentServer TCP_NODELAYMedian time outside the computation region (ms)
1Off45.05
2On0.25
3On0.24
4Off45.43

The table uses the nearest-rank p50. For each segment, sort the per-request differences and take the value at rank ⌈0.5 × n⌉, where n is the number of observations.

The remainder shrank when I enabled the option and returned when I turned it off. For all 305 measured requests across the two off segments, the application had submitted the response body to the socket before the ACK for the header bytes, and the body appeared in the packet capture just after that ACK. Taken together, the reversal and the recorded ordering support a wait associated with Nagle and ACK behavior for these small responses in this test setup.

The packet trace records the timing I observed. It leaves the ACK timer itself unmeasured. I also did not vary TCP_NODELAY under the original contention conditions, so these results cannot tell me how much of the earlier delay came from each mechanism. Computation CPU time and the client’s request rate changed during the diagnostic as well. Both experiments used a single outstanding request in a short VM run, which leaves production capacity to be measured separately.

Make the resource decision on client results

Before committing more background work, I would agree with the service owner on the request load, success rate and response time we need to sustain. Then I would ask engineering to confirm where the service and the new work can run in the intended deployment. A representative comparison with and without the background work should measure complete requests from the client, with resource and request-path observations available to explain any change.

If the service misses those limits, the people who can allocate resources or change the commitment have a choice to make. They can place the work elsewhere, change the allocation, or reduce the load the team promises to support. I would check the chosen arrangement against the same client criteria. That is the evidence I would use to decide whether the machine has room for the work.

Measurement scope and sources

The measurements come from two controlled Linux VM runs on November 28, 2026. The original experiment recorded 5,386 measured requests, and the follow-up diagnostic recorded 1,479. The Linux references describe the interfaces. The experiment results come from the retained request, system and packet records.

Share this article