workload

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package workload is what the benchmarks' guests do: the programs they run, how to tell they are ready, and the requests sent to them.

A workload is separate from what a scenario measures, so that a fleet, a fork fan-out and a standby can all run the same guests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitForHTTP

func WaitForHTTP(ctx context.Context, url string, timeout time.Duration) error

WaitForHTTP blocks until the service at url answers with 200 OK, for at most timeout.

Types

type LoadGenerator

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

LoadGenerator sends each guest's service requests at a fixed rate and records how long they take.

The rate is kept whatever the guests do: each request is due at a set time, and its latency is counted from then, not from when it was sent. A guest that falls behind is charged for the requests that queued behind a slow one, which a sender that waited for each response would hide.

It is safe for concurrent use.

func NewLoadGenerator

func NewLoadGenerator(requestsPerSecond float64) *LoadGenerator

NewLoadGenerator returns a generator sending requestsPerSecond to each guest it is given.

func (*LoadGenerator) Add

func (g *LoadGenerator) Add(ctx context.Context, url string)

Add starts sending requests to url until ctx is done.

func (*LoadGenerator) Take

func (g *LoadGenerator) Take() ([]time.Duration, int)

Take returns the latencies and failures recorded since it was last called.

func (*LoadGenerator) Wait

func (g *LoadGenerator) Wait()

Wait blocks until every guest's sender has stopped, once their contexts are done.

type Workload

type Workload struct {
	// Name says what the workload is, in the results.
	Name string

	// Image is the image it runs in.
	Image string

	// Cmd and Env are the guest's command and its environment.
	Cmd []string
	Env map[string]string

	// Port is where its HTTP service answers, or 0 if it has none: it is
	// then ready once a command can run in its guest.
	Port int
}

Workload is a guest's program.

func Idle

func Idle(image string) Workload

Idle returns an HTTP service, in an image with Python 3, that holds no more than the interpreter and answers each request with "ok": a sandbox or a development environment waiting for someone to use it.

func Job

func Job(image string, mib int, rest time.Duration) Workload

Job returns a batch job, in an image with Python 3, that works through mib of data, then rests for rest, over and over: a guest that is busy some of the time.

func Service

func Service(image string, workingSetMiB, workKiB int) Workload

Service returns an HTTP service, in an image with Python 3, that keeps workingSetMiB of memory in use and hashes workKiB of it for each request: a guest that costs the host memory and CPU, as a real service would.

func (Workload) URL

func (w Workload) URL(ip string) string

URL is where the workload's service answers in a guest at ip.

Jump to

Keyboard shortcuts

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