Request Batching Simulator

The trick that tripled our throughput, as a toy you can break.

Transformers are built for throughput. A forward pass over 16 inputs costs nowhere near 16 times a single input, because the fixed overhead (kernel launches, memory movement) dominates small workloads. So production ML servers do something that sounds backwards: when a request arrives, they wait a few milliseconds in the hope that others arrive too, then run the whole group through the model at once. Each request pays a small waiting tax, and in return all of them ride much cheaper.

This simulation does the same thing. Requests arrive randomly at your chosen rate, a batcher collects up to N of them for at most W milliseconds, and the "model" charges a realistic sub-linear cost per batch. Try 800 RPS with batching off (batch size 1) and the queue grows without bound while p99 goes vertical, same as on a bad Tuesday in production. Then give it a 10ms window and a batch of 16 and watch the same traffic become boring, which is the whole point.

—
p50 latency
—
p99 latency
—
throughput
—
queue depth

The model here charges 8ms + 2ms × batch^0.7 per forward pass, which is roughly how real inference scales: a batch of 16 costs about 2.2× a batch of 1 instead of 16×, and that gap is the entire business case for batching. The real story, including the load-testing cluster we built to find this: Terraform, GKE, and the 150-Millisecond Question →