soak

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package soak provides the pure metric primitives for the aether soak/chaos suite: bounded-memory latency percentiles, a windowed latency-trend check and a growth (leak) check. Nothing here touches NATS or an OS process, so it is fast to unit-test in normal CI, while the long-running orchestration that uses it lives behind the `soak` build tag in internal/lord.

Latencies are kept in fixed-bucket histograms rather than a growing slice: a soak run makes an unbounded number of calls, and because the lord runs in the same process as the test, an unbounded recorder would inflate the process heap and corrupt the very leak measurement the suite performs. Histograms make the recorder's footprint constant.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GrowthOK

func GrowthOK(start, end, tolerance float64) bool

GrowthOK reports whether `end` stayed within tolerance above `start` (end <= start * (1+tolerance)). Used for goroutine counts, heap and thrall RSS: a leak shows up as unbounded growth over the run. A shrink or flat value passes. A non-positive start with a positive end is unbounded growth and fails.

func GrowthPct

func GrowthPct(start, end float64) float64

GrowthPct returns the growth of end over start as a percentage. A non-positive start yields 0 to avoid a division by zero in the report.

Types

type Bars

type Bars struct {
	LatP99Max time.Duration // sustained-load p99 ceiling (story: < 50ms)
	TrendTol  float64       // allowed rise of the last latency window over the first (fraction)
	GrowthTol float64       // allowed growth of goroutines / heap / RSS end-vs-start (fraction)

	// Resilience (v2).
	RecoveryMax      time.Duration // per-strategy recovery after a thrall kill (story: < 3s)
	FailoverMax      time.Duration // singleton failover after the holder dies (story: < 5s)
	MaxLiveSingleton int           // max live singleton instances allowed at once (fencing: 1)
}

Bars holds the pass/fail thresholds for a soak run. The defaults are the story's approved values; a run may tighten or loosen them per profile.

func DefaultBars

func DefaultBars() Bars

DefaultBars returns the story's approved bars: p99 < 50ms, no upward latency trend beyond 20%, less than 10% resource growth after warm-up, chaos recovery within 3s, singleton failover within 5s, and never more than one live singleton.

type LatencyRecorder

type LatencyRecorder struct {
	// contains filtered or unexported fields
}

LatencyRecorder collects call latencies into an overall histogram plus per-window histograms so a trend (early vs late in the run) can be computed. It is safe for concurrent use: the load generator records from many goroutines at once. Memory is bounded by (windows+1) * histBuckets regardless of how many calls are recorded.

func NewLatencyRecorder

func NewLatencyRecorder(total time.Duration, windows int) *LatencyRecorder

NewLatencyRecorder returns a recorder that spreads samples across `windows` equal time windows over the expected total run duration. Samples arriving after the last window fold into it, so an over-running phase never panics.

func (*LatencyRecorder) Add

func (r *LatencyRecorder) Add(d time.Duration)

Add records one latency sample, placing it in the window for the current elapsed time.

func (*LatencyRecorder) Count

func (r *LatencyRecorder) Count() uint64

Count returns the number of recorded samples.

func (*LatencyRecorder) Max

func (r *LatencyRecorder) Max() time.Duration

Max returns the largest recorded sample, or 0 when empty.

func (*LatencyRecorder) Percentile

func (r *LatencyRecorder) Percentile(p float64) time.Duration

Percentile returns the p-th percentile (0..100) over all samples.

func (*LatencyRecorder) Trend

func (r *LatencyRecorder) Trend(p float64) Trend

Trend reports the p-th percentile of the earliest and latest windows that received samples. Comparing them surfaces a runtime that degrades over time. A run short enough to fill only one window yields First == Last (a flat, passing trend).

type Report

type Report struct {
	Profile  string
	Duration time.Duration
	Seed     int64
	Bars     Bars

	// Sustained load.
	CallCount   int
	LatP99      time.Duration
	LatMax      time.Duration
	LatP99First time.Duration // p99 of the first latency window (trend baseline)
	LatP99Last  time.Duration // p99 of the last latency window

	// Durable no-loss.
	Published  int
	Distinct   int
	Duplicates int

	// Leak deltas over the run's settled (back-half) region, so a working-set ramp is
	// not mistaken for a leak. LeakEvaluated is false when the run was too short to
	// reach a steady state: the deltas are then reported for information but not held
	// to the growth bars.
	LeakEvaluated  bool
	GoroutineStart int
	GoroutineEnd   int
	HeapStart      uint64           // bytes
	HeapEnd        uint64           // bytes
	ThrallRSSStart map[string]int64 // KB, per thrall name
	ThrallRSSEnd   map[string]int64 // KB, per thrall name

	// Chaos (v2): random thralls SIGKILLed under load; recovery = kill -> ready again.
	Kills       int
	RecoveryP99 time.Duration
	RecoveryMax time.Duration

	// Singleton failover (v2): the lock holder killed repeatedly.
	Failovers        int
	FailoverMax      time.Duration
	MaxLiveInstances int // most singleton instances seen live at once (fencing: must stay 1)

	// Graceful drain (v2): a drain triggered mid-stream must lose no work.
	DrainPublished int
	DrainDelivered int
}

Report is the structured outcome of a soak run. Fields for a phase that did not run stay at their zero value, and Breaches skips a bar whose phase produced no data (e.g. a load-only smoke run leaves the durable and leak sections empty).

func (Report) Breaches

func (r Report) Breaches() []string

Breaches returns a human-readable list of bar violations; an empty slice means every bar held. The caller turns a non-empty result into a non-zero exit.

func (Report) Format

func (r Report) Format() string

Format renders the report as a structured, human-readable block. Only sections whose phase ran are printed.

type Trend

type Trend struct {
	First time.Duration // percentile of the first window that saw traffic
	Last  time.Duration // percentile of the last window that saw traffic
}

Trend describes how a percentile moved from the start of the run to the end.

func (Trend) OK

func (t Trend) OK(tolerance float64) bool

OK reports whether the trailing window stayed within tolerance of the leading one (Last <= First * (1+tolerance)). A flat or improving trend passes. With no leading data it passes - there is nothing to regress against.

Jump to

Keyboard shortcuts

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