English | 中文
This project provides a simple performance test suite to compare popular Go web frameworks:
- Hertz (High-performance HTTP framework by CloudWeGo)
- Gin (Popular lightweight HTTP framework)
- Go-Zero (Microservice framework)
- Kratos (Microservice framework by Bilibili)
- net/http (Go standard library)
This project was generated using Cursor Testing tools used:
- Deploy to docker and run tests
docker compose up -d - Export results to local
docker cp go-http-benchmark-benchmark-1:/app/benchmark_results/summary_20250419_022006.md .
- Cursor Rules settings are attached at the end.
- During project generation, input the following prompt:
Create a performance test plan for Hertz, Gin, Go-zero, Kratos and net/http frameworks
- Output the following content:
I'll create a complete Go project to test the performance of Hertz, Gin, Go-zero, Kratos and standard net/http. This project will fairly compare the performance of these frameworks in different scenarios. First create project structure: ... (remaining content follows same pattern of translation)
This benchmark covers the following scenarios:
- Simple Response (
/hello): Returns simple Hello World response - JSON Response (
/json): Returns JSON formatted data list - Path Parameter (
/params/:id): Processes and returns URL path parameter - Query Parameter (
/query?name=xxx): Processes and returns URL query parameter - POST Request (
/post): Processes JSON formatted POST request body
.
├── cmd
│ ├── benchmark/ # Benchmark execution tool
│ └── server/ # Framework server implementations
│ ├── gin/
│ ├── gozero/
│ ├── hertz/
│ ├── kratos/
│ └── nethttp/
├── docker/ # Docker config files
├── internal/
│ └── benchmark/ # Benchmark tools and shared code
├── docker-compose.yml # Docker Compose config
├── go.mod # Go module definition
└── README.md # Project description
└── README_CN.md # Project description
- Go 1.20 or higher
- Docker and Docker Compose (optional, for containerized testing)
- hey or wrk (HTTP benchmarking tools)
# Install hey tool
go install github.com/rakyll/hey@latest
# Or install wrk (Linux/Mac)
# Ubuntu/Debian
apt-get install wrk
# Mac
brew install wrk- Start servers for each framework (run each in a separate terminal):
# Start standard HTTP service
go run cmd/server/nethttp/main.go
# Start Gin service
go run cmd/server/gin/main.go
# Start Hertz service
go run cmd/server/hertz/main.go
# Start Go-Zero service
go run cmd/server/gozero/main.go
# Start Kratos service
go run cmd/server/kratos/main.go- Run benchmark
# Test all frameworks
go run cmd/benchmark/main.go
# Test specific framework
go run cmd/benchmark/main.go -framework gin
# Custom test parameters
go run cmd/benchmark/main.go -framework hertz -n 10000 -c 200 -d 30s -tool wrk# Build and start all services
docker-compose up -d
# Run benchmarks
docker-compose run benchmark
The benchmark tool supports these parameters:
framework: Framework to test (nethttp, gin, hertz, gozero, kratos, all)n: Total requestsc: Concurrent connectionsd: Test duration (e.g. "10s", "1m")tool: Benchmark tool (hey, wrk)format: Report format (json, csv)
After testing, performance comparisons across frameworks will be displayed. Compare:
- Requests per second (RPS)
- Average response time
- P99 response time (99% of requests respond within this time)
- Error rate and failed requests
You can extend tests by:
- Adding new scenarios in internal/benchmark/scenario.go
- Implementing corresponding route handlers in each framework
- Adj3sting test parameters and analysis methods as needed
- For fair comparison, all frameworks are configured with minimal middleware usage, disabling default logging and error handling middleware
- Benchmark results may be affected by hardware, network and system load
- In production environments, framework selection should also consider features, ecosystem and maintenance factors