Documentation
¶
Overview ¶
Package loadtest is a game-agnostic WebSocket load-test harness: slots and ramp, histograms, per-second rates, disconnect reasons and the player loop (player.go).
Index ¶
- Constants
- func HumansPerRoom(players, rooms int) int
- func Line(prev, cur Sample) string
- func PerClientKB(bytesPerSec float64, conns int64) float64
- func Reason(err error, serverMsg string) string
- func Run(ctx context.Context, c Config, sc Script) error
- func SnapTick(b []byte) (tick int, ok bool)
- func StartAt(i, n int, ramp time.Duration) time.Duration
- func Summary(from, to Sample, hs Counts, reasons map[string]int) string
- func WSURL(raw string) (string, error)
- type Config
- type Counts
- type Hist
- type Sample
- type Script
- type Slot
- type Stats
Constants ¶
const HistMax = 1000
HistMax is the last finite bucket bound; slower observations land in the overflow bucket and read as HistMax+1 ms.
Variables ¶
This section is empty.
Functions ¶
func HumansPerRoom ¶
HumansPerRoom is the most humans any one room gets from Assign.
func Line ¶
line is the per-interval report between two samples. "in" is what the players received (the server's outbound), "out" what they sent; rx/client is the server's outbound bandwidth per connected player.
func PerClientKB ¶
func Reason ¶
reason names why a player's socket ended: the server's error message if it sent one, else the close status or the kind of read error.
func Run ¶
Run starts every player on its ramp slot and reports until the run ends. The game's cadence has no default: a wrong SnapEvery miscounts gaps silently.
func SnapTick ¶
SnapTick reads a snapshot's tick from its prefix without decoding the rest; ok is false for anything else (decode it in full).
func StartAt ¶
StartAt is player i's connect time after the run starts: players start evenly over ramp (all at once with ramp 0).
Types ¶
type Config ¶
type Config struct {
URL string
Players, Rooms int
InputHz int // inputs a player sends per second (pings follow every InputHz inputs: 1 s)
SnapEvery int // server ticks between two snapshots: a larger tick step is a gap
Duration, Ramp, Settle, Every time.Duration
}
Config is one run: the target, the crowd, the game's cadence and the timing.
type Counts ¶
Counts is a point-in-time copy of a Hist's buckets.
func (Counts) Quantile ¶
Quantile is the upper bound in ms of the bucket where the q-th observation falls (bucket i reads i+1); 0 with no observations.
type Hist ¶
type Hist struct {
// contains filtered or unexported fields
}
Hist is a lock-free latency histogram with 1 ms buckets: bucket i holds observations in [i, i+1) ms, the last one everything >= HistMax ms. Writers Observe from any goroutine; the reporter reads counts.
type Script ¶
type Script interface {
Hello(i int) any // player i's hello
Create() any // a creator's create message
Input(i int, seq uint32) any // player i's input number seq (Config.InputHz)
React(i, you int, t string, raw []byte) any // a reply to a server message other than snap/pong/error, or nil; raw is valid until return
}
Script is what a game tells the load test.
Concurrency: methods are called from several goroutines at once. For one player, Hello and Create run on the player's goroutine, Input on its send goroutine and React on its read goroutine, so Input and React run concurrently; one player's React calls are serial. Different players run concurrently too. An implementation must guard any state it shares between them. React's replies are best-effort: one dropped while another is still waiting to be sent is not retried.
type Slot ¶
Slot is one simulated player's place in the run: its room (-1 = quick play) and whether it creates that room.
type Stats ¶
type Stats struct {
Conns atomic.Int64 // players past the handshake, still connected
MsgsIn, MsgsOut, BytesIn atomic.Uint64
BytesOut, Snaps, Gaps atomic.Uint64
SnapIv, RTT, Handshake Hist
// contains filtered or unexported fields
}
Stats is the run's shared tally. Players write it lock-free (atomics and hists); only Disconnect reasons, rare, take the lock.