loadshed

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 1 Imported by: 0

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

View Source
const (
	PriorityCritical   = ils.PriorityCritical
	PriorityHigh       = ils.PriorityHigh
	PriorityNormal     = ils.PriorityNormal
	PriorityLow        = ils.PriorityLow
	PriorityBestEffort = ils.PriorityBestEffort
)

Variables

View Source
var DefaultThresholds = ils.DefaultThresholds

DefaultThresholds returns the default priority thresholds.

View Source
var ErrLoadShed = ils.ErrLoadShed

ErrLoadShed indicates a request was shed due to load.

View Source
var IsLoadShed = ils.IsLoadShed

IsLoadShed checks whether err is a load shedding rejection.

View Source
var PriorityFromContext = ils.PriorityFromContext

PriorityFromContext extracts priority from a context.

View Source
var WithPriority = ils.WithPriority

WithPriority attaches a priority to a context.

Functions

This section is empty.

Types

type Config

type Config = ils.Config

Config defines load shedding parameters.

type Priority

type Priority = ils.Priority

Priority defines the importance of a request. Lower numeric values = higher priority.

type Shedder

type Shedder = ils.Shedder

Shedder implements priority-based load shedding.

func NewShedder

func NewShedder(cfg Config) *Shedder

NewShedder creates a new priority-based load shedder.

shedder := loadshed.NewShedder(loadshed.Config{
    Capacity: 1000,
})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL