Try
↑ ↓ move↵ openesc close
In this lesson · topic 1 of 7
  1. 1. Why put a buffer in the middle
  2. 2. Capacity, full-queue policy and Little's law
  3. 3. Bursts against a 200-message buffer
  4. 4. Why a bigger buffer only adds delay
  5. 5. Watch the age of the oldest message
  6. 6. One slow message holds up the line
  7. 7. Sizing, waiting and dropping: three checks

Topic 1

Why put a buffer in the middle

5 min read

Two parts that do not run at the same speed

A producer creates messages: orders, clicks, emails to send. A consumer does something with each one. If the producer calls the consumer directly, the two have to be ready at the same moment. When the consumer is busy, the producer either waits or fails.

That is fine while the traffic is smooth. Real traffic is not. A sale starts, a batch job wakes up, a mobile app reconnects after a tunnel. For a few seconds messages arrive far faster than anyone can handle them, and then it goes quiet again.

A queue sits in between. The producer hands over a message and moves on. The consumer takes the next message when it is ready. The queue is a buffer, and it exists to hold the difference between the two speeds.

The same average, with bursts

Take three consumers that each finish 3 messages a second. Together they can do 9 messages a secondmeasured. Producers send 6 messages a second on average, which is two thirds of that. On average there is plenty of spare capacity.

Now compare two ways of sending those 6 messages a second. One is a steady stream. The other packs the same traffic into bursts at four times the average rate, with quiet time in between. Neither queue has a limit.

Predict first

The producers send bursts at four times their average rate, and the average is two thirds of what the consumers can do. A queue with room for 200 messages sits in between. What do you expect?

What the buffer buys

With no limit on the queue, the steady stream never has more than 15measured messages waiting at its busiest moment. The bursty stream, which has exactly the same average, reaches 101measured messages waiting. A message in the steady stream waits 0.15 smeasured on average. In the bursty stream it waits 3.25 smeasured.

So bursts cost waiting even when capacity is plentiful. The queue is where that waiting happens, and that is better than the alternatives. If the queue holds one message, 50%measured of the bursty messages are thrown away. If it holds 10, 41%measured are. If it holds 200, 0%measured are.

The next topic looks at how a queue works. The lesson after that shows what happens when the average, and not just the peak, is more than the consumers can do.

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