ShM-MP

How should a pool of CPU workers be split, and why does the answer move on a VM?

Data loaders for deep learning run a pool of processes: some produce items (decode, transform), others consume them (hand them to the GPU). We ran a minimal version of that pipeline in C over every split of producers and consumers, on bare metal and on virtual machines, and asked a classic bottleneck model to explain and to choose the split.

The model

Each item costs a producer c of work and makes a consumer wait d for the device. Three limits cap throughput: what the producers can make, what the consumers can take, and what the cores can run. Throughput follows the lowest of the three.

So give the slower role more processes until the cores run out. A surplus on the side that waits is almost free, because a blocked process holds no core; a surplus on the side that computes takes cores. A VM changes nothing in the model, only its costs: waiting can start to burn CPU, and some hypervisors charge for idle vCPUs.

Try it: the three limits over the split, with 36 processes in all

A sketch from the model, not a measurement. Make the device wait longer and the best split moves toward more consumers.

producers' limit consumers' limit cores' limit throughput

Every split, measured

We ran all 36 splits, 1 to 32 producers by 1 to 32 consumers, on five platforms, with two ways to wait (block: sleep until woken, as real queues do; sleep: check, sleep 1 µs, check again) and two doses: ⟨10,100⟩, where consumers are slower, and ⟨100,10⟩, where producers are. Each square is a split's throughput as a share of the best.

Platform
Waiting
Dose ⟨c,d⟩ in µs
consumers K →
◯ best split (fewest processes within 5% of the top)× the model's pickrows: producers P

Can the model choose the split?

We fed the model costs from five runs of the even split (4,4) on each platform, let it pick a split, and committed the pick before the sweep. We compared it with a simple tuner that starts at (4,4) and keeps doubling or halving whichever role helps, like tf.data's AUTOTUNE. The table gives each method's largest loss against the best split.

Largest loss over both doses, rounded to whole percent. Even (4,4): range over all four settings. Ryzen's best: the bare-metal best split carried to that platform, under block. The tuner used runs; the model used five.

A follow-up, with its rules committed before any run

What it means