Documentation
¶
Overview ¶
Package backpressure provides queue-based backpressure control for GRIP streaming pipelines.
It coordinates three components to manage load:
- Queue: bounded message buffer with configurable capacity
- Limiter: concurrency limiter for in-flight processing
- Policy: strategy for handling capacity exhaustion (hard reject, soft allow, drop oldest)
The Controller ties these together and exposes Acquire/Release semantics for stream engines to throttle message processing.
Usage ¶
q := backpressure.NewQueue(1000)
l := backpressure.NewLimiter(100)
ctrl := backpressure.NewController(backpressure.PolicyHardReject, q, l)
if err := ctrl.Acquire(ctx); err != nil {
// backpressure triggered
}
defer ctrl.Release()
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrQueueClosed = capacity.ErrQueueClosed
ErrQueueClosed is exported for backward compatibility.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller coordinates backpressure decisions using policy, limiter, and queue.
func NewController ¶
func NewController( policy Policy, queue *Queue, limiter *Limiter, ) *Controller
func (*Controller) Acquire ¶
func (c *Controller) Acquire(ctx context.Context) (bool, error)
Acquire decides whether execution may proceed.
Contract: - acquired == true → caller MUST call Release(true) - acquired == false → caller MUST NOT call Release
func (*Controller) Close ¶
func (c *Controller) Close()
Close shuts down the queue and unblocks all waiters.
func (*Controller) Release ¶
func (c *Controller) Release(acquired bool)
Release releases capacity and wakes one queued waiter.
type Decision ¶
type Decision int
Decision represents what to do with an incoming request.
func ResolveDecision ¶
ResolveDecision decides what to do given policy and state.
Invariants: - DecisionReject MUST NOT execute or enqueue - DecisionAllow MUST consume capacity - DecisionQueue MUST NOT consume capacity - DecisionAllowWithSignal MUST consume capacity - Unknown policy MUST fail closed
type Limiter ¶
Limiter is a type alias for capacity.Limiter. Kept for backward compatibility within backpressure package.