loadtest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 21 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.

README

loadtest

Tools to measure the throughput and the memory stability of the evaluation hot path.

Benchmarks

What Where Run
Library variations per scenario (no rule, rule, multiple rules, JsonLogic, percentage, progressive, scheduled, large in list), tracking off/on, serial/parallel, all-flags state (10/100/1000) variation_scenarios_bench_test.go (build tag bench) go test -tags bench -run xxx -bench 'Scenarios|AllFlagsState' -benchmem .
Relay proxy handlers in-process (Semaphore eval/allflags, OFREP eval/bulk) internal/loadtest/relay/handlers_bench_test.go go test -run xxx -bench Handlers -benchmem ./internal/loadtest/relay
Event store, flush cycle, manager with discard/slow/failing exporter exporter/exporter_bench_test.go go test -run xxx -bench . -benchmem ./exporter
Flag cache reads, with concurrent UpdateCache internal/cache/cache_bench_test.go go test -run xxx -bench . -benchmem ./internal/cache

Compare two runs with benchstat old.txt new.txt (use -count=10).

Soak

internal/loadtest/cmd/soak evaluates at max rate with N goroutines against the embedded library or a real relay proxy over loopback HTTP, with event tracking on and a selectable exporter behaviour (discard, slow = 2s per batch, failing), and prints one line per interval: evals/s, p50/p99 latency (1 evaluation out of 16 is timed), post-GC heap (HeapAlloc, HeapInuse, HeapObjects), NumGC and goroutines.

go run ./internal/loadtest/cmd/soak -target library -exporter slow -duration 60s
go run ./internal/loadtest/cmd/soak -target relay -endpoint semaphore-eval -exporter failing -duration 60s
go run ./internal/loadtest/cmd/soak -target relay -endpoint ofrep-bulk -flag x -duration 60s

Endpoints: semaphore-eval, semaphore-allflags, ofrep-eval, ofrep-bulk. Only semaphore-eval and ofrep-eval queue events: -exporter slow|failing is rejected on the bulk endpoints (they would bypass the exporter). Unknown -endpoint/-exporter values are rejected, a failed evaluation (for example an unknown -flag) counts as an error, and Ctrl+C stops the run without a verdict (exit status 130). -cpuprofile writes a CPU profile. -protocol http1|h2c (relay target) selects HTTP/1.1 with keep-alive or HTTP/2 over cleartext with prior knowledge (the proxy is started with server.enableH2C; a response that does not use the expected protocol counts as an error). For the bulk endpoints the report gives flags evaluated per second next to calls per second (one probe request counts the flags of a response), and the last lines print the window after the warm-up: calls/s, flags/s, errors and p50/p95/p99 latency. See the performance page for a measured matrix. For the relay target the proxy runs in the same process as the load generator (the heap and the CPU are shared), the exporter is the webhook exporter pointed at a local sink with the chosen behaviour.

The final line is the verdict ("memory stable", exit status 1 on FAIL):

  • after a warm-up (-warmup, default max(2, 20%) of the samples) the median post-GC HeapInuse of the last half of the samples (a bounded sawtooth, the events that wait for their flush, has a stable median, a leak raises it) must not exceed the first half's by more than max(-heap-tolerance (25%), 32 MiB);
  • the goroutine count must not exceed its value at the end of the warm-up by more than 64;
  • the run is aborted and fails when the live heap exceeds 6 GiB.

The run needs at least 3 samples after the warm-up: use -duration >= 6 x -interval.

Documentation

Overview

Package loadtest contains the flag fixtures, the exporter behaviours and the soak harness used to measure the throughput and the memory stability of semaphore. See README.md in this directory.

Index

Constants

View Source
const SlowDelay = 2 * time.Second

SlowDelay is the time the "slow" exporter blocks on each Export call.

Variables

This section is empty.

Functions

func FlagKey

func FlagKey(scenario, typ string, track bool) string

FlagKey returns the key of the generated flag for a scenario, a type and the tracking mode.

func FlagsYAML

func FlagsYAML() string

FlagsYAML returns a flag configuration (YAML) with one flag per scenario, type and tracking mode. Keys are given by FlagKey.

func ManyFlagsYAML

func ManyFlagsYAML(n int) string

ManyFlagsYAML returns n simple flags named flag-0 .. flag-(n-1), mixing static, targeting and percentage flags, used for the all-flags benchmarks.

func Scenarios

func Scenarios() []string

Scenarios returns the list of flag scenarios generated by FlagsYAML.

func Types

func Types() []string

Types returns the list of flag value types generated by FlagsYAML.

Types

type Exporter

type Exporter struct {
	Mode     ExporterMode
	Delay    time.Duration
	Batches  atomic.Int64
	Events   atomic.Int64
	Failures atomic.Int64
}

Exporter is a bulk exporter with a configurable behaviour that counts what it received.

func NewExporter

func NewExporter(mode ExporterMode) *Exporter

NewExporter creates an Exporter for the mode.

func (*Exporter) Export

func (e *Exporter) Export(ctx context.Context, _ *fflog.FFLogger, events []exporter.ExportableEvent) error

Export implements exporter.Exporter.

func (*Exporter) IsBulk

func (e *Exporter) IsBulk() bool

IsBulk implements exporter.CommonExporter.

type ExporterMode

type ExporterMode string

ExporterMode selects the behaviour of the exporter used by the harness and the benchmarks.

