Performance and stress testing for Sentinel.
Load Testing Tools
wrk
High-performance HTTP benchmarking tool:
# Install
# Basic usage
# Options:
# -t12 12 threads
# -c400 400 connections
# -d30s 30 second duration
hey
Simple HTTP load generator:
# Install
# Basic usage
# Options:
# -n 10000 10,000 requests total
# -c 100 100 concurrent workers
k6
Modern load testing with JavaScript:
# Install
Basic Load Tests
Throughput Test
Measure maximum requests per second:
# Start Sentinel
&
# Run throughput test
Expected output:
Running 1m test @ http://localhost:8080/health
4 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.23ms 0.45ms 15.32ms 92.45%
Req/Sec 20.12k 1.23k 24.56k 85.12%
4821456 requests in 1.00m, 512.34MB read
Requests/sec: 80357.60
Transfer/sec: 8.54MB
Latency Test
Measure response time distribution:
# Output includes:
# - Response time histogram
# - Latency percentiles (p50, p90, p99)
# - Error rates
Connection Test
Test connection handling:
# Many short-lived connections
# Keep-alive connections
k6 Test Scripts
Basic Script
// load_test.js
;
;
;
Run:
Stress Test Script
// stress_test.js
;
;
;
Spike Test Script
// spike_test.js
;
;
Testing Agents
Agent Latency Impact
// agent_overhead.js
;
;
;
;
Agent Under Load
Test agent behavior under pressure:
# Start agent with limited resources
&
# Generate high load
Monitor agent metrics:
|
Metrics Collection
Prometheus Metrics During Load Test
# Start Prometheus
# During load test, query:
# - Request rate: rate(sentinel_requests_total[1m])
# - Latency p99: histogram_quantile(0.99, rate(sentinel_request_duration_seconds_bucket[1m]))
# - Error rate: rate(sentinel_requests_total{status=~"5.."}[1m])
Recording Results
# Save wrk output
|
# k6 with JSON output
# k6 with InfluxDB
Benchmark Tests
Cargo Benchmarks
Using criterion for micro-benchmarks:
// benches/routing.rs
use ;
use Router;
criterion_group!;
criterion_main!;
Run benchmarks:
# Save baseline
# Compare to baseline
Performance Profiling
CPU Profiling with perf
# Linux
&
# Run load test
CPU Profiling with Instruments (macOS)
# Profile with Instruments
Memory Profiling
# Using heaptrack
&
# Run load test
# Using valgrind
Flamegraphs
# Install flamegraph
# Generate flamegraph
&
# Run load test
# Stop sentinel
# View flamegraph.svg in browser
Performance Checklist
Before Release
-
Baseline Performance
-
Measure current RPS with
wrk - Record p50, p95, p99 latencies
- Document memory usage under load
-
Measure current RPS with
-
Regression Testing
- Compare against previous release
- Check for latency increases
- Verify no memory leaks
-
Stress Testing
- Run 1-hour stress test
- Monitor for degradation over time
- Check connection handling under load
Performance Targets
| Metric | Target | Minimum |
|---|---|---|
| RPS (simple proxy) | 100,000 | 50,000 |
| p50 latency | < 1ms | < 5ms |
| p99 latency | < 10ms | < 50ms |
| Memory per connection | < 10KB | < 50KB |
Troubleshooting Performance
High Latency
# Check for blocking operations
RUST_LOG=trace |
# Profile to find hot spots
Connection Issues
# Check file descriptor limits
# Check connection states
| | |
Memory Growth
# Monitor memory over time
while ; do
done |
CI Performance Tests
GitHub Actions
name: Performance
on:
push:
branches:
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Run benchmarks
run: cargo bench -- --save-baseline new
- name: Compare benchmarks
run: cargo bench -- --baseline main --load-baseline new
Next Steps
- Testing Overview - General testing strategy
- Integration Tests - E2E testing
- Release Process - Performance requirements for releases