The nself bench command provides performance benchmarking and load testing capabilities. Run benchmarks against your API, database, and other services to measure performance and establish baselines.
Run benchmark against a target.
nself bench run [target]
# Targets:
# api Benchmark GraphQL API
# auth Benchmark auth service
# db Benchmark database
# functions Benchmark serverless functions
# custom <url> Custom endpoint
# Examples
nself bench run api # Benchmark GraphQL API
nself bench run auth # Benchmark auth service
nself bench run db # Benchmark database
nself bench run functions # Benchmark serverless functions
nself bench run custom <url> # Custom endpoint| Option | Description | Default |
|---|---|---|
| --requests N | Number of requests | 1000 |
| --concurrency N | Concurrent connections | 10 |
| --duration N | Test duration in seconds | 30 |
| --rate N | Requests per second limit | unlimited |
| --warmup N | Warmup period in seconds | 5 |
| --output FILE | Save results to file | - |
| --force | Skip confirmation for stress tests | false |
| --json | Output in JSON format | false |
# Thorough benchmark with more requests
nself bench run api --requests 5000 --concurrency 50Establish a performance baseline for future comparisons.
nself bench baseline # Create baseline
# The baseline is saved to .ɳSelf/benchmarks/baseline_latest.jsonCompare current performance against a baseline.
nself bench compare # Compare to latest baseline
nself bench compare baseline.json # Compare to specific file
# Output:
# Comparison: current vs baseline
#
# Metric Current Baseline Change
# ---------------------------------------------
# RPS 2,345 2,100 +11.7%
# Latency (p50) 23ms 25ms -8.0%
# Latency (p99) 89ms 95ms -6.3%
# Error Rate 0.1% 0.2% -50.0%When comparing against a baseline:
Run stress tests to find breaking points.
nself bench stress [target]
# Examples
nself bench stress api # Stress test API
nself bench stress api --duration 120 # 2 minute stress test
# Output:
# Stress Test Results:
# Connections RPS Latency(p99) Errors
# 50 1,234 45ms 0%
# 100 2,156 67ms 0%
# 150 2,890 95ms 0.1%
# 200 3,102 145ms 0.5%
# 250 2,987 289ms 2.1% <- Degradation
# 300 2,456 567ms 5.3% <- Breaking pointWarning: Stress tests can impact system performance.
Generate benchmark report.
nself bench report # Show recent benchmarks
nself bench report --json # JSON output ➞ Running curl benchmark
URL: https://api.local.nself.org/v1/graphql
Requests: 1000
➞ Results
Total requests: 1000
Successful: 998
Failed: 2
Total time: 45 seconds
Requests/sec: 22 req/sec
Avg response: 45 ms
Min response: 12 ms
Max response: 234 ms| Target | Description |
|---|---|
| api | Hasura GraphQL API |
| auth | Authentication service |
| db | PostgreSQL database |
| functions | Serverless functions |
| custom <url> | Custom HTTP endpoint |
nself bench uses available tools in order of preference:
# macOS
brew install wrk
# Ubuntu/Debian
apt-get install apache2-utils# Quick API benchmark
nself bench run api
# Thorough benchmark with more requests
nself bench run api --requests 5000 --concurrency 50
# Establish baseline
nself bench baseline
# Compare against baseline
nself bench compare
# Stress test for 60 seconds
nself bench stress api --duration 60 --force
# Export benchmark report
nself bench report --json > benchmarks.json