Try
↑ ↓ move↵ openesc close
In this lesson · topic 2 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 2

Capacity, full-queue policy and Little's law

5 min read

A queue meets a burst

Step through a small example. The queue has six places, and one consumer takes one message at a time.

A queue meets a burst

Step 1 / 6
producerconsumerarrivals match the consumerqueue, 6 places
waiting
1 of 6
  1. A steady stream

    Messages arrive about as fast as the consumer finishes them. The queue holds one message or none. This is a toy with six places, to show the idea.

The parts

A queue has a producer side, where messages come in, and a consumer side, where they leave in the order they arrived. In between it has a capacity, the number of messages it is allowed to hold. Without a limit a queue can eat all the memory or disk of the machine that hosts it, so real queues have one, even if it is large.

The consumers are the other half. How many there are, and how fast each one is, decide how quickly the queue drains. Adding a consumer helps only if there is work waiting for it to take.

What a full queue does

Once the queue is full, the next message has to go somewhere. There are three common answers.

Block the producer. The send call waits until there is room. Nothing is lost, but the delay moves to the producer, and the producer’s own callers may be waiting on it. If the producer cannot afford to wait, the overload spreads upstream.

Drop the newest. The arriving message is refused. The messages already in the queue are kept. This is simple, and it protects the work already accepted.

Drop the oldest. The message at the head is evicted to make room. The queue always holds the most recent data. That suits a stream where only the latest reading matters, such as a position update, and it is wrong for an order that must not disappear.

None of these creates capacity. They choose who pays: the producer, the newest message, or the oldest one.

Little’s law

Little’s law says that in a stable system, the average number of items inside equals the average rate at which they arrive times the average time each one spends inside.

In symbols, L = λ W. Here L is the average number waiting, λ is the rate at which messages enter, and W is the average time a message spends in the queue.

Put numbers on it with the lab’s default setup. Averaged over the whole run, 12.9measured messages were waiting. Messages entered the queue at 6.86 a secondmeasured, and each spent 1.88 smeasured in the queue on average. Multiply the last two and you get 12.9measured, the same as the first.

The lab measures the two sides separately. L comes from watching the queue depth over time. λ comes from counting messages as they enter. W comes from timing each message. They agree because of the law, and not because the code was written to make them agree.

The law holds whatever the arrival pattern is and whatever order messages are served in. It is about averages, so it says nothing about the slowest messages. The fourth topic comes back to that.

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