stress

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package stress provides a multi-protocol load testing engine for the Nexus CLI.

Package stress provides a multi-protocol load testing engine for the Nexus CLI.

Package stress provides a multi-protocol load testing engine for the Nexus CLI. It supports generating load for HTTP, WebSocket, and gRPC endpoints, and collecting detailed performance metrics.

Package stress provides a multi-protocol load testing engine for the Nexus CLI.

Package stress provides a multi-protocol load testing engine for the Nexus CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRPCConfig

type GRPCConfig struct {
	Target      string
	Method      string // Full method string, e.g., "/task.v1.TaskService/GetTask"
	Payload     []byte // Raw payload bytes
	Concurrency int
	Rate        int // Requests per second
	Duration    time.Duration
}

GRPCConfig defines the configuration for a gRPC load test.

type GRPCRunner

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

GRPCRunner executes a gRPC load test.

func NewGRPCRunner

func NewGRPCRunner(ctx context.Context, cfg GRPCConfig, metrics *Metrics) (*GRPCRunner, error)

NewGRPCRunner creates a new GRPCRunner.

func (*GRPCRunner) Close

func (r *GRPCRunner) Close() error

Close closes the underlying gRPC connection.

func (*GRPCRunner) Run

func (r *GRPCRunner) Run(ctx context.Context)

Run starts the load test and blocks until it completes or context is canceled.

type HTTPConfig

type HTTPConfig struct {
	Method      string
	URL         string
	Body        []byte
	Headers     map[string]string
	Concurrency int
	Rate        int // requests per second across all workers
	Duration    time.Duration
}

HTTPConfig defines the configuration for an HTTP load test.

type HTTPRunner

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

HTTPRunner executes an HTTP load test.

func NewHTTPRunner

func NewHTTPRunner(cfg HTTPConfig, metrics *Metrics) *HTTPRunner

NewHTTPRunner creates a new HTTPRunner.

func (*HTTPRunner) Run

func (r *HTTPRunner) Run(ctx context.Context)

Run starts the load test and blocks until it completes or the context is canceled.

type Metrics

type Metrics struct {
	TotalRequests uint64
	TotalErrors   uint64
	ErrorTypes    map[string]uint64
	StatusCodes   map[int]uint64

	Latencies []time.Duration

	StartTime time.Time
	EndTime   time.Time
	// contains filtered or unexported fields
}

Metrics represents a thread-safe collector for load test metrics.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics initializes a new Metrics collector.

func (*Metrics) Calculate

func (m *Metrics) Calculate() Report

Calculate computes percentiles, throughput, and returns a summarized Report.

func (*Metrics) Record

func (m *Metrics) Record(latency time.Duration, statusCode int, err error)

Record adds a single request's result to the metrics.

func (*Metrics) Stop

func (m *Metrics) Stop()

Stop marks the end of the load test and records the end time.

type Phase

type Phase struct {
	Name        string        `yaml:"name"`
	Duration    time.Duration `yaml:"duration"`
	Rate        int           `yaml:"rate"`
	Connections int           `yaml:"connections,omitempty"` // Used for WebSocket
	Targets     []Target      `yaml:"targets"`
}

Phase represents a distinct period of time within a load test with specific traffic characteristics.

type Report

type Report struct {
	TotalRequests  uint64
	TotalErrors    uint64
	Duration       time.Duration
	RequestsPerSec float64

	ErrorTypes  map[string]uint64
	StatusCodes map[int]uint64

	MinLatency  time.Duration
	MaxLatency  time.Duration
	MeanLatency time.Duration

	P50 time.Duration
	P90 time.Duration
	P95 time.Duration
	P99 time.Duration
}

Report contains the calculated summary of a load test.

type Scenario

type Scenario struct {
	Name   string  `yaml:"name"`
	Phases []Phase `yaml:"phases"`
}

Scenario represents a complete load testing scenario with multiple phases.

func ParseScenario

func ParseScenario(filepath string) (*Scenario, error)

ParseScenario reads and parses a YAML scenario file.

type Target

type Target struct {
	Method string `yaml:"method"`
	URL    string `yaml:"url"`
	Body   string `yaml:"body,omitempty"`
	Weight int    `yaml:"weight,omitempty"` // Probability weight compared to other targets
}

Target defines a single endpoint to hit during a load test phase.

type WSConfig

type WSConfig struct {
	URL         string
	Concurrency int
	Rate        int // messages per second per connection
	Duration    time.Duration
	Message     []byte // Payload to send
}

WSConfig defines the configuration for a WebSocket load test.

type WSRunner

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

WSRunner executes a WebSocket load test.

func NewWSRunner

func NewWSRunner(cfg WSConfig, metrics *Metrics) *WSRunner

NewWSRunner creates a new WSRunner.

func (*WSRunner) Run

func (r *WSRunner) Run(ctx context.Context)

Run starts the load test and blocks until it completes or context is canceled.

Jump to

Keyboard shortcuts

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