hit is a concurrent HTTP server benchmarking tool written in Go. It allows you to load test web servers by sending a specified number of requests with configurable concurrency and rate limiting.
The project is inspired by the book Go by Example by Inac Gumus.
- Concurrency: Send multiple requests in parallel.
- Rate Limiting: Control the number of requests per second (RPS).
- Detailed Summary: Provides statistics on success rate, throughput (RPS), and latency (min, max, average).
- Graceful Shutdown: Handles interruption signals to stop cleanly.
go run cmd/hit/main.go [options] url-n: Number of requests to send (default: 1000).-c: Concurrency level (number of concurrent workers) (default: 1).-rps: Requests per second limit (default: 0, no limit).
Example:
Send 1000 requests to http://localhost:8082 with 10 concurrent workers:
go run cmd/hit/main.go -n 1000 -c 10 http://localhost:8082The core library containing the server benchmarking logic.
hit.go: Contains the primary entry points Send (single request) and SendN (multiple requests). SendN orchestrates the execution flow using the pipeline.
options.go: Defines the Options struct for configuration (concurrency, RPS, timeout) and handles default values and validation.
pipeline.go: Implements the concurrent processing pipeline. It uses a Producer -> Throttler -> Dispatcher pattern to manage request generation, rate limiting, and concurrent execution.
result.go: Defines data structures for capturing metrics (Result) and aggregating them into a Summary (total requests, success rate, latency stats).
The command-line interface for the tool.
main.go: Handles command-line argument parsing, validation, signal handling (SIGINT), and printing the benchmark summary to the console.
A simple HTTP server helper for testing the hit tool locally.
main.go: Starts a basic HTTP server on port:8082that responds with "hello world".
-
Start the test server in one terminal:
go run ./cmd/test-server/main.go
-
Run
hitagainst it in another terminal:go run ./cmd/hit/main.go -n 5000 -c 5 http://localhost:8082