Scripts2026年4月26日·1 分钟阅读

hey — HTTP Load Generator for Benchmarking Web Servers

Lightweight HTTP load generator written in Go, designed as a modern replacement for ApacheBench with better concurrency handling.

Introduction

hey is a tiny HTTP load generator written in Go that sends a configurable number of requests to a target URL and reports latency histograms, status code distribution, and throughput. It was created as a modern, cross-platform replacement for ApacheBench (ab) that handles HTTP/1.1 keep-alive, concurrent workers, and custom payloads. A single binary with zero dependencies makes it easy to drop into any CI pipeline or developer workstation.

What hey Does

  • Sends a fixed number of HTTP requests with configurable concurrency
  • Reports detailed latency percentiles (p10 through p99) and averages
  • Supports custom HTTP methods, headers, request bodies, and basic auth
  • Distributes requests across a pool of concurrent Go goroutines
  • Outputs results as a latency histogram, status code summary, and throughput number

Architecture Overview

hey uses Go's goroutine-based concurrency to maintain a pool of workers that share a channel of work items. Each worker opens a persistent HTTP connection and fires requests sequentially, while the coordinator counts completions and collects timing data. After all requests finish, hey aggregates latency samples into percentile buckets and prints a summary. The entire tool compiles to a single static binary with no runtime dependencies.

Self-Hosting & Configuration

  • Install with go install github.com/rakyll/hey@latest or download a prebuilt binary from GitHub Releases
  • On macOS also available via brew install hey
  • Use -n for total requests and -c for concurrency level
  • Set -q to cap requests per second (rate limiting)
  • Pipe output to a file or parse the text summary in CI scripts

Key Features

  • Single static binary — no runtime, no config files, no dependencies
  • Accurate latency histograms with ten percentile buckets
  • HTTP/1.1 keep-alive and connection reuse by default
  • Rate limiting via -q to simulate steady-state traffic patterns
  • Cross-platform: runs on Linux, macOS, and Windows without changes

Comparison with Similar Tools

  • wrk — higher raw throughput via C and epoll, but requires Unix and Lua for customization
  • ApacheBench (ab) — classic but single-threaded, no keep-alive by default, limited output
  • oha — Rust-based with a real-time TUI dashboard; hey is simpler and text-only
  • bombardier — similar Go tool with a progress bar; hey predates it and has wider adoption
  • Vegeta — constant-rate attack model with reporting; hey uses a fixed-request-count model

FAQ

Q: How do I limit the request rate with hey? A: Use -q 100 to cap throughput at 100 requests per second per worker. Total rate equals -q multiplied by -c.

Q: Does hey support HTTP/2? A: Yes. Pass -h2 to enable HTTP/2 connections to servers that support it.

Q: Can I use hey in a CI pipeline? A: Yes. Run hey with fixed -n and -c values and check the exit code or parse stdout for pass/fail thresholds.

Q: What is the difference between hey and ab? A: hey supports keep-alive by default, handles concurrent connections via goroutines, and provides richer latency percentile output than ab.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产