Documentation
¶
Overview ¶
Package loadshed provides priority-based load shedding.
Load shedding protects services during overload by rejecting low-priority requests first. Five priority levels are supported: Critical, High, Normal, Low, and BestEffort.
Example:
shedder := loadshed.New(loadshed.Config{
MaxLoad: 1000,
})
if err := shedder.Admit(priority); err != nil {
return status.Error(codes.ResourceExhausted, "load shed")
}
Package loadshed provides priority-based load shedding for gRPC execution pipelines.
Load shedding protects services from overload by rejecting lower-priority requests when capacity utilization exceeds configurable thresholds.
Priority levels (highest to lowest):
- PriorityCritical (100% — always admitted)
- PriorityHigh (80%)
- PriorityNormal (60%)
- PriorityLow (30%)
- PriorityBestEffort (10%)
Usage:
shedder := loadshed.NewShedder(loadshed.Config{
Capacity: 1000,
})
// In handler:
ctx := loadshed.WithPriority(ctx, loadshed.PriorityHigh)
if err := shedder.AdmitFromContext(ctx); err != nil {
return status.Error(codes.ResourceExhausted, "overloaded")
}
defer shedder.Done()
Integration with GRIP pipelines:
u := unary.New(unary.WithLoadShedder(shedder))
Index ¶
Constants ¶
const ( PriorityCritical = ils.PriorityCritical PriorityHigh = ils.PriorityHigh PriorityNormal = ils.PriorityNormal PriorityLow = ils.PriorityLow PriorityBestEffort = ils.PriorityBestEffort )
Variables ¶
var DefaultThresholds = ils.DefaultThresholds
DefaultThresholds returns the default priority thresholds.
var ErrLoadShed = ils.ErrLoadShed
ErrLoadShed indicates a request was shed due to load.
var IsLoadShed = ils.IsLoadShed
IsLoadShed checks whether err is a load shedding rejection.
var PriorityFromContext = ils.PriorityFromContext
PriorityFromContext extracts priority from a context.
var WithPriority = ils.WithPriority
WithPriority attaches a priority to a context.
Functions ¶
This section is empty.