netem

package
v1.1.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: 8 Imported by: 0

Documentation

Overview

Package netem emulates slower networks inside the load generator: added round-trip latency with jitter, per-connection bandwidth limits and the effect of packet loss, applied to each virtual user's connections. It needs no privileges, so it works on any worker.

Loss is emulated at the level the application sees it: TCP never loses data, but a lost segment stalls the stream until it is retransmitted. So with probability Loss a read or write waits one retransmission timeout (200ms, or 1.5 x RTT when larger) before proceeding, which is what a user on a lossy network experiences.

Index

Constants

This section is empty.

Variables

View Source
var Profiles = map[string]Profile{
	"slow-3g":   {Name: "slow-3g", RTT: 400 * time.Millisecond, Down: 400_000 / 8, Up: 400_000 / 8},
	"3g":        {Name: "3g", RTT: 300 * time.Millisecond, Down: 1_600_000 / 8, Up: 768_000 / 8},
	"4g":        {Name: "4g", RTT: 70 * time.Millisecond, Down: 12_000_000 / 8, Up: 6_000_000 / 8},
	"slow-wifi": {Name: "slow-wifi", RTT: 30 * time.Millisecond, Down: 2_000_000 / 8, Up: 1_000_000 / 8},
}

Profiles are the built-in networks. Bandwidths are in bits per second in the names users know, stored here as bytes per second.

Functions

func Dialer

func Dialer(p Profile, dial func(ctx context.Context, network, addr string) (net.Conn, error)) func(ctx context.Context, network, addr string) (net.Conn, error)

Dialer wraps a dial function so every connection is shaped by p.

func Names

func Names() []string

Names lists the built-in profiles.

func ParseBandwidth

func ParseBandwidth(s string) (int64, error)

ParseBandwidth reads "1.6mbps", "768kbps", "100000" (bits per second) and returns bytes per second.

Types

type Profile

type Profile struct {
	Name string
	// RTT is added to every round trip: half before data is sent after
	// receiving, half before data is delivered after sending.
	RTT time.Duration
	// Down and Up are bandwidth limits in bytes per second (0 = unlimited).
	Down, Up int64
	// Jitter varies each RTT uniformly by up to this much either way.
	Jitter time.Duration
	// Loss is the probability (0..1) that a transfer is delayed by a
	// retransmission timeout.
	Loss float64
}

Profile describes a network.

Jump to

Keyboard shortcuts

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