Documentation
¶
Index ¶
- Variables
- func OptimalWindowSize(bandwidthKbps int, latencyMs int) uint32
- func PrintHeader(title string)
- func PrintResult(name string, result *BenchmarkResult)
- func TheoreticalThroughput(bandwidthKbps int) float64
- type BenchmarkResult
- type Config
- type Driver
- type FingerprintResult
- type Metrics
- func (m *Metrics) GetBucket() *latencyBucket
- func (m *Metrics) RecordConnection()
- func (m *Metrics) RecordFailure(err error, bucket *latencyBucket)
- func (m *Metrics) RecordH2Stream()
- func (m *Metrics) RecordSuccess(bytes int64, latency time.Duration, bucket *latencyBucket)
- func (m *Metrics) Result() *BenchmarkResult
- func (m *Metrics) Start()
- func (m *Metrics) Stop()
- type NetworkScenario
- type Proxy
- type Scenario
- type Toxic
- type ToxiproxyClient
- func (c *ToxiproxyClient) AddToxic(proxyName string, toxic *Toxic) error
- func (c *ToxiproxyClient) ApplyNetworkScenario(proxyName string, scenario NetworkScenario) error
- func (c *ToxiproxyClient) ClearToxics(proxyName string) error
- func (c *ToxiproxyClient) CreateProxy(proxy *Proxy) error
- func (c *ToxiproxyClient) GetProxy(name string) (*Proxy, error)
- func (c *ToxiproxyClient) Health() error
- func (c *ToxiproxyClient) RemoveToxic(proxyName, toxicName string) error
- func (c *ToxiproxyClient) Reset(proxyName string) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
OptimalWindowSize calculates the optimal HTTP/2 window size for a network scenario. Based on Bandwidth-Delay Product (BDP) calculation.
func PrintResult ¶
func PrintResult(name string, result *BenchmarkResult)
PrintResult prints a benchmark result in a formatted way.
func TheoreticalThroughput ¶
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 (*Driver) ValidateFingerprint ¶
func (d *Driver) ValidateFingerprint(ctx context.Context, expectedJA3Hash string) (*FingerprintResult, error)
ValidateFingerprint validates the client's fingerprint against expected values.
type FingerprintResult ¶
FingerprintResult holds fingerprint validation results.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics collects benchmark metrics with thread-safe operations.
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 ¶
RecordFailure records a failed request.
func (*Metrics) RecordH2Stream ¶
func (m *Metrics) RecordH2Stream()
RecordH2Stream records an HTTP/2 stream.
func (*Metrics) RecordSuccess ¶
RecordSuccess records a successful request.
func (*Metrics) Result ¶
func (m *Metrics) Result() *BenchmarkResult
Result returns the benchmark result.
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 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 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).