Table of Contents
Round robin gives each eligible item a turn in a fixed order. In CPU scheduling, runnable tasks take turns using the processor for a limited time. In load balancing, successive requests can go to successive servers.

How round-robin CPU scheduling works
The scheduler takes the first runnable task from a queue and lets it run for up to a time slice, also called a quantum. If the slice expires and the task still needs CPU time, it returns to the back of the runnable queue. A task that finishes leaves the queue. A task waiting for input or output becomes runnable again when the event it is waiting for completes.

Round robin rotates through the runnable queue.
Example: Three jobs with a two-millisecond time slice
Suppose A needs 5 ms, B needs 3 ms, and C needs 1 ms. All are ready at time zero, and the example ignores the time spent switching tasks.
| Time (ms) | Task | Result at end of turn |
|---|---|---|
| 0–2 | A | 3 ms left |
| 2–4 | B | 1 ms left |
| 4–5 | C | Finished |
| 5–7 | A | 1 ms left |
| 7–8 | B | Finished |
| 8–9 | A | Finished |
Short slices let other tasks have a turn sooner, but increase the number of context switches. Long slices reduce that overhead and can make a newly runnable task wait longer. Equal turns also don’t guarantee that jobs will finish equally quickly.
How round robin distributes web requests
With three equivalent backends, a load balancer might send requests to A, B, C, then A again. This spreads request counts. If requests vary widely in cost, one backend can still end up doing more work than another. Weighted round robin gives some servers more turns. Least-connections routing uses the number of active connections to choose a backend. The Nginx load-balancing guide shows how those policies are used.
Reader Comments 0
Sign in with email or Google to join the discussion.