driver

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NetworkLAN = NetworkScenario{
		Name:       "LAN",
		Latency:    1,
		Jitter:     0,
		Bandwidth:  0,
		PacketLoss: 0,
	}

	NetworkBroadband = NetworkScenario{
		Name:       "Broadband",
		Latency:    20,
		Jitter:     5,
		Bandwidth:  100 * 1024,
		PacketLoss: 0.1,
	}

	Network4G = NetworkScenario{
		Name:       "4G Mobile",
		Latency:    50,
		Jitter:     20,
		Bandwidth:  10 * 1024,
		PacketLoss: 1.0,
	}

	NetworkLossyWiFi = NetworkScenario{
		Name:       "Lossy WiFi",
		Latency:    30,
		Jitter:     10,
		Bandwidth:  50 * 1024,
		PacketLoss: 3.0,
	}

	NetworkIntercontinental = NetworkScenario{
		Name:       "Intercontinental",
		Latency:    150,
		Jitter:     30,
		Bandwidth:  50 * 1024,
		PacketLoss: 0.5,
	}
)

Predefined network scenarios

Functions

func OptimalWindowSize

func OptimalWindowSize(bandwidthKbps int, latencyMs int) uint32

OptimalWindowSize calculates the optimal HTTP/2 window size for a network scenario. Based on Bandwidth-Delay Product (BDP) calculation.

func PrintHeader

func PrintHeader(title string)

PrintHeader prints a benchmark header.

func PrintResult

func PrintResult(name string, result *BenchmarkResult)

PrintResult prints a benchmark result in a formatted way.

func TheoreticalThroughput

func TheoreticalThroughput(bandwidthKbps int) float64

TheoreticalThroughput calculates the theoretical max throughput for a network scenario. Returns MB/s.

Types

type BenchmarkResult

type BenchmarkResult struct {
	// Throughput
	RequestsCompleted int64
	BytesTransferred  int64
	ActualRPS         float64
	Throughput        float64 // MB/s
	Duration          time.Duration

	// Latency
	LatencyAvg  time.Duration
	LatencyP50  time.Duration
	LatencyP95  time.Duration
	LatencyP99  time.Duration
	LatencyP999 time.Duration
	LatencyMax  time.Duration

	// Reliability
	SuccessRate    float64 // Percentage
	TotalRequests  int64
	FailedRequests int64
	ErrorBreakdown map[string]int

	// Protocol
	H2Streams         int64
	ConnectionsOpened int64

	// Fingerprint validation (set by caller)
	FingerprintValid bool
	FingerprintScore float64
}

BenchmarkResult holds the final benchmark results.

type Config

type Config struct {
	OracleURL    string // e.g., "https://localhost:8443"
	PayloadURL   string // e.g., "https://localhost:19443" (through toxiproxy)
	ToxiproxyURL string // e.g., "http://localhost:8474"
	Profile      string // "chrome143", "firefox146", "safari261"
}

Config holds driver configuration.

type Driver

type Driver struct {
	// Target URLs
	OracleURL  string
	PayloadURL string

	// Toxiproxy client (optional)
	Toxiproxy *ToxiproxyClient
	// contains filtered or unexported fields
}

Driver runs benchmark scenarios.

func NewDriver

func NewDriver(cfg Config) *Driver

NewDriver creates a new benchmark driver.

func (*Driver) Run

func (d *Driver) Run(ctx context.Context, scenario Scenario) (*BenchmarkResult, error)

Run executes a benchmark scenario.

func (*Driver) ValidateFingerprint

func (d *Driver) ValidateFingerprint(ctx context.Context, expectedJA3Hash string) (*FingerprintResult, error)

ValidateFingerprint validates the client's fingerprint against expected values.

type FingerprintResult

type FingerprintResult struct {
	Raw        string
	Valid      bool
	StatusCode int
}

FingerprintResult holds fingerprint validation results.

type Metrics

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

Metrics collects benchmark metrics with thread-safe operations.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a new metrics collector.

func (*Metrics) GetBucket

func (m *Metrics) GetBucket() *latencyBucket

GetBucket returns a latency bucket for the calling goroutine.

func (*Metrics) RecordConnection

func (m *Metrics) RecordConnection()

RecordConnection records a new connection.

func (*Metrics) RecordFailure

func (m *Metrics) RecordFailure(err error, bucket *latencyBucket)

RecordFailure records a failed request.

func (*Metrics) RecordH2Stream

func (m *Metrics) RecordH2Stream()

RecordH2Stream records an HTTP/2 stream.

func (*Metrics) RecordSuccess