const (
	// ExporterDiscard accepts and drops every batch immediately.
	ExporterDiscard ExporterMode = "discard"
	// ExporterSlow sleeps for SlowDelay on every batch before accepting it.
	ExporterSlow ExporterMode = "slow"
	// ExporterFailing returns an error on every batch.
	ExporterFailing ExporterMode = "failing"
)

func ParseExporterMode

func ParseExporterMode(s string) (ExporterMode, error)

ParseExporterMode validates an exporter mode name.

type LibraryOptions

type LibraryOptions struct {
	FlagKey          string
	ExporterMode     ExporterMode
	FlushInterval    time.Duration
	MaxEventInMemory int64
}

LibraryOptions configure NewLibraryTarget.

type LibraryTarget

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

LibraryTarget evaluates a bool flag through the embedded library with event tracking.

func NewLibraryTarget

func NewLibraryTarget(o LibraryOptions) (*LibraryTarget, error)

NewLibraryTarget starts a library client on the generated flags.

func (*LibraryTarget) Close

func (l *LibraryTarget) Close()

Close implements Target.

func (*LibraryTarget) Eval

func (l *LibraryTarget) Eval(worker, i int) error

Eval implements Target.

func (*LibraryTarget) Extra

func (l *LibraryTarget) Extra() map[string]int64

Extra implements Target.

type Options

type Options struct {
	Name     string
	Duration time.Duration
	// Interval is the sampling period (default 5s).
	Interval time.Duration
	// Workers is the number of goroutines evaluating at max rate (default GOMAXPROCS).
	Workers int
	// WarmupIntervals is the number of leading samples ignored by the verdict
	// (default max(2, 20% of the samples)).
	WarmupIntervals int
	// HeapTolerance is the maximum relative growth of the median post-GC HeapInuse between the first and
	// the last half of the measured window (default 0.25 = 25%).
	HeapTolerance float64
	// HeapMinGrowthBytes is an absolute allowance under which growth never fails (default 32 MiB).
	HeapMinGrowthBytes uint64
	// GoroutineSlack is the number of goroutines the count may exceed its value at the end of the
	// warm-up by (default 64).
	GoroutineSlack int
	// MaxHeapBytes aborts the run (verdict FAIL) when the live heap exceeds it, to protect the
	// machine from an unbounded leak (default 6 GiB).
	MaxHeapBytes uint64
}

Options configure Run.

type Report

type Report struct {
	Extra   map[string]int64
	Name    string
	Samples []Sample
	Reasons []string
	// Window is the throughput and latency of the measured window; the zero value when it is too short.
	Window    Window
	TotalEval int64
	TotalErr  int64
	// HeapGrowthBytes is the growth of the median HeapInuse between the first and the last half of the measured window.
	HeapGrowthBytes float64
	Pass            bool
}

Report is the result of Run.

func Run

func Run(ctx context.Context, t Target, o Options, out io.Writer) Report

Run evaluates the target at max rate with Workers goroutines for Duration and samples the throughput, the latency, the heap and the goroutine count every Interval. If out is not nil, each sample is written to it as it is taken.

func (Report) Summary

func (r Report) Summary(w io.Writer)

Summary writes the final verdict.

type Sample

type Sample struct {
	Elapsed     time.Duration
	EvalsPerSec float64
	Errors      int64
	P50, P99    time.Duration
	HeapAlloc   uint64 // after a forced GC
	HeapInuse   uint64 // after a forced GC
	HeapObjects uint64 // after a forced GC
	NumGC       uint32
	Goroutines  int
}

Sample is one line of the time series.

type Target

type Target interface {
	// Eval does one evaluation. i is a per-worker increasing counter.
	Eval(worker, i int) error
	// Extra returns target specific counters that are printed at the end of the run (optional).
	Extra() map[string]int64
	// Close releases the resources of the target.
	Close()
}

Target is something we can evaluate flags against.

type Weighted

type Weighted interface {
	// FlagsPerCall is the number of flags one successful call evaluates (at least 1).
	FlagsPerCall() int
}

Weighted is implemented by a target whose call evaluates several flags (a bulk request): the report then also gives flags evaluated per second.

type Window

type Window struct {
	// Samples is the number of sampling intervals in the window.
	Samples int
	// CallsPerSec is the mean number of calls (requests) per second.
	CallsPerSec float64
	// FlagsPerCall is the number of flags evaluated by one call (1 unless the target is Weighted).
	FlagsPerCall int
	// FlagsPerSec is CallsPerSec * FlagsPerCall.
	FlagsPerSec float64
	// Errors is the number of failed calls in the window.
	Errors int64
	// P50, P95, P99 are latency quantiles of the sampled calls of the window (upper bound of the bucket).
	P50, P95, P99 time.Duration
}

Window summarizes the measured part of a run (the samples after the warm-up).

Directories

Path Synopsis
cmd
soak command
Command soak runs a max-rate load against the library or a real relay proxy (loopback HTTP), with event tracking on and a selectable exporter behaviour, and prints a time series and a "memory stable" verdict.
Command soak runs a max-rate load against the library or a real relay proxy (loopback HTTP), with event tracking on and a selectable exporter behaviour, and prints a time series and a "memory stable" verdict.
Package relay starts an in-process relay proxy for the benchmarks and the soak harness.
Package relay starts an in-process relay proxy for the benchmarks and the soak harness.

Jump to

Keyboard shortcuts

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