mirror of
https://github.com/lightningnetwork/lnd.git
synced 2026-08-13 12:32:48 +02:00
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. |
||
|---|---|---|
| .. | ||
| back_pressure.go | ||
| back_pressure_test.go | ||
| circular_buf.go | ||
| circular_buf_test.go | ||
| gc_queue.go | ||
| gc_queue_test.go | ||
| go.mod | ||
| go.sum | ||
| priority_queue.go | ||
| priority_queue_test.go | ||
| queue.go | ||
| queue_test.go | ||