mload

package
v0.0.0-...-7eb2361 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package mload holds the domain model for load-test scenarios: the `load:` block of a yamlflow document, decoded into engine-ready values.

It deliberately knows nothing about YAML or about the load runner. The yamlflow translator produces these, and the CLI's load runner consumes them, so neither has to depend on the other.

Index

Constants

View Source
const (
	// DefaultTimeUnit is the period a `rate` is expressed over.
	DefaultTimeUnit = time.Second
	// DefaultGracefulStop is how long in-flight iterations of a ramping or
	// arrival-rate scenario may keep running once the schedule ends, before
	// they are interrupted.
	DefaultGracefulStop = 30 * time.Second
	// DefaultGracefulRampDown is how long an iteration may keep running after
	// a ramping-vus stage has taken its VU away.
	DefaultGracefulRampDown = 30 * time.Second
	// DefaultAbortWindow is the trailing window an abort condition is
	// evaluated over when it does not name one.
	DefaultAbortWindow = 30 * time.Second
)

Defaults applied when a scenario leaves the corresponding field unset.

Variables

Metrics lists the canonical metrics in the order they are written out, so exports and error messages are deterministic.

SupportedExecutors lists the executors this build accepts, for error messages that have to name the valid alternatives.

Functions

This section is empty.

Types

type AbortRule

type AbortRule struct {
	Condition Condition
	// Window is the trailing period the condition is evaluated over. Zero
	// means DefaultAbortWindow.
	Window time.Duration
	// Delay postpones the first evaluation from the start of the run.
	Delay time.Duration
}

AbortRule stops a run early once Condition holds over the trailing Window. Rules are not evaluated before Delay has elapsed, so a cold start does not trip them.

func (AbortRule) String

func (r AbortRule) String() string

String renders the rule for a report: "errors>20% over 30s".

type Condition

type Condition struct {
	// Step scopes the condition to one request step; empty means the whole
	// run.
	Step   string
	Metric Metric
	Op     Operator
	// Value is the limit exactly as written ("300ms", "1%"), kept so a
	// condition exports the way it was authored.
	Value string
	// Limit is Value normalized for comparison: nanoseconds for latency
	// metrics, a 0..1 ratio for errors, requests per second for rps.
	Limit float64
}

Condition is a comparison of one run statistic against a limit, such as `p95<300ms`, `p95(PostLogin)<500ms` or `errors<1%`.

The same grammar serves thresholds (a condition that must hold for the run to pass) and abort rules (a condition that, once it holds, stops the run).

func ParseComparison

func ParseComparison(step, metric, comparison string) (Condition, error)

ParseComparison parses the map form of a condition, where the metric and optional step come from keys and the comparison from the value: ParseComparison("PostLogin", "p95", "<500ms").

func ParseCondition

func ParseCondition(expr string) (Condition, error)

ParseCondition parses a single-expression condition:

metric[(step)] op value

where metric is one of p50, p90, p95, p99, max, errors (alias error_rate) or rps; op is <, <=, > or >=; and value is a Go duration for latency metrics, a percentage or 0..1 ratio for errors, and a number for rps. Whitespace around the parts is ignored.

func (Condition) FormatObserved

func (c Condition) FormatObserved(observed float64) string

FormatObserved renders an observed value (in Limit's units) for a report: a rounded duration for latencies, a percentage for errors, two decimals for rps.

func (Condition) Holds

func (c Condition) Holds(observed float64) bool

Holds reports whether observed (in Limit's units) satisfies the condition.

func (Condition) String

func (c Condition) String() string

String renders the condition in its canonical single-expression form.

type Executor

type Executor string

Executor names the scheduling strategy a scenario uses.

const (
	// ExecutorConstantVUs holds a fixed number of virtual users for the
	// scenario's duration or iteration budget. Each VU starts its next
	// iteration as soon as the previous one finishes (a closed model).
	ExecutorConstantVUs Executor = "constant-vus"
	// ExecutorRampingVUs varies the number of active virtual users over a
	// list of stages, interpolating linearly from one target to the next.
	ExecutorRampingVUs Executor = "ramping-vus"
	// ExecutorConstantArrivalRate starts iterations at a fixed rate,
	// independent of how long they take (an open model). Iterations that
	// find no free VU are dropped and counted.
	ExecutorConstantArrivalRate Executor = "constant-arrival-rate"
	// ExecutorRampingArrivalRate is the open-model counterpart of
	// ramping-vus: the iteration start rate follows a list of stages.
	ExecutorRampingArrivalRate Executor = "ramping-arrival-rate"
)

func (Executor) IsArrivalRate

func (e Executor) IsArrivalRate() bool

IsArrivalRate reports whether e is an open-model executor, i.e. one that starts iterations on a schedule rather than whenever a VU is free.

type Metric

type Metric string

Metric names a statistic a Condition compares.

const (
	MetricP50 Metric = "p50"
	MetricP90 Metric = "p90"
	MetricP95 Metric = "p95"
	MetricP99 Metric = "p99"
	MetricMax Metric = "max"
	// MetricErrors is the failed-request ratio (non-2xx/3xx and transport
	// failures over all requests). It is written as a percentage ("1%") or a
	// ratio ("0.01").
	MetricErrors Metric = "errors"
	// MetricRPS is requests per second.
	MetricRPS Metric = "rps"
)

func (Metric) IsLatency

func (m Metric) IsLatency() bool

IsLatency reports whether m is a latency statistic, whose values are durations.

type Operator

type Operator string

Operator is a comparison.

const (
	OpLess         Operator = "<"
	OpLessEqual    Operator = "<="
	OpGreater      Operator = ">"
	OpGreaterEqual Operator = ">="
)

type Scenario

type Scenario struct {
	// Name identifies the scenario, e.g. for `flow run --scenario <name>`.
	Name string
	// FlowName is the flow this scenario drives, by its `flows:` entry name.
	FlowName string
	// Executor is the scheduling strategy.
	Executor Executor
	// VUs is the number of concurrent virtual users for constant-vus.
	VUs int
	// Duration bounds the window during which new iterations start, for
	// constant-vus and constant-arrival-rate. Zero means unbounded, in which
	// case MaxIterations is set (constant-vus only).
	Duration time.Duration
	// MaxIterations bounds the total iterations issued (constant-vus only).
	// Zero means unbounded, in which case Duration is set.
	MaxIterations int64

	// StartVUs is the VU count ramping-vus starts from.
	StartVUs int
	// Stages drive ramping-vus (VU targets) and ramping-arrival-rate (rate
	// targets).
	Stages []Stage
	// GracefulRampDown bounds how long a ramping-vus iteration may keep
	// running after its VU was ramped away. Zero means the default.
	GracefulRampDown time.Duration

	// Rate is the iterations started per TimeUnit for constant-arrival-rate.
	Rate float64
	// StartRate is the rate ramping-arrival-rate starts from.
	StartRate float64
	// TimeUnit is the period Rate, StartRate and arrival stage targets are
	// expressed over. Zero means DefaultTimeUnit.
	TimeUnit time.Duration
	// PreAllocatedVUs are built before an arrival-rate scenario starts.
	PreAllocatedVUs int
	// MaxVUs caps how many VUs an arrival-rate scenario may use. Iterations
	// that would need more are dropped. Zero means PreAllocatedVUs.
	MaxVUs int

	// GracefulStop bounds how long in-flight iterations may run once a
	// ramping or arrival-rate schedule ends. Zero means the default.
	GracefulStop time.Duration
	// ThinkTime is the pause after each iteration.
	ThinkTime ThinkTime

	// Thresholds are pass/fail conditions evaluated once the run ends.
	Thresholds []Condition
	// Abort conditions are evaluated every reporting interval; the first
	// one that holds stops the run early.
	Abort []AbortRule
}

Scenario is one entry of the `load:` block: a named load profile applied to an existing flow. Flows are never edited to be load-tested, so a Scenario refers to its flow by name rather than owning it.

Which fields are meaningful depends on Executor:

  • constant-vus: VUs, plus Duration and/or MaxIterations.
  • ramping-vus: StartVUs, Stages, GracefulRampDown.
  • constant-arrival-rate: Rate, TimeUnit, Duration, PreAllocatedVUs, MaxVUs.
  • ramping-arrival-rate: StartRate, TimeUnit, Stages, PreAllocatedVUs, MaxVUs.

GracefulStop, ThinkTime, Thresholds and Abort apply to every executor (GracefulStop is ignored by constant-vus, which always lets in-flight iterations finish).

func (Scenario) Scaled

func (s Scenario) Scaled(vusScale, rateScale float64) Scenario

Scaled returns a copy of s sized for one machine of a split run: VU counts (and constant-vus iteration budgets) are multiplied by vusScale, and arrival rates by rateScale. Running the scaled scenario on 1/scale machines reproduces the original profile in aggregate.

VU counts and iteration budgets are rounded to the nearest whole number, but a positive count never rounds down to zero - a machine asked to take part runs at least one VU. Rates are not rounded. A scale of 1 returns s unchanged; callers validate that scales are positive.

type Stage

type Stage struct {
	Duration time.Duration
	Target   float64
}

Stage is one leg of a ramping profile: over Duration, the target moves linearly from the previous stage's target (or the scenario's start value) to Target. For ramping-vus Target is a VU count; for ramping-arrival-rate it is iterations per TimeUnit.

type ThinkTime

type ThinkTime struct {
	Min time.Duration
	Max time.Duration
}

ThinkTime is the pause a VU takes after each iteration. Min == Max is a fixed pause; Min < Max draws uniformly from the range; zero is none.

func (ThinkTime) IsZero

func (t ThinkTime) IsZero() bool

IsZero reports whether no think time is configured.

Jump to

Keyboard shortcuts

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