Highlights

Contents

Part IV
04

CPU-bound, I/O-bound and bottlenecks

We locate the stage that prevents useful completions. Buying capacity for another stage can leave the wait unchanged. We will separate computation from I/O waits, identify bottlenecks, and interpret utilization.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Latency, throughput andLittle's law2p50, p95 and p99 latency3IOPS, bandwidth andstorage4CPU-bound, I/O-bound andbottlenecks5Scaling and Amdahl's law6Queueing and backpressure7Case study: capacityestimation

#Section 16CPU-bound work and service demand

A clip transcoder repeatedly calculates new pixel values while the score service mostly waits for reads. A CPU-bound workload reaches its capacity through computation. A busy core is useful evidence only when the time is spent on required work rather than avoidable serialization, spinning, or repeated failed attempts.

Suppose each Heron API request needs an illustrative 2 ms of CPU service. At 1,000 requests per second, CPU demand is 1,000×0.002=21,000\times0.002=2 CPU-seconds per second, equivalent to two fully occupied cores under ideal scheduling. Four fully available cores imply a service-demand ceiling of 4/0.002=2,0004/0.002=2,000 requests per second.

That ceiling assumes the work parallelizes and no other stage limits it. Garbage collection, synchronization, compression, and system work can consume capacity outside the timer. A single event loop can saturate one core while a host-level average shows spare cores. Inspect utilization at the thread or execution unit that owns the work.

Optimize the large measured CPU contribution first. Avoid repeating parsing or transformation when the same result can be reused safely. Then remeasure the entire path, because moving the CPU limit may expose the database as the next bottleneck. A capacity improvement is meaningful only when useful throughput or the relevant latency improves.

CPU SERVICE DEMAND IS DIFFERENT FROM WALL TIMEcore 1core 2core 3core 4r0r1r2r3r4r5r6r7r8r90 ms2 ms4 ms6 ms8 ms10 mstwo coresstay busytwo coresstay freeone request arrives every millisecond, each needs 2 ms of CPUone request: 200 ms in the service, 2 ms on a core1,000 req/s × 0.002 s = 2 CPU-seconds/sceiling: 4 cores / 0.002 s = 2,000 req/swaiting is notCPU work
Figure 2.19Illustrative 2 ms CPU demand at 1,000 requests/s requires two CPU-seconds/s.

#Section 17I/O-bound work and useful overlap

A score request can spend most of its time waiting for a remote service while using very little CPU. An I/O-bound workload reaches its useful limit through input/output capacity or waiting. Threads and asynchronous tasks let independent requests overlap those waits, but they do not shorten the remote operation itself.

Picture a request issuing a database call and yielding its execution slot. Another request can use that slot while the first waits. When the reply arrives, the scheduler resumes the original task. This increases overlap without reserving a fully active thread for every outstanding operation in an asynchronous design.

The shared dependency still sees all those operations. If it already saturates its storage or pool, raising concurrency puts more work into its queue. The callers look idle because their wait is elsewhere. This is why low application CPU and high user latency can occur together during overload.

Separate waiting for admission, waiting for a socket, waiting for storage, and waiting for a result. Bound simultaneous calls to each dependency, propagate deadlines, and cancel abandoned work. Use overlap until it fills actual service capacity; beyond that, reduce demand or increase the capacity that performs the I/O. The waiting location tells you which action is plausible.

Network-bound work

A network-bound workload reaches its useful limit through data transfer. Heron's illustrative live delivery payload is 200 MB/s, or 1.6 billion bits/s, while a 1-billion-bit/s link cannot carry even that payload alone. More CPU cannot create link capacity; distribute delivery or reduce transferred data where the product permits it.

Distinguish link saturation from CPU spent on compression or encryption. Both involve network responses, but they consume different limiting resources. Inspect transferred bytes, retransmissions, send-buffer waits, and CPU service before choosing a remedy. A slow recipient can also retain a buffer without saturating the whole gateway's link.

DIFFERENT WAITS NEED DIFFERENT FIXEScompute limitI/O waitevery core busycallers queue for computefix: optimize the work or add computeapp CPU mostly idlestoragequeued I/Oidle CPU does notprove spare capacityfix: bound overlap, inspect the I/O
Figure 2.20Illustrative compute saturation versus waiting callers; the relevant resource determines the remedy.

#Section 18Bottlenecks across a pipeline

Heron's application fleet accepts work faster than a shared database completes it. A bottleneck is the stage that limits sustainable throughput for the current workload. It can change when the request mix changes, so there is no permanent answer such as "the database is always the limit."

For serial stages with comparable counted work, path capacity cannot exceed the smallest stage capacity. If one request performs several operations at a stage, divide that stage's capacity by operations per request before comparing it with request throughput. A raw database-operation rate is not directly comparable with an API-request rate.

The limiting stage shows a combination of demand, saturation, and growing wait. A high resource percentage without a queue may simply reflect efficient usage. A queue without high CPU may reveal a lock or downstream I/O limit. Use completion rate and oldest waiting age to confirm that more arriving work does not produce proportional useful completions.

Then change one cause and observe the result. Reducing query page reads addresses storage demand; coalescing replaceable score snapshots addresses fan-out; widening a pool addresses only an admission limit when the database has room. State the predicted metric change before the experiment. A wrong prediction teaches you which stage you misunderstood.

THE SLOWEST SHARED STAGE LIMITS COMPLETIONSmany callersapp admissionDB service limitbounded result ratework waits hereslowest shared stagecompare stages in the same unit: divide DB capacity by operations per requestcapacity is a property of the whole path
Figure 2.21Illustrative pipeline capacity belongs to the whole path and its per-request service demands.

#Section 19Utilization and queueing near saturation

A worker that is busy most of the time seems productive, yet its queue grows after small bursts. Utilization is the fraction of service capacity in use at the resource being measured. A mean utilization value can hide uneven shards or intervals where arrivals exceed capacity.

A simplified M/M/1 queue assumes independent Poisson arrivals, exponential service durations, a single server, and a stable arrival rate below service rate. This is a teaching model, not a measurement claim about Heron. With arrival rate λ\lambda and service rate μ\mu, utilization is ρ=λ/μ\rho=\lambda/\mu.

W=1μ−λW=\frac{1}{\mu-\lambda}

Read this as: mean time in the model's system WW is the reciprocal of service rate μ\mu minus arrival rate λ\lambda. For μ=1,000\mu=1,000 operations per second, arrival rates of 500, 900, and 990 give mean times of 2, 10, and 100 ms. All include the model’s queue wait and service.

The mechanism matters more than fitting this equation blindly. When little spare service remains, a random burst takes longer to clear while new work keeps arriving. Real service-time variance, lock contention, and scheduling can alter the curve. Load-test the shape for your own workload and reserve capacity based on the tail objective you actually need.

M/M/1 MEAN TIME RISES AS SPARE SERVICE SHRINKSarrivals λ per secondmean time W, msμ500/s → 2 ms · L = 1900/s → 10 ms · L = 9990/s → 100 ms · L = 99in the systemW = 1 / (μ − λ), μ = 1,000/sρ = λ / μ, L = λWρ 0.5ρ 0.9ρ 0.99teaching model: Poisson arrivals, exponential service, one server
Figure 2.22Computed M/M/1 examples under the stated assumptions; these are not measured production latencies.

#Section 20Finding a limit with a load test

A single test at one request rate cannot show where a system begins losing control of its queue. Increase offered load in stages while holding the workload mix and data set explicit. The purpose is to connect each rate with completions, latency distribution, resource usage, and waiting state.

For Heron, warm score reads, cold score reads, writes, and live deliveries use different resources. Test their individual paths, then their expected mixture. Keep payload sizes and key popularity realistic. Uniform random keys may hide a hot match; repeatedly querying one key may exaggerate a cache hit rate that users do not receive.

Watch whether throughput plateaus while queue age increases. This identifies an offered-load increase that creates waiting rather than useful work. Repeat the relevant interval with a failed application server, cold cache, or slow dependency when that condition is part of the design’s promise. Keep the failure in place long enough to inspect recovery behavior.

Record what the load generator itself cannot sustain. Client CPU, sockets, or network limits can cap offered load before Heron saturates. A useful result states its boundaries and conditions, then names the next uncertain assumption. It is evidence for a particular workload, not a timeless capacity label for a machine.

MEASURE THE QUEUE WHEN USEFUL COMPLETIONS PLATEAUtest stagecompletions stop rising: find who owns the wait12345678offered workuseful completionsoldest queue ageshapes illustrative; hold the workload mix fixed between stages
Figure 2.23Illustrative experiment records offered work, useful completions, and queue age together.