Benchmark Commands

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.

Updated for ɳSelf v0.4.8

Benchmarking (v0.4.6+)

  • - Load Testing: HTTP and GraphQL load tests
  • - Stress Testing: Find breaking points
  • - Baseline Comparison: Compare against previous runs
  • - Detailed Reports: Latency percentiles, throughput, errors

Running Benchmarks

nself bench run

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

Options

OptionDescriptionDefault
--requests NNumber of requests1000
--concurrency NConcurrent connections10
--duration NTest duration in seconds30
--rate NRequests per second limitunlimited
--warmup NWarmup period in seconds5
--output FILESave results to file-
--forceSkip confirmation for stress testsfalse
--jsonOutput in JSON formatfalse

Advanced Usage

# Thorough benchmark with more requests
nself bench run api --requests 5000 --concurrency 50

Baseline Management

nself bench baseline

Establish a performance baseline for future comparisons.

nself bench baseline           # Create baseline

# The baseline is saved to .ɳSelf/benchmarks/baseline_latest.json

nself bench compare

Compare 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:

Stress Testing

nself bench stress

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 point

Warning: Stress tests can impact system performance.

Reports

nself bench report

Generate benchmark report.

nself bench report              # Show recent benchmarks
nself bench report --json       # JSON output

Benchmark Output Example

  ➞ 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

Benchmark Targets

TargetDescription
apiHasura GraphQL API
authAuthentication service
dbPostgreSQL database
functionsServerless functions
custom <url>Custom HTTP endpoint

Benchmark Tools

nself bench uses available tools in order of preference:

  1. wrk - High-performance HTTP benchmarking tool
  2. hey - HTTP load generator
  3. ab (Apache Bench) - Classic HTTP server benchmarking
  4. curl (fallback) - Basic HTTP testing

Installing Recommended Tools

# macOS
brew install wrk

# Ubuntu/Debian
apt-get install apache2-utils

Usage Examples

# 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

Next Steps