This document provides detailed information about the gRPC-zig benchmarking system.
The gRPC-zig benchmarking tool provides comprehensive performance measurements for the gRPC implementation, including:
- Latency Metrics: Min, max, average, P95, and P99 latency measurements
- Throughput Metrics: Requests per second under various load conditions
- Error Metrics: Success and failure rates
- Scalability Testing: Concurrent client simulation
-
Build the project:
zig build
-
Run benchmarks with default settings:
./scripts/run_benchmark.sh
-
Run benchmarks with custom parameters:
./zig-out/bin/grpc-benchmark --requests 1000 --clients 10 --output json
| Option | Description | Default |
|---|---|---|
--host |
Server hostname or IP | localhost |
--port |
Server port | 50051 |
--requests |
Number of requests per client | 1000 |
--clients |
Number of concurrent clients | 10 |
--size |
Request payload size in bytes | 1024 |
--output |
Output format (text or json) |
text |
--help |
Show help message | - |
# Basic benchmark
./zig-out/bin/grpc-benchmark
# High-load benchmark
./zig-out/bin/grpc-benchmark --requests 5000 --clients 50 --size 2048
# JSON output for analysis
./zig-out/bin/grpc-benchmark --output json > results.jsonThe benchmark tool is integrated into the CI/CD pipeline and runs automatically on:
- Pull Requests: Benchmark results are posted as PR comments
- Main Branch Pushes: Results are stored as artifacts for tracking
- Performance Regression Detection: Automatic alerts for performance degradation
The benchmark runs with reduced load in CI to ensure fast feedback:
- Requests per client: 100
- Concurrent clients: 5
- Payload size: 512 bytes
- Timeout: 60 seconds
The CI system checks for performance regressions using these thresholds:
- Minimum Throughput: 1000 requests/second
- Maximum P95 Latency: 100ms
- Maximum Error Rate: 5%
Benchmark Results:
==================
Total Requests: 1000
Successful: 995
Failed: 5
Error Rate: 0.50%
Total Duration: 2543.21ms
Requests/sec: 391.24
Latency Stats:
Min: 1.23ms
Max: 45.67ms
Avg: 12.34ms
P95: 23.45ms
P99: 34.56ms
{
"total_requests": 1000,
"successful_requests": 995,
"failed_requests": 5,
"total_duration_ms": 2543.21,
"requests_per_second": 391.24,
"latency_stats": {
"min_ms": 1.23,
"max_ms": 45.67,
"avg_ms": 12.34,
"p95_ms": 23.45,
"p99_ms": 34.56
},
"error_rate": 0.005,
"timestamp": 1640995200
}- Payload Size: Larger payloads generally reduce throughput but may better simulate real-world usage
- Concurrency: Optimal client count depends on server resources and network conditions
- Warmup: The tool includes automatic warmup requests to ensure stable measurements
- Environment: Run benchmarks in consistent environments for reliable comparisons
- Average Latency: Overall response time performance
- P95 Latency: 95% of requests complete within this time
- P99 Latency: 99% of requests complete within this time (captures outliers)
- Requests/Second: Total system throughput under the given load
- Consider both successful and failed requests when analyzing throughput
- Error Rate: Percentage of failed requests
- Low error rates (< 1%) are expected under normal conditions
- High error rates may indicate server overload or network issues
- Connection Refused: Ensure the gRPC server is running on the specified host/port
- High Error Rates: Check server logs for errors, consider reducing load
- Inconsistent Results: Ensure stable network conditions and sufficient server resources
For debugging benchmark issues, run with verbose logging:
# Enable Zig debug logging
./zig-out/bin/grpc-benchmark --requests 10 --clients 1To add new benchmark scenarios or metrics:
- Modify
src/benchmark.zigto add new measurement capabilities - Update this documentation
- Ensure CI thresholds remain appropriate
- Test with various load patterns
src/benchmark.zig- Main benchmark implementationscripts/run_benchmark.sh- Local testing script.github/workflows/ci.yml- CI/CD configurationexamples/basic_server.zig- Test server with benchmark handler