Choosing a Policy for a Full Queue

A bounded queue needs a documented outcome when an insertion reaches capacity, including which entries are affected.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Compare two observations
  2. Check the next removal
  3. Simulate a burst larger than storage
  4. Make overflow visible in a test and operational data

Compare two observations

In capacity three with A, B, C waiting, an insertion of D may fail and keep all three entries. A recent-history buffer may discard A and retain B, C, D. Ring storage can implement either policy under the same storage constraint.

Check the next removal

After handling the attempted insert, remove one and check whether it yields A or B according to the promise. The resulting retention policy belongs in the queue contract.[1]

Simulate a burst larger than storage

For capacity two and arrivals A, B, C with no removals, rejecting C preserves A and B. Dropping the oldest retains B and C. Blocking delays completion of C's insertion until there is room. Select a policy from the meaning of lost or delayed work. See ring buffer layout for the separate storage representation.

Capacity 2, third arrival C
Reject newest → [A, B], C reported rejected
Drop oldest  → [B, C], A reported dropped
Block        → [A, B], C pending

Make overflow visible in a test and operational data

A telemetry sampler may tolerate an explicit count of dropped old readings. A queue of promised exports needs the caller to learn when work was rejected. Test capacity one, an exact fit and a burst just beyond capacity.

References

  1. Jeff Erickson, Algorithms ↩