bench

package
v0.2.0-dev.9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 9 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 the engine benchmark suite: Hysteria2, VLESS (REALITY over TCP and over XHTTP) and AmneziaWG, each between two network namespaces joined by a veth pair (with netem variants), measured for throughput, CPU per gigabyte, latency under load, memory and handshakes per second. The suite itself is in the *_test.go files behind the build tag "bench" and runs only on Linux, as root, with MISTGATE_BENCH=1 (see docs/en/reference/benchmarks.md and scripts/bench.sh). This file is the part that needs none of that: the report format and the comparison against the committed baseline, which is plain Go and is tested on every OS.

Index

Constants

View Source
const DefaultThreshold = 0.15

DefaultThreshold is how much worse than the baseline a metric may get before the run fails: 15 percent.

View Source
const FrontSuffix = "-front"

FrontSuffix marks an engine run behind the agent's shared-port front (internal/node/front): "vless-tcp-front" is "vless-tcp" with the front in front of it, and the front may cost at most the threshold against the direct case of the same run.

View Source
const SchemaVersion = 1

SchemaVersion is the version of the report format. A baseline of another version is not compared.

View Source
const ThresholdEnv = "MISTGATE_BENCH_THRESHOLD"

ThresholdEnv names the environment variable that overrides the threshold: "20" or "20%" or "0.2" all mean 20 percent.

Variables

This section is empty.

Functions

func ParseThreshold

func ParseThreshold(s string) (float64, error)

ParseThreshold reads a threshold given as "15", "15%" or "0.15" (everything above 1 is a percentage). An empty string is the default. A value that is not a positive number is an error: a typo must not silently turn the check off.

func ThresholdFromEnv

func ThresholdFromEnv() (float64, error)

ThresholdFromEnv is ParseThreshold of the environment variable.

Types

type Finding

type Finding struct {
	Case, Metric   string
	Baseline, Got  float64
	ChangePct      float64 // positive = worse
	HigherIsBetter bool
}

Finding is one metric of one case that got worse than the threshold allows.

func (Finding) String

func (f Finding) String() string

type Metrics

type Metrics struct {
	// Throughput of 1 and of 8 parallel streams, Mbit/s, client to internet direction as seen by the client (a download).
	Tput1Mbit float64 `json:"tput_1_mbit_s,omitempty"`
	Tput8Mbit float64 `json:"tput_8_mbit_s,omitempty"`
	// CPUSecPerGB is the CPU time the engine process used (user plus system) per gigabyte it moved in both throughput phases.
	CPUSecPerGB float64 `json:"cpu_s_per_gb,omitempty"`
	// P50MS and P99MS are the latency of a small request while 8 streams are loading the link.
	P50MS float64 `json:"p50_ms,omitempty"`
	P99MS float64 `json:"p99_ms,omitempty"`
	// RSSMB is the engine process's peak resident memory after the run.
	RSSMB float64 `json:"rss_mb,omitempty"`
	// HandshakesPerS is how many new sessions per second a client can complete. For AmneziaWG it is a re-handshake of one peer
	// with one ping, paced at WireGuard's own flood limit (one initiation per 20 ms), so it tops out near 30 and mostly shows
	// that every one of them succeeds.
	HandshakesPerS float64 `json:"handshakes_per_s,omitempty"`
}

Metrics is what one case measured. A zero value is "not measured" (a case that could not measure it) and is never compared.

func MedianOf

func MedianOf(runs []Metrics) Metrics

MedianOf is the metric-by-metric median of several runs of one case (a metric a run did not measure is left out of its own median; an even count takes the mean of the middle two). One run of a throughput test on a shared machine can be off by a third, so a baseline is best made from three or five.

type Report

type Report struct {
	Schema int    `json:"schema"`
	When   string `json:"when,omitempty"`
	Host   string `json:"host,omitempty"` // kernel, CPU count and Go version: a baseline only means something on the same kind of machine
	// Cases is keyed "<engine>/<variant>": hysteria2/clean, vless-tcp/rtt50-loss1, awg/mtu1280 and so on.
	Cases map[string]Metrics `json:"cases"`
}

Report is the JSON the suite writes.

func LoadReport

func LoadReport(path string) (Report, error)

LoadReport reads a report (or the baseline) from a file.

func (Report) Marshal

func (r Report) Marshal() ([]byte, error)

Marshal is the report as indented JSON with a final newline.

type Result

type Result struct {
	Regressions []Finding
	// Notes are things worth saying that do not fail the run: a case without a baseline, a baseline case that was not run.
	Notes []string
}

Result is the outcome of a comparison.

func Compare

func Compare(baseline, got Report, threshold float64) Result

Compare checks got against baseline. A metric fails when it is worse than the baseline by more than threshold (a fraction: 0.15 is 15 percent) and by more than its minimum absolute change. Better is never a failure. A case or a metric missing on one side is a note, not a failure, so a new engine does not need a baseline first.

func CompareFront

func CompareFront(r Report, threshold float64) Result

CompareFront checks every "<engine>-front/<variant>" case of one report against "<engine>/<variant>" of the same report (the baseline in each finding is the direct figure). A front case without its direct case is left out.

func (Result) Failed

func (r Result) Failed() bool

Failed says whether the comparison found a regression.

func (Result) Summary

func (r Result) Summary() string

Summary is the comparison as text, one line per finding and note.

Jump to

Keyboard shortcuts

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