Batching queueing and concurrency
Quick answer
Batching groups requests into one computation. Queueing is waiting for service; concurrency is the number of overlapping operations. Together they determine throughput, tail latency and resource pressure. Examples use Python and NumPy 2.3.5. Timing examples use fixed synthetic values; actual benchmark timings are in the milestone. ByteMind execution is unverified.
Single-worker queue
finish=0; waits=[]for a in [0,2,4]: start=max(a,finish); waits.append(start-a); finish=start+3print(waits)Expected output (locally tested): [0, 1, 2]. The waiting time grows when arrivals exceed capacity.
How it works
Static batching uses an explicit input batch; dynamic batching waits briefly for compatible requests and dispatches at a size or time limit. Every request still needs its own response identifier and deadline. A maximum wait alone cannot guarantee end-to-end latency because execution and downstream delays remain. For a single FIFO worker with arrival a, duration d and previous finish f, start=max(a,f), finish=start+d, wait=start-a. Overlapping workers can increase throughput until CPU, memory bandwidth or another resource saturates. More workers may then worsen latency. For stable systems, Little’s law relates average in-system count to arrival rate times average residence time; do not apply steady-state identities to an accumulating unbounded backlog. Set bounded queues, explicit overload rejection and deadline policies. Use synthetic arrivals to understand mechanisms before performing a small approved local load test.
Preserve batch identities
requests=[("r1",2),("r2",5)]print([(key,x*3) for key,x in requests])Expected output (locally tested): [('r1', 6), ('r2', 15)]. Each result remains associated with its request.
Common mistakes
Do not average per-batch durations and call the result end-to-end per-request latency. Do not let retries multiply a saturated workload indefinitely.
Practice and next steps
Simulate a single FIFO worker and inspect waiting times when interarrival time is shorter than service time. Compare with spaced arrivals.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Batching queueing and concurrency — knowledge check
Apply batching queueing and concurrency to small examples and debugging scenarios.
What is queue wait?
Why limit dynamic batching delay?
What can excessive concurrency do?
What is needed to align batched outputs?
When is Little’s law useful?