bench

package
v1.5.10 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 7 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 bench is an open-loop HTTP load driver with failure-window analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Percentile

func Percentile(sorted []time.Duration, p float64) time.Duration

Percentile returns the nearest-rank percentile (0 < p <= 100) of sorted.

func Schedule

func Schedule(rate float64, d time.Duration) []time.Duration

Schedule returns the intended send offsets of a constant-rate run.

Types

type Config

type Config struct {
	URL         string
	Rate        float64
	Duration    time.Duration
	Timeout     time.Duration
	MaxInFlight int
}

Config describes one constant-arrival-rate run.

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer is the subset of *http.Client the driver needs.

type Event

type Event struct {
	Name string
	At   time.Duration
	Fire func(ctx context.Context) error
}

Event is an action fired at a fixed offset into a run.

type EventReport

type EventReport struct {
	Name          string  `json:"name"`
	FiredAtMS     float64 `json:"fired_at_ms"`
	FireError     string  `json:"fire_error,omitempty"`
	Dropped       int     `json:"dropped_requests"`
	FirstErrorMS  float64 `json:"first_error_ms"`
	ErrorWindowMS float64 `json:"error_window_ms"`
	RecoveryMS    float64 `json:"recovery_ms"`
	Recovered     bool    `json:"recovered"`
}

EventReport is the failure analysis for one fired event.

func AnalyzeEvent

func AnalyzeEvent(samples []Sample, eventAt, runLen, tail time.Duration) EventReport

AnalyzeEvent measures the failures at or after eventAt. A run counts as recovered when its last failure is more than tail before the run ends.

type Overhead

type Overhead struct {
	P50MS float64 `json:"p50_ms"`
	P95MS float64 `json:"p95_ms"`
	P99MS float64 `json:"p99_ms"`
}

Overhead is the latency a proxied path adds over a direct one, in milliseconds.

func Compare

func Compare(proxied, direct Stats) Overhead

Compare returns proxied minus direct latency per percentile.

type Result

type Result struct {
	Stats  Stats        `json:"stats"`
	Event  *EventReport `json:"event,omitempty"`
	Sample []Sample     `json:"-"`
}

Result is the outcome of Run.

func Run

func Run(ctx context.Context, d Doer, cfg Config, ev *Event) (Result, error)

Run drives cfg.URL at a constant arrival rate. Each request is launched on its own goroutine at its intended time and latency is measured from that time, so a stalled server cannot hide its own queueing delay.

type Sample

type Sample struct {
	Offset  time.Duration
	Latency time.Duration
	Failed  bool
}

Sample is one request, positioned by its intended send time.

type Stats

type Stats struct {
	Sent        int     `json:"sent"`
	Succeeded   int     `json:"succeeded"`
	Failed      int     `json:"failed"`
	Saturated   int     `json:"client_saturated"`
	AchievedRPS float64 `json:"achieved_rps"`
	ErrorRate   float64 `json:"error_rate"`
	P50MS       float64 `json:"p50_ms"`
	P95MS       float64 `json:"p95_ms"`
	P99MS       float64 `json:"p99_ms"`
	MaxMS       float64 `json:"max_ms"`
}

Stats summarises a run. Latencies are milliseconds measured from the intended send time.

func RunClosed

func RunClosed(ctx context.Context, d Doer, url string, workers int, duration, timeout time.Duration) (Stats, error)

RunClosed drives url with a fixed number of workers, each sending its next request when the previous one returns. It measures capacity at a given concurrency, not latency under a fixed arrival rate (use Run for that).

func Summarize

func Summarize(samples []Sample, elapsed time.Duration) Stats

Summarize computes Stats from samples; elapsed is the wall time of the run.

Jump to

Keyboard shortcuts

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