|
| 1 | +# BunGate API Gateway Benchmark |
| 2 | + |
| 3 | +This directory contains a comprehensive benchmark suite comparing BunGate against industry-standard API gateways (Nginx and Envoy) using Docker Compose. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The benchmark evaluates three API gateways implementing round-robin load balancing: |
| 8 | + |
| 9 | +- **BunGate**: High-performance HTTP gateway built on Bun.js using the actual BunGate library |
| 10 | +- **Nginx**: Industry-standard reverse proxy and load balancer |
| 11 | +- **Envoy**: Modern proxy designed for cloud-native applications |
| 12 | + |
| 13 | +## Architecture |
| 14 | + |
| 15 | +``` |
| 16 | +┌─────────────┐ ┌─────────────┐ ┌─────────────┐ |
| 17 | +│ BunGate │ │ Nginx │ │ Envoy │ |
| 18 | +│ :3000 │ │ :3001 │ │ :3002 │ |
| 19 | +└─────────────┘ └─────────────┘ └─────────────┘ |
| 20 | + │ │ │ |
| 21 | + └───────────────────┼───────────────────┘ |
| 22 | + │ |
| 23 | + ┌────────────────┼────────────────┐ |
| 24 | + │ │ │ |
| 25 | + ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ |
| 26 | + │Echo Server 1│ │Echo Server 2│ │Echo Server 3│ |
| 27 | + │ :8081 │ │ :8082 │ │ :8083 │ |
| 28 | + └─────────────┘ └─────────────┘ └─────────────┘ |
| 29 | +``` |
| 30 | + |
| 31 | +## Test Configuration |
| 32 | + |
| 33 | +- **Backend**: 3 high-performance Bun.js echo servers |
| 34 | +- **Load Balancing**: Round-robin strategy |
| 35 | +- **Benchmark Tool**: wrk (HTTP benchmarking tool) |
| 36 | +- **Duration**: 30 seconds |
| 37 | +- **Connections**: 150 concurrent connections |
| 38 | +- **Threads**: 8 worker threads |
| 39 | +- **Test Method**: Latency-focused performance testing |
| 40 | + |
| 41 | +## Quick Start |
| 42 | + |
| 43 | +1. **Prerequisites**: |
| 44 | + - Docker and Docker Compose installed |
| 45 | + - Sufficient system resources (recommended: 4+ CPU cores, 8GB+ RAM) |
| 46 | + |
| 47 | +2. **Run the benchmark**: |
| 48 | + |
| 49 | + ```bash |
| 50 | + # Start all services |
| 51 | + docker-compose up -d |
| 52 | + |
| 53 | + # Wait for services to be ready (about 30 seconds) |
| 54 | + docker-compose logs -f bungate nginx envoy |
| 55 | + |
| 56 | + # Run the benchmark |
| 57 | + docker-compose exec wrk /scripts/benchmark.sh |
| 58 | + |
| 59 | + # Generate a fresh comprehensive report |
| 60 | + docker-compose exec wrk /scripts/wrk_report.sh |
| 61 | + |
| 62 | + # View results |
| 63 | + docker-compose exec wrk cat /results/wrk_benchmark_report.txt |
| 64 | + ``` |
| 65 | + |
| 66 | +3. **Cleanup**: |
| 67 | + ```bash |
| 68 | + docker-compose down -v |
| 69 | + ``` |
| 70 | + |
| 71 | +## Results Summary |
| 72 | + |
| 73 | +Performance Results Summary: |
| 74 | + |
| 75 | +🏆 Envoy: 46257.27 RPS (Winner) |
| 76 | +🥈 Nginx: 28665.95 RPS |
| 77 | +🥉 BunGate: 20627.36 RPS |
| 78 | + |
| 79 | +## Output |
| 80 | + |
| 81 | +The benchmark generates: |
| 82 | + |
| 83 | +1. **Performance comparison table**: RPS, latency percentiles, errors |
| 84 | +2. **Load balancing analysis**: Distribution verification across all backend servers |
| 85 | +3. **Winner determination**: Best performing gateway with detailed metrics |
| 86 | +4. **Detailed results**: Full wrk output for all gateways |
| 87 | + |
| 88 | +## Key Metrics |
| 89 | + |
| 90 | +- **Requests/sec**: Throughput measurement |
| 91 | +- **Latency percentiles**: Average, P99 latency measurements |
| 92 | +- **Error rate**: Socket errors and timeouts (all tests achieve 0% error rate) |
| 93 | +- **Load balancing**: Round-robin distribution verification |
| 94 | +- **Resource usage**: Container-based resource isolation |
| 95 | + |
| 96 | +## Troubleshooting |
| 97 | + |
| 98 | +1. **Services not starting**: Check Docker logs for each service |
| 99 | + |
| 100 | + ```bash |
| 101 | + docker-compose logs bungate nginx envoy |
| 102 | + ``` |
| 103 | + |
| 104 | +2. **Benchmark failures**: Ensure all services are healthy before testing |
| 105 | + |
| 106 | + ```bash |
| 107 | + docker-compose ps |
| 108 | + curl http://localhost:3000 # Test BunGate |
| 109 | + curl http://localhost:3001 # Test Nginx |
| 110 | + curl http://localhost:3002 # Test Envoy |
| 111 | + ``` |
| 112 | + |
| 113 | +3. **Low performance**: Verify system resources and Docker limits |
| 114 | +4. **Network issues**: Check Docker networking configuration |
| 115 | + |
| 116 | +## Advanced Usage |
| 117 | + |
| 118 | +### Manual Testing |
| 119 | + |
| 120 | +You can manually test each gateway: |
| 121 | + |
| 122 | +```bash |
| 123 | +# Test BunGate |
| 124 | +docker-compose exec wrk wrk -t4 -c100 -d30s --latency http://bungate:3000 |
| 125 | + |
| 126 | +# Test Nginx |
| 127 | +docker-compose exec wrk wrk -t4 -c100 -d30s --latency http://nginx:80 |
| 128 | + |
| 129 | +# Test Envoy |
| 130 | +docker-compose exec wrk wrk -t4 -c100 -d30s --latency http://envoy:8080 |
| 131 | +``` |
| 132 | + |
| 133 | +### Load Balancing Verification |
| 134 | + |
| 135 | +```bash |
| 136 | +# Test round-robin distribution |
| 137 | +docker-compose exec wrk curl -s http://bungate:3000 |
| 138 | +docker-compose exec wrk curl -s http://nginx:80 |
| 139 | +docker-compose exec wrk curl -s http://envoy:8080 |
| 140 | +``` |
| 141 | + |
| 142 | +### Generate New Report |
| 143 | + |
| 144 | +```bash |
| 145 | +# Generate a fresh comprehensive report |
| 146 | +docker-compose exec wrk /scripts/wrk_report.sh |
| 147 | +``` |
| 148 | + |
| 149 | +## License |
| 150 | + |
| 151 | +This benchmark suite is part of the BunGate project and follows the same MIT license. |
0 commit comments