تخطَّ إلى المحتوى

oha

oha هو مُولّد حمل HTTP سريع وحديث مكتوب بلغة Rust. يتميز بواجهة طرفية فورية تعرض إحصائيات مباشرة، ويدعم HTTP/1.1 و HTTP/2 والرؤوس المخصصة وأجسام الطلبات، ويوفر مخرجات تفصيلية لتوزيع الكمون.

التثبيت

# Using cargo (Rust)
cargo install oha

# macOS
brew install oha

# Linux (prebuilt binary)
curl -sSfL https://github.com/hatoo/oha/releases/latest/download/oha-linux-amd64 \
  -o /usr/local/bin/oha
chmod +x /usr/local/bin/oha

# Docker
docker run --rm hatoo/oha http://host.docker.internal:8080/

# Verify installation
oha --version

الاستخدام الأساسي

# Simple benchmark (200 requests, default concurrency)
oha http://localhost:8080/

# Specify number of requests
oha -n 1000 http://localhost:8080/

# Specify duration instead of request count
oha -z 30s http://localhost:8080/

# Set concurrent connections
oha -c 50 http://localhost:8080/

# Combine: 50 connections for 30 seconds
oha -c 50 -z 30s http://localhost:8080/

Requests Per Second

# Rate-limited testing (target specific RPS)
oha -q 100 http://localhost:8080/
# Sends exactly 100 requests per second

# Rate limit with concurrency
oha -c 20 -q 500 -z 60s http://localhost:8080/
# 20 concurrent connections targeting 500 RPS for 60 seconds

# Burst testing (no rate limit, as fast as possible)
oha -c 100 -z 30s http://localhost:8080/

Concurrent Connections

# Light load
oha -c 10 -z 30s http://localhost:8080/

# Medium load
oha -c 100 -z 30s http://localhost:8080/

# Heavy load
oha -c 500 -z 30s http://localhost:8080/

# Stress test
oha -c 1000 -z 60s http://localhost:8080/

Duration and Timing

# Run for specific duration
oha -z 10s http://localhost:8080/   # 10 seconds
oha -z 5m http://localhost:8080/    # 5 minutes

# Fixed number of requests
oha -n 5000 http://localhost:8080/

# With timeout per request
oha -t 5s -c 100 -z 30s http://localhost:8080/
# Each request times out after 5 seconds

HTTP/2

# Force HTTP/2
oha --http2 http://localhost:8080/

# HTTP/2 with concurrent streams
oha --http2 -c 100 -z 30s https://localhost:8443/

# HTTP/1.1 (default)
oha --http-version 1.1 http://localhost:8080/

Custom Headers

# Add custom headers
oha -H "Authorization: Bearer token123" http://localhost:8080/api

# Multiple headers
oha -H "Authorization: Bearer token123" \
    -H "Accept: application/json" \
    -H "X-Request-ID: load-test" \
    http://localhost:8080/api

# Custom User-Agent
oha -H "User-Agent: oha-loadtest/1.0" http://localhost:8080/

Request Body

# POST with JSON body
oha -m POST -d '{"key": "value"}' \
    -H "Content-Type: application/json" \
    http://localhost:8080/api/items

# POST with body from file
oha -m POST -D payload.json \
    -H "Content-Type: application/json" \
    http://localhost:8080/api/items

# PUT request
oha -m PUT -d '{"name": "updated"}' \
    -H "Content-Type: application/json" \
    http://localhost:8080/api/items/1

# DELETE request
oha -m DELETE http://localhost:8080/api/items/1

Real-time TUI

# The TUI is shown by default during tests
oha -c 100 -z 30s http://localhost:8080/

# TUI shows:
# - Live requests/sec counter
# - Latency histogram (real-time)
# - Status code distribution
# - Error count
# - Elapsed time and progress

# Disable TUI (for CI/scripting)
oha --no-tui -c 100 -z 30s http://localhost:8080/

صيغ الإخراج

# JSON output (for scripting/analysis)
oha -j -c 100 -z 30s http://localhost:8080/ > results.json

# JSON output example fields:
# - summary.successRate
# - summary.total
# - summary.slowest
# - summary.fastest
# - summary.average
# - latencyDistribution
# - statusCodeDistribution
# - rps.mean / rps.stddev

# Parse JSON results
oha -j -c 100 -z 30s http://localhost:8080/ | \
    python3 -c "import sys,json; d=json.load(sys.stdin); print(f'Avg: {d[\"summary\"][\"average\"]:.3f}s, RPS: {d[\"summary\"][\"requestsPerSec\"]:.0f}')"

TLS and Certificates

# HTTPS endpoints (certificates verified by default)
oha https://example.com/

# Skip TLS verification (self-signed certs)
oha --insecure https://localhost:8443/

# With client certificate
oha --cert client.crt --key client.key https://localhost:8443/

Connection Settings

# Keep-alive (enabled by default)
oha -c 100 -z 30s http://localhost:8080/

# Disable keep-alive (new connection per request)
oha --disable-keepalive -c 100 -z 30s http://localhost:8080/

# Set connection timeout
oha --connect-timeout 3s http://localhost:8080/

# Redirect following
oha --redirect 5 http://localhost:8080/redirect  # Follow up to 5 redirects

Common Benchmark Patterns

# Quick health check
oha -n 10 http://localhost:8080/health

# Baseline single-connection performance
oha -c 1 -z 30s --no-tui http://localhost:8080/

# Scalability test
for c in 1 10 50 100 200 500; do
    echo "=== $c connections ==="
    oha -c $c -z 15s --no-tui http://localhost:8080/ 2>&1 | tail -20
    echo ""
    sleep 2
done

# Compare HTTP/1.1 vs HTTP/2
echo "=== HTTP/1.1 ==="
oha -c 100 -z 30s --no-tui http://localhost:8080/
echo "=== HTTP/2 ==="
oha -c 100 -z 30s --http2 --no-tui https://localhost:8443/

# Sustained load test
oha -c 200 -q 1000 -z 10m --no-tui http://localhost:8080/

Reading Results

# Example oha output:
# Summary:
#   Success rate: 100.00%
#   Total:        30.0012 secs
#   Slowest:      0.0482 secs
#   Fastest:      0.0002 secs
#   Average:      0.0051 secs
#   Requests/sec: 19523.45
#
# Latency Distribution:
#   10% in 0.0021 secs
#   25% in 0.0032 secs
#   50% in 0.0045 secs
#   75% in 0.0062 secs
#   90% in 0.0085 secs
#   95% in 0.0105 secs
#   99% in 0.0182 secs
#
# Status code distribution:
#   [200] 585712 responses