lnd/queue
Gijs van Dam ea8a665772 queue: add BackpressureQueue[T] with Random Early Drop
Add a generic BackpressureQueue that uses a DropPredicate to proactively
shed load before the queue is completely full.

Two predicate types are provided:
- DropCheckFunc: length-only drop decision (func(queueLen int) bool)
- DropPredicate[T]: item-aware drop decision

RandomEarlyDrop returns a DropCheckFunc since RED only considers queue
depth. The AsDropPredicate helper adapts it to DropPredicate[T] for use
with BackpressureQueue.

In addition to the blocking Enqueue/Dequeue methods, the queue exposes
TryEnqueue (non-blocking send with drop check), Len, ReceiveChan, and
Close. These are needed by the actor package's BackpressureMailbox which
uses BackpressureQueue as its core buffer while implementing the Mailbox
interface's select-based iteration and lifecycle methods.

Property-based tests using pgregory.net/rapid verify queue invariants
(capacity bounds, FIFO ordering, model consistency) across randomized
enqueue/dequeue sequences with RED enabled.
2026-03-28 12:42:53 +01:00
..
back_pressure.go queue: add BackpressureQueue[T] with Random Early Drop 2026-03-28 12:42:53 +01:00
back_pressure_test.go queue: add BackpressureQueue[T] with Random Early Drop 2026-03-28 12:42:53 +01:00
circular_buf.go queue: add fixed size circular buffer 2020-03-17 08:22:23 +02:00
circular_buf_test.go queue: add fixed size circular buffer 2020-03-17 08:22:23 +02:00
gc_queue.go multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
gc_queue_test.go multi: add buffer.Write and pool.WriteBuffer, make GCQueue generic 2019-02-15 19:31:24 -08:00
go.mod queue: add BackpressureQueue[T] with Random Early Drop 2026-03-28 12:42:53 +01:00
go.sum queue: add BackpressureQueue[T] with Random Early Drop 2026-03-28 12:42:53 +01:00
priority_queue.go remove repetitive words 2024-03-07 14:05:47 +08:00
priority_queue_test.go queue: Introducing a general purpose priority queue. 2019-12-11 16:08:05 +01:00
queue.go queue: detect close of incoming channel 2020-04-08 08:54:03 +02:00
queue_test.go queue: replace defer cleanup with t.Cleanup 2022-10-13 17:47:04 +08:00