Try
↑ ↓ move↵ openesc close
In this lesson · topic 3 of 7
  1. 1. Why callers need a limit
  2. 2. Five ways to count
  3. 3. Race five limiters across a window edge
  4. 4. What each limiter admits at the edge
  5. 5. The sliding counter, worked by hand
  6. 6. Pricing requests and stacking limits
  7. 7. Choosing a limiter under pressure

Topic 3

Race five limiters across a window edge

7 min read

One stream, five limiters

The lab starts with a burst that straddles a window edge. All five limiters see exactly the same arrivals. The first chart shows how many requests each admitted in the last 20 ticks, against the limit. The table lists the worst window each one allowed, and the state it needed.

Predict before you press play

The limit is 20 per 20 ticks and two bursts of 20 land either side of a window edge. Which algorithm's line will rise far above the limit?

limit = 20 per 20 ticksrate = 1 per tickoffered so far 40 requests in 70 ticks

Requests admitted in the last 20 ticks
Requests admitted in the last 20 ticks. Text version available below the chart.013253850tick 1tick 36tick 70timeadmitted
Requests rejected so far
Requests rejected so far. Text version available below the chart.013253850tick 1tick 36tick 70timerejected
Requests arriving at each tick
Requests arriving at each tick. Text version available below the chart.013253850tick 1tick 36tick 70timearrivals

All five on the same traffic

Each row is one algorithm. Worst window is the most it admitted in any 20 ticks in a row, against a limit of 20.
AlgorithmAdmittedRejectedWorst windowPeak state per clientMean delay
Fixed window40040 (2x the limit)2 valuesnone
Sliding window log20202020 valuesnone
Sliding window counter2020203 valuesnone
Token bucket211921 (1.1x the limit)2 valuesnone
Leaky bucket (queue)21192020 values10.0 ticks

Red means a window let through more than the limit. Memory counts values stored per client: the log keeps one timestamp per admitted request, the leaky bucket keeps its queue, and the rest keep two or three numbers.

Full-page version with guided experiments: Rate limiter algorithms lab.

Experiments

  1. Switch the traffic to Bursty. Look at the rejected chart. The token bucket and the leaky bucket reject the same share, but one of them delays the requests it admits.
  2. Switch to Steady and set the offered traffic to 0.8 of the limit. The average is under the limit, yet some algorithms still reject requests. Find which ones, and why.
  3. Shrink the bucket size to 4. The refill rate has not changed. See what happens to the token bucket under bursty traffic.
  4. Raise the limit to 60 and read the peak state column. Which algorithms get bigger?
  5. Change the seed. The numbers move a little, but the ordering of the algorithms should not.

The full-page lab also has five guided experiments you can apply with one click.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms