engine

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package engine executes a compiled scenario: it runs virtual users under a load plan, records every request and emits one metrics snapshot per interval.

Index

Constants

View Source
const (
	StopCompleted = "completed"
	StopRequested = "stopped"
	StopKilled    = "killed"
)

Stop reasons.

Variables

This section is empty.

Functions

func FindChrome

func FindChrome() (string, error)

FindChrome returns a Chrome or Chromium executable: $STAMPEDE_CHROME, then the usual names on PATH, then the standard install locations.

Types

type Engine

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

Engine runs one scenario.

func New

func New(opts Options) (*Engine, error)

New prepares an engine: loads feeders, builds HTTP transports and renders the base URL.

func (*Engine) ActiveVUs

func (e *Engine) ActiveVUs() int

ActiveVUs is the number of virtual users currently running.

func (*Engine) BaseURL

func (e *Engine) BaseURL() string

BaseURL is the rendered target base URL.

func (*Engine) Kill

func (e *Engine) Kill()

Kill stops all load immediately, abandoning in-flight requests.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) (*Result, error)

Run executes the plan and blocks until all load has stopped.

func (*Engine) Stop

func (e *Engine) Stop(reason string)

Stop ends the load phase; in-flight iterations get the graceful stop period to finish.

type Options

type Options struct {
	Program *scenario.Program
	Plan    *scenario.Plan
	RunID   string

	// Env and Secrets back ${env.X} and ${secret.X}.
	Env     map[string]string
	Secrets map[string]string

	// ShareLo and ShareHi select this engine's slice of the total load as
	// cumulative fractions. A single engine uses 0 and 1. Workers with
	// slices [0, .5) and [.5, 1) together produce exactly the plan.
	ShareLo, ShareHi float64
	// WorkerIndex and WorkerCount partition unique test data.
	WorkerIndex, WorkerCount int

	// T0 is the synchronised start time. Zero starts immediately.
	T0 time.Time
	// Resume starts part-way through the plan, at T0 + Resume: the worker
	// takes over a lost worker's share. Arrivals before then are skipped.
	Resume time.Duration
	// Attempt counts takeovers of this share; generated data mixes it in
	// so values stay unique.
	Attempt int
	// Interval between snapshots (default 1s).
	Interval time.Duration
	// OnSnapshot receives each interval's metrics. It must not block for long.
	OnSnapshot func(*metrics.Snapshot)
	// AllowHost vets every request URL. Nil allows all hosts.
	AllowHost func(*url.URL) bool
	// MaxBodyBytes caps response bytes kept for checks and extraction
	// (default 10 MiB).
	MaxBodyBytes int64
	// Transport overrides the HTTP dialer (tests, network emulation).
	HTTP httpx.Options
	// PluginDir is where plugin executables are looked for before PATH
	// (default: pluginhost.Dir()).
	PluginDir string
	Logger    *slog.Logger
}

Options configures an engine.

type Result

type Result struct {
	T0         time.Time
	End        time.Time
	StopReason string
	Phases     map[int]*[metrics.NumPhases]*metrics.Histogram
	PeakVUs    int
}

Result describes a finished run.

type VU

type VU struct {
	ID int
	// contains filtered or unexported fields
}

VU is one virtual user. A VU runs one iteration at a time.

Jump to

Keyboard shortcuts

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