✅ 支持GET/POST方法
✅ 动态模板变量({{.Random}}和{{.Number}})
✅ 智能连接池管理
✅ 实时统计QPS和延迟
✅ 并发控制(最高支持10万并发)
✅ 自动内存复用机制
go build -o httpload
./httpload \ -u "http://example.com/?q={{.Random | urlquery}}" \ # 必填URL(支持模板) -m GET \ # 请求方法 [GET|POST] (默认GET) -c 1000 \ # 并发数 (默认100) -t 60s \ # 测试时长 (默认30s) -d "data={{.Number}}" \ # POST数据模板 -content-type "application/json" # Content-Type头 -H "Authorization:Bearer token,X-Custom-Header:value"
./httpload -u "http://api.example.com/search?q={{.Random}}" -c 500 -t 5m
./httpload -m POST \ -u "https://api.example.com/users" \ -d '{"name":"{{.Random}}", "age":{{.Number}}}' \ -content-type "application/json" \ -c 2000 \ -t 300s
./httpload -m POST \ -u "http://login.example.com" \ -d "username={{.Random}}&password={{.Number}}" \ -content-type "application/x-www-form-urlencoded" \ -c 1000
| 变量名 | 类型 | 示例值 | 说明 |
|---|---|---|---|
{{.Random}} | string | "aB3x9mNkL8h2" | 12位随机字母数字组合(大小写敏感) |
{{.Number}} | int | 834692 | 0-999999之间的随机整数 |
export GODEBUG=http2debug=1 # 启用HTTP/2 ulimit -n 100000 # 提升文件描述符限制
./httpload -c 5000 -t 300s ...
watch -n 1 "netstat -ant | grep ESTABLISHED | wc -l" # 查看连接数 nload -u M
Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }
测试实际持续时间 = min(指定时长, 请求处理时间)。强制停止用Ctrl+C
检查服务端日志确认请求到达
使用-c逐步增加并发数(建议以100为单位递增)
运行top监控CPU和内存使用
修改代码第183行fastRandomString(rng, 12)中的数字
统计误差 < 0.1%,因以下情况可能丢失计数:
DNS解析失败
TLS握手超时
客户端缓冲区溢出
建议测试时间至少30秒以获得稳定结果