Section 14.37

Computational versus communication bottleneck

Definition

A bottleneck is the resource that limits how fast a system completes work under a given workload. A computational bottleneck is a processor that cannot execute the needed instructions any faster; a communication bottleneck is a link, bus or radio channel that cannot move the needed data any faster. The difference that matters: added computation lowers throughput, the work completed per second, only when computation is the bottleneck. Behind a communication bottleneck, it shows only in processor busy time, energy, latency and spare capacity.

The idea

A sensor gateway forwards messages over a radio link that can carry 1000 messages per second. Its processor can prepare 2000 messages per second. A new security check adds processor time to each message, and the processor can now prepare only 1500 per second. A throughput benchmark shows 1000 messages per second before and after the change. The conclusion “the check costs nothing” is wrong. The processor is now busy two thirds of the time instead of half, which shortens battery life on a device whose processor sleeps when idle, and leaves less room for other tasks.

The gateway handles each message in a series of stages, preparation by the processor and then transmission over the link, and such a system behaves like a chain of pipes of different widths. The flow through the chain is set by the narrowest pipe, and narrowing any other pipe changes nothing at the outlet until that pipe becomes the narrowest. The picture stops being accurate in two ways. Real stages do not flow smoothly: messages arrive in bursts, wait in queues and wait for each other, so the actual throughput can fall below the capacity of the narrowest stage. And on a small device the stages often share one processor. If the processor also runs the radio’s protocol software, extra processor work can delay the radio even before the processor is the narrowest stage.

Two kinds of benchmark see these effects differently. A microbenchmark measures one small operation in isolation, for example the microseconds that one function call takes, repeated many times in a loop. A macrobenchmark, also called an end-to-end benchmark, measures a whole workload as a user experiences it: messages delivered per second, or the time from a user’s action to the device’s response. The microbenchmark shows what an operation costs; only the macrobenchmark shows whether that cost matters for a given workload. Each needs the other. A microbenchmark cannot say whether users will notice, and a macrobenchmark on a workload limited by communication cannot see a processor cost at all.

How it works

  1. Put every capacity in the same unit for the same message. For the processor, the capacity is 1 divided by the processor time that one message needs. For a link, it is the link’s data rate divided by the number of bytes that one message occupies on the link, headers and protocol overhead included.

  2. Find the smallest capacity. Every message must pass every stage, so throughput can be no higher than the smallest capacity, and the stage with that capacity is the bottleneck.

  3. Confirm it by measuring utilization, the fraction of time a resource is busy. At the observed throughput, the bottleneck is busy nearly all the time and every other stage has idle time.

  4. Make a hidden processor cost visible with a measurement or a workload in which the link cannot hide it:

    • measure processor time per message directly, with a cycle counter, a hardware counter of processor clock cycles, read around the code that handles one message;

    • measure processor utilization at a fixed message rate;

    • run a background task at the lowest priority that only counts loop iterations, so that it runs only in otherwise idle time; the fall in its count per second shows how much processor time the foreground work took;

    • change the workload so that the processor becomes the bottleneck: deliver messages inside the device without the radio (a loopback), use a faster link, or send smaller messages so that each needs less link time;

    • measure latency at a low load, where messages do not wait for the link, so that each message’s latency includes the added processor time.

  5. Repeat for each workload of interest. The bottleneck moves when the message size, the number of simultaneous flows or the mix of work changes.

Worked example

Take the gateway above. The link carries 1000 messages per second. The processor needs 0.5 ms per message, so its capacity is 1/(0.0005s)=20001 / (0.0005\ \text{s}) = 2000 messages per second. The security check adds 1/61/6 ms, about 0.167 ms, per message. The processor now needs 0.5+1/6=2/3≈0.6670.5 + 1/6 = 2/3 \approx 0.667 ms per message, and its capacity is 1/(2/3ms)=1.51 / (2/3\ \text{ms}) = 1.5 messages per millisecond, which is 1500 messages per second.

Throughput is at most the smaller capacity: min(2000,1000)=1000\min(2000, 1000) = 1000 before and min(1500,1000)=1000\min(1500, 1000) = 1000 after, where min\min picks the smaller value. The throughput benchmark sees no change.

Processor utilization does show the change. At 1000 messages per second, the processor is busy 1000×0.5ms=5001000 \times 0.5\ \text{ms} = 500 ms in every second before the change, which is 50%, and 1000×2/3ms≈6671000 \times 2/3\ \text{ms} \approx 667 ms after it, about 66.7%. Its idle time falls from 50% to about 33.3%, so a background counting task that runs only in idle time loses (50−33.3)/50≈1/3(50 - 33.3) / 50 \approx 1/3 of its count.

Moving the bottleneck shows it too. With a link, or a loopback path, that can carry 3000 messages per second, throughput is min(2000,3000)=2000\min(2000, 3000) = 2000 before and min(1500,3000)=1500\min(1500, 3000) = 1500 after: a loss of (2000−1500)/2000=0.25(2000 - 1500) / 2000 = 0.25, or 25%, which the radio link had hidden.

A microbenchmark of the check reports about 167 microseconds per message. A user of the gateway at 1000 messages per second sees no slower transfer. The user does see shorter battery life if the processor sleeps whenever it is idle, and, at low load, each message arrives about 0.167 ms later. The end-to-end measurements that show these effects are energy per message or battery life at the fixed rate, latency at low load, and throughput in a workload limited by the processor.

Stated precisely

Let every message pass through stages j=1,…,kj = 1, \dots, k, and let sjs_j be the busy time, in seconds, that stage jj spends on one message. The capacity of stage jj is Cj=1/sjC_j = 1 / s_j messages per second. In a steady state §11.27, where no queue grows without limit, the throughput XX, in messages per second, satisfies X≤min1≤j≤kCj,X \le \min_{1 \le j \le k} C_j, and the utilization of stage jj, the fraction of time it is busy, is Uj=Xsj≤1.U_j = X s_j \le 1. The second relation is called the utilization law. Suppose a change adds Δsj\Delta s_j seconds per message to a stage that is not the bottleneck, and 1/(sj+Δsj)1 / (s_j + \Delta s_j) stays above the smallest capacity. Then the bound on XX is unchanged, while UjU_j rises by XΔsjX \Delta s_j. In the example, XΔsj=1000×1/6000=1/6≈0.167X \Delta s_j = 1000 \times 1/6000 = 1/6 \approx 0.167: the rise from 50 to 66.7%.

These statements assume that every message uses every stage, that a stage’s time per message does not depend on the load, and that the stages are separate resources. When two stages share one resource, for example a processor that both checks messages and runs the radio protocol, their busy times add on that resource, and the shared resource must be treated as a single stage.

Limits and common mistakes

Equal throughput does not mean equal cost. It means only that the changed resource is not the bottleneck for this workload.

The minimum is an upper bound. Bursts, queueing, and protocols that wait for an acknowledgment before sending more can keep throughput well below the smallest capacity, and can let an added processor cost reduce throughput before the processor is fully busy.

The bottleneck depends on the workload. Small messages make the per-message processor cost dominate; large messages make the link dominate. A result for one message size does not carry over to another.

A workload built to expose the processor also changes other conditions: what the caches hold, how threads are scheduled, which code paths run. Its throughput measures the processor cost of this code, not what a user of the deployed system experiences; that question needs the end-to-end measurement.

Throughput hides tail latency §11.36, energy use and the loss of spare capacity for bursts. A processor that runs close to 100% utilization has little room left for a burst, and its queueing delay §14.38 grows sharply.

Microbenchmark costs do not add up simply into end-to-end costs. Warm caches make a microbenchmark faster than the same code inside a real workload. A saving in one part speeds up the whole only in proportion to that part’s share of the total time. By Amdahl’s law §18.5.1 [184], if a fraction ff of the time is spent in a part that is made rr times faster, the whole becomes 1/((1−f)+f/r)1 / ((1 - f) + f / r) times faster.

Questions answered

Which independent workload would reveal the hidden CPU overhead?

A workload in which the processor, not the communication link, limits throughput reveals the hidden CPU overhead, best combined with a direct measurement of processor time. While the link is the bottleneck, extra processor work per message does not change throughput, so throughput on that workload cannot show the overhead. Useful choices are:

In a gateway whose link carries 1000 messages per second, a check that lowers the processor’s capacity from 2000 to 1500 messages per second leaves throughput at 1000, raises processor utilization from 50 to about 66.7%, and, with a link of 3000 messages per second, lowers throughput from 2000 to 1500. The processor-limited workload changes cache and scheduling conditions, so report it as a measure of processor cost, and keep the end-to-end measurement for what users experience.

Related entries: Finite-window rate (§11.41), Queueing delay (§14.38), Availability (§1.10), Benchmark harness (§14.36), Instrumentation overhead (§11.32). Further reading: [184].