func (m *Metrics) RecordSuccess(bytes int64, latency time.Duration, bucket *latencyBucket)

RecordSuccess records a successful request.

func (*Metrics) Result

func (m *Metrics) Result() *BenchmarkResult

Result returns the benchmark result.

func (*Metrics) Start

func (m *Metrics) Start()

Start marks the beginning of the benchmark.

func (*Metrics) Stop

func (m *Metrics) Stop()

Stop marks the end of the benchmark.

type NetworkScenario

type NetworkScenario struct {
	Name       string
	Latency    int     // One-way latency in ms
	Jitter     int     // Latency jitter in ms
	Bandwidth  int     // Bandwidth in Kbps (0 = unlimited)
	PacketLoss float64 // Packet loss percentage (0-100)
}

NetworkScenario defines network conditions to simulate.

func AllNetworkScenarios

func AllNetworkScenarios() []NetworkScenario

AllNetworkScenarios returns all predefined network conditions.

type Proxy

type Proxy struct {
	Name     string `json:"name"`
	Listen   string `json:"listen"`
	Upstream string `json:"upstream"`
	Enabled  bool   `json:"enabled"`
}

Proxy represents a Toxiproxy proxy.

type Scenario

type Scenario struct {
	Name        string
	Description string

	// Load configuration
	TargetRPS   float64       // Target requests per second (0 = unlimited)
	Duration    time.Duration // Test duration
	Warmup      time.Duration // Warmup period (excluded from stats)
	Concurrency int           // Max concurrent requests

	// Request configuration
	Method   string // HTTP method
	Endpoint string // Endpoint path (e.g., "/bytes/1024")
	Body     []byte // Request body for POST

	// Network scenario
	Network NetworkScenario
}

Scenario defines a benchmark scenario.

func AllScenarios

func AllScenarios() []Scenario

AllScenarios returns all predefined scenarios.

func AssetDownloader

func AssetDownloader() Scenario

AssetDownloader simulates large file downloads. Few concurrent large transfers.

func DataScraper

func DataScraper() Scenario

DataScraper simulates sustained scraping workload. Steady state with many small requests.

func FingerprintValidation

func FingerprintValidation() Scenario

FingerprintValidation is a minimal scenario for fingerprint testing.

func HighLatency

func HighLatency() Scenario

HighLatency tests performance under high-latency network conditions.

func LossyNetwork

func LossyNetwork() Scenario

LossyNetwork tests resilience to packet loss.

func SneakerDrop

func SneakerDrop() Scenario

SneakerDrop simulates sudden burst traffic (e.g., limited product release). Cold start with maximum load immediately.

type Toxic

type Toxic struct {
	Name       string                 `json:"name"`
	Type       string                 `json:"type"`
	Stream     string                 `json:"stream"`
	Toxicity   float64                `json:"toxicity"`
	Attributes map[string]interface{} `json:"attributes"`
}

Toxic represents a Toxiproxy toxic (network impairment).

type ToxiproxyClient

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

ToxiproxyClient manages network conditions via Toxiproxy.

func NewToxiproxyClient

func NewToxiproxyClient(baseURL string) *ToxiproxyClient

NewToxiproxyClient creates a new Toxiproxy client.

func (*ToxiproxyClient) AddToxic

func (c *ToxiproxyClient) AddToxic(proxyName string, toxic *Toxic) error

AddToxic adds a toxic to a proxy.

func (*ToxiproxyClient) ApplyNetworkScenario

func (c *ToxiproxyClient) ApplyNetworkScenario(proxyName string, scenario NetworkScenario) error

ApplyNetworkScenario applies a network scenario to a proxy.

func (*ToxiproxyClient) ClearToxics

func (c *ToxiproxyClient) ClearToxics(proxyName string) error

ClearToxics removes all toxics from a proxy.

func (*ToxiproxyClient) CreateProxy

func (c *ToxiproxyClient) CreateProxy(proxy *Proxy) error

CreateProxy creates a new proxy.

func (*ToxiproxyClient) GetProxy

func (c *ToxiproxyClient) GetProxy(name string) (*Proxy, error)

GetProxy retrieves a proxy by name.

func (*ToxiproxyClient) Health

func (c *ToxiproxyClient) Health() error

Health checks if Toxiproxy is reachable.

func (*ToxiproxyClient) RemoveToxic

func (c *ToxiproxyClient) RemoveToxic(proxyName, toxicName string) error

RemoveToxic removes a toxic from a proxy.

func (*ToxiproxyClient) Reset

func (c *ToxiproxyClient) Reset(proxyName string) error

Reset removes all toxics from a proxy (returns to clean state).

Jump to

Keyboard shortcuts

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