benchworkload

package
v0.1.0-rc.38 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package benchworkload contains the publisher and visitor workloads shared by local runtime tests and deployed benchmarks. runners own setup and cleanup.

Index

Constants

View Source
const (
	BandwidthDownstream    = "downstream"
	BandwidthUpstream      = "upstream"
	BandwidthBidirectional = "bidirectional"
)
View Source
const RequestTimeout = 5 * time.Second

Variables

This section is empty.

Functions

func Assignment

func Assignment(total, count, index int) int

func CancellationOnly

func CancellationOnly(err error) bool

errors.Is alone would hide a close failure joined with cancellation.

func Origin

func Origin(size int) http.Handler

func Payload

func Payload(size int) []byte

func PublicURLIndexes

func PublicURLIndexes(total, count, index int) []int

func WaitUntil

func WaitUntil(ctx context.Context, at time.Time) error

Types

type BandwidthConfig

type BandwidthConfig struct {
	Direction      string        `json:"direction"`
	Streams        int           `json:"streams_per_direction"`
	BytesPerSecond int64         `json:"bytes_per_second_per_direction"`
	Start          time.Time     `json:"start"`
	Duration       time.Duration `json:"duration"`
}

BandwidthConfig describes a fixed-rate transfer phase. Streams is the number of streams per active direction.

type BandwidthResult

type BandwidthResult struct {
	Direction              string        `json:"direction"`
	StreamsPerDirection    int           `json:"streams_per_direction"`
	TargetBytesPerSecond   int64         `json:"target_bytes_per_second_per_direction"`
	TargetDuration         time.Duration `json:"target_duration"`
	StartedAt              time.Time     `json:"started_at"`
	Elapsed                time.Duration `json:"elapsed"`
	ExpectedUploadBytes    int64         `json:"expected_upload_bytes"`
	UploadBytes            int64         `json:"upload_bytes"`
	ExpectedDownloadBytes  int64         `json:"expected_download_bytes"`
	DownloadBytes          int64         `json:"download_bytes"`
	UploadBytesPerSecond   float64       `json:"upload_bytes_per_second"`
	DownloadBytesPerSecond float64       `json:"download_bytes_per_second"`
	Failures               int           `json:"failures"`
	FailureSamples         []string      `json:"failure_samples,omitempty"`
}

BandwidthResult records exact application bytes transferred by a phase.

func (BandwidthResult) Err

func (r BandwidthResult) Err() error

Err reports incomplete or failed transfers.

type Coordination

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

func NewCoordination

func NewCoordination(endpoint, token string) (*Coordination, error)

func (*Coordination) Get

func (c *Coordination) Get(ctx context.Context, name string, value any) (bool, error)

func (*Coordination) Put

func (c *Coordination) Put(ctx context.Context, name string, value any) error

func (*Coordination) Wait

func (c *Coordination) Wait(ctx context.Context, name string, value any) error

func (*Coordination) WorkloadContext

func (c *Coordination) WorkloadContext(parent context.Context) (context.Context, func())

WorkloadContext also stops participants measuring when a failure occurs. Stop joins its watcher; cleanup reports its outcome with a separate context.

type Coordinator

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

Coordinator stores immutable run events. the runner owns the phase sequence; participants acknowledge readiness/results under their own event names.

func NewCoordinator

func NewCoordinator() *Coordinator

func (*Coordinator) Handler

func (s *Coordinator) Handler(token string) http.Handler

type HeldStream

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

func (*HeldStream) Alive

func (s *HeldStream) Alive() bool

func (*HeldStream) BytesReceived

func (s *HeldStream) BytesReceived() int64

BytesReceived distinguishes ongoing delivery from a stalled, still-open socket.

func (*HeldStream) Close

func (s *HeldStream) Close() error

type Histogram

type Histogram struct {
	BoundsMilliseconds  []float64 `json:"bounds_milliseconds"`
	Counts              []uint64  `json:"counts"`
	Count               uint64    `json:"count"`
	SumMilliseconds     float64   `json:"sum_milliseconds"`
	MinimumMilliseconds float64   `json:"minimum_milliseconds"`
	MaximumMilliseconds float64   `json:"maximum_milliseconds"`
}

histogram counts are cumulative and use the production duration buckets.

func NewHistogram

func NewHistogram(samples []time.Duration) *Histogram

func (*Histogram) Merge

func (h *Histogram) Merge(other Histogram) error

func (*Histogram) Observe

func (h *Histogram) Observe(duration time.Duration)

func (*Histogram) Percentile

func (h *Histogram) Percentile(percentile int) *float64

type Phase

type Phase struct {
	Name        string           `json:"name"`
	Start       time.Time        `json:"start"`
	Duration    time.Duration    `json:"duration"`
	URLs        []string         `json:"urls"`
	Bandwidth   *BandwidthConfig `json:"bandwidth,omitempty"`
	Combined    bool             `json:"combined,omitempty"`
	Direct      bool             `json:"direct,omitempty"`
	HeldStreams int              `json:"held_streams,omitempty"`
	CloseHeld   bool             `json:"close_held,omitempty"`
	OpenHeld    bool             `json:"open_held,omitempty"`
	Done        bool             `json:"done,omitempty"`
}

Phase is sent by the coordinator; participants do not copy the scenario sequence. a zero duration requests correctness probes only.

type PublishedPublicURL

type PublishedPublicURL struct {
	Index      int             `json:"index"`
	Ready      publisher.Event `json:"ready"`
	Activation time.Duration   `json:"activation"`
}

type PublisherConfig

