http_load 為輕量級 HTTP 壓測工具,支援並發進程數與請求率兩種壓力模式,輸出 QPS、延遲、傳輸量等關鍵指標。同類工具還有 ab、wrk、Siege。
cd /root
wget https://acme.com/software/http_load/http_load-12mar2006.tar.gz
tar xzf http_load-12mar2006.tar.gz
cd http_load-12mar2006
make
# 產生 http_load 二進制檔
# 編輯 Makefile,取消註解以下區塊
SSL_TREE = /usr
SSL_DEFS = -DUSE_SSL
SSL_INC = -I$(SSL_TREE)/include
SSL_LIBS = -L$(SSL_TREE)/lib -lssl -lcrypto
# 安裝 OpenSSL 開發套件
apt-get install libssl-dev # Debian/Ubuntu
yum install openssl-devel # CentOS/RHEL
# 重新編譯
make clean && make
| 參數 | 縮寫 | 說明 |
|---|---|---|
-parallel N | -p N | 並發進程數(同時連線數) |
-rate N | -r N | 每秒請求率(吞吐量控制) |
-fetches N | -f N | 總請求次數(達到即停止) |
-seconds N | -s N | 總測試時間(秒) |
-timeout N | 單次請求超時秒數 | |
-proxy host:port | 透過代理發送請求 |
互斥規則:-parallel 與 -rate 二擇一;-fetches 與 -seconds 二擇一。
# 建立 URL 清單
cat > urls.txt <<'EOF'
https://example.com/
https://example.com/api/health
https://example.com/static/style.css
EOF
# 範例 1:50 並發持續 10 秒
http_load -parallel 50 -seconds 10 urls.txt
# 範例 2:每秒 50 請求,共 5000 次
http_load -rate 50 -fetches 5000 urls.txt
49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
5916 mean bytes/connection
4.89274 fetches/sec, 28945.5 bytes/sec
msecs/connect: 28.8932 mean, 44.243 max, 24.488 min
msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min
HTTP response codes: code 200 -- 49
top/vmstat/sar 觀察 CPU、記憶體、I/O。