Documentation
¶
Overview ¶
Package admission owns the daemon-wide new-work admission boundary.
Index ¶
Constants ¶
const DefaultLoadSampleInterval = 5 * time.Second
DefaultLoadSampleInterval is how often the load monitor reads the host load average.
Variables ¶
var ErrDraining = errors.New("daemon is draining; new work admission is closed")
ErrDraining reports that the daemon is temporarily refusing new work.
var ErrLoadAverageUnsupported = errors.New("admission: load average is unsupported on this platform")
ErrLoadAverageUnsupported reports a platform without a cheap load-average source.
Functions ¶
func IsBackgroundWork ¶
IsBackgroundWork reports whether ctx carries the background-work marker.
func WithBackgroundWork ¶
WithBackgroundWork marks ctx as daemon-initiated background work (automation, Loop, scheduler wakes). Background work yields to host CPU pressure at admission; unmarked work is treated as user-initiated and never waits.
Types ¶
type Gate ¶
type Gate struct {
// contains filtered or unexported fields
}
Gate is a concurrency-safe, in-memory daemon admission gate.
func (*Gate) BeginBoot ¶
BeginBoot permits only composition-root recovery until FinishBoot publishes readiness. The capability is an in-process context value and cannot be supplied by clients.
func (*Gate) Check ¶
Check admits active daemons and rejects new work while draining. Background work (see WithBackgroundWork) first waits, bounded, for host CPU pressure to clear.
func (*Gate) FinishBoot ¶
func (g *Gate) FinishBoot()
FinishBoot publishes composition-root readiness independently of public drain control.
func (*Gate) SetLoadMonitor ¶
func (g *Gate) SetLoadMonitor(monitor *LoadMonitor)
SetLoadMonitor attaches host-load-aware admission for background work; nil detaches it.
type LoadMonitor ¶
type LoadMonitor struct {
// contains filtered or unexported fields
}
LoadMonitor samples host load and holds background admissions while the host is saturated.
func NewLoadMonitor ¶
func NewLoadMonitor(cfg LoadMonitorConfig) *LoadMonitor
NewLoadMonitor constructs a monitor; Start begins sampling.
func (*LoadMonitor) Shutdown ¶
func (m *LoadMonitor) Shutdown(ctx context.Context) error
Shutdown stops sampling, releases waiters, and joins the sampling goroutine.
func (*LoadMonitor) Snapshot ¶
func (m *LoadMonitor) Snapshot() LoadSnapshot
Snapshot returns the latest pressure observation.
type LoadMonitorConfig ¶
type LoadMonitorConfig struct {
// Threshold is the 1-minute load average divided by logical CPUs above which
// background work waits. Zero disables the monitor entirely.
Threshold float64
// MaxWait bounds how long one background admission waits before proceeding.
MaxWait time.Duration
// Interval is the sampling cadence; nonpositive uses DefaultLoadSampleInterval.
Interval time.Duration
Logger *slog.Logger
// Sample and LogicalCPUs are test seams; nil/zero use the platform source.
Sample func() (float64, error)
LogicalCPUs int
Now func() time.Time
}
LoadMonitorConfig configures host-load-aware admission.
type LoadSnapshot ¶
type LoadSnapshot struct {
Enabled bool
Supported bool
Pressured bool
Threshold float64
MaxWait time.Duration
LogicalCPUs int
Load1 float64
NormalizedLoad float64
SampledAt time.Time
Waiting int
Deferred uint64
WaitExpired uint64
}
LoadSnapshot is one immutable view of host CPU pressure as seen by admission.