type PublisherConfig struct {
	Server, LoginToken, Domain, StateRoot, Target string
	HostnamePrefix                                string
	Ephemeral                                     bool
	HTTPClient                                    *http.Client
	RelayTLS                                      *tls.Config
	AllowedIPPrefixes                             []string
	// mixed forces alternating QUIC/TLS-TCP cohorts; auto uses production fallback.
	Transport                   TransportChoice
	QUICDisablePathMTUDiscovery bool
	QUICQlog                    bool
	QUICKeepAlive               time.Duration
	Parallel                    int
	RequestLimit                int
	// StartParallel overrides Parallel only during activation; shutdown has its own bound.
	StartParallel             int
	ReadyTimeout, StopTimeout time.Duration
	DrainTime                 time.Duration
	OnFailure                 func()
	OnActivationFailure       func(index int)
	Observe                   func(int, publisher.Event) error
	Report                    func(index int, err error)
}

type Publishers

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

func OpenPublishers

func OpenPublishers(ctx context.Context, config PublisherConfig) (_ *Publishers, retErr error)

func (*Publishers) Close

func (g *Publishers) Close(ctx context.Context) (ShutdownResult, error)

func (*Publishers) Failures

func (g *Publishers) Failures() <-chan error

func (*Publishers) Start

func (g *Publishers) Start(ctx context.Context, indexes []int) ([]PublishedPublicURL, error)

Start returns any ready results collected before failure, then cancels the group. the coordinator must call Close even after partial activation and call lifecycle methods serially.

func (*Publishers) Started

func (g *Publishers) Started() int

func (*Publishers) Stop

func (g *Publishers) Stop(ctx context.Context, indexes []int) (ShutdownResult, error)

Stop leaves public URLs running until their bounded shutdown slot is available.

type RequestResult

type RequestResult struct {
	URL          string        `json:"url,omitempty"`
	Scheduled    time.Time     `json:"scheduled"`
	Started      time.Time     `json:"started"`
	FirstByte    time.Time     `json:"first_body_byte,omitzero"`
	QueueDelay   time.Duration `json:"queue_delay"`
	DNS          time.Duration `json:"dns"`
	Connect      time.Duration `json:"connect"`
	TLS          time.Duration `json:"tls"`
	Duration     time.Duration `json:"duration"`
	Bytes        int64         `json:"bytes"`
	Error        string        `json:"error,omitempty"`
	Timeout      bool          `json:"timeout,omitempty"`
	QueueExpired bool          `json:"queue_expired,omitempty"`
}

type ShutdownResult

type ShutdownResult struct {
	StartedAt                     time.Time     `json:"started_at"`
	Duration                      time.Duration `json:"duration"`
	Attempts, Successes, Failures int
	Timings                       []time.Duration `json:"timings"`
}

type TransportChoice

type TransportChoice string

TransportChoice selects a benchmark publisher cohort or production fallback.

const (
	TransportAuto  TransportChoice = "auto"
	TransportMixed TransportChoice = "mixed"
	TransportQUIC  TransportChoice = "quic"
	TransportTCP   TransportChoice = "tcp"
)

func (TransportChoice) Valid

func (transport TransportChoice) Valid() bool

type Visitor

type Visitor struct {
	Roots         *x509.CertPool
	Address       string
	Resolver      *net.Resolver
	Network       string
	SourceAddress *net.TCPAddr
	PayloadBytes  int
}

func (Visitor) Bandwidth

func (v Visitor) Bandwidth(ctx context.Context, config BandwidthConfig, urls []string) (BandwidthResult, error)

Bandwidth runs paced, byte-verified transfers against the supplied URLs.

func (Visitor) Hold

func (v Visitor) Hold(parent context.Context, url string) (*HeldStream, error)

func (Visitor) Request

func (v Visitor) Request(parent context.Context, url string, scheduled time.Time) (result RequestResult)

func (Visitor) Run

func (v Visitor) Run(ctx context.Context, config VisitorConfig, urls []string) (VisitorResult, error)

type VisitorConfig

type VisitorConfig struct {
	Rate, Workers, QueueSlots int
	Start                     time.Time
	Duration                  time.Duration
	// OnResult is serialized and is intended for scenario-specific observations.
	OnResult func(RequestResult)
}

type VisitorResult

type VisitorResult struct {
	StartedAt      time.Time       `json:"started_at"`
	OfferDuration  time.Duration   `json:"offer_duration"`
	DrainDuration  time.Duration   `json:"drain_duration"`
	Workers        int             `json:"workers"`
	QueueSlots     int             `json:"queue_slots"`
	Rate           int             `json:"rate"`
	Scheduled      int             `json:"scheduled"`
	Started        int             `json:"started"`
	Completed      int             `json:"completed"`
	Successes      int             `json:"successes"`
	Failures       int             `json:"failures"`
	Timeouts       int             `json:"timeouts"`
	Missed         int             `json:"missed"`
	QueueExpired   int             `json:"queue_expired"`
	Bytes          int64           `json:"bytes"`
	QueueDelay     Histogram       `json:"queue_delay"`
	DNS            Histogram       `json:"dns"`
	Connect        Histogram       `json:"connect"`
	TLS            Histogram       `json:"tls"`
	FirstByte      Histogram       `json:"first_body_byte"`
	Total          Histogram       `json:"total"`
	FailuresSample []RequestResult `json:"failure_samples,omitempty"`
}

func (VisitorResult) Err

func (r VisitorResult) Err() error

func (*VisitorResult) Merge

func (r *VisitorResult) Merge(other VisitorResult) error

func (*VisitorResult) Observe

func (r *VisitorResult) Observe(request RequestResult)

Observe adds one completed or queue-expired request to a local summary.

Jump to

Keyboard shortcuts

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