Skip to content

faizan2786/hit

Repository files navigation

hit - HTTP Server Benchmarking Tool

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.

Features

  • 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.

Usage

go run cmd/hit/main.go [options] url

Options

  • -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:8082

Project Structure

Package hit

The 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).

CLI cmd/hit

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.

Test Server cmd/test-server

A simple HTTP server helper for testing the hit tool locally.

  • main.go: Starts a basic HTTP server on port :8082 that responds with "hello world".

Usage:

  1. Start the test server in one terminal:

    go run ./cmd/test-server/main.go
  2. Run hit against it in another terminal:

    go run ./cmd/hit/main.go -n 5000 -c 5 http://localhost:8082

About

An HTTP server benchmarking tool written in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages