HTTP 压测工具:wrk
wrk 是当今最流行的 HTTP 压测工具,用于模拟高并发情况下的 HTTP 请求。wrk 使用 Lua 作为脚本语言,可以通过编写 Lua 脚本来自定义请求的参数和逻辑。只支持linux。wg/wrk: Modern HTTP benchmarking tool
使用示例:
wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html
HTTP 压测工具:ab
ab(Apache Bench)是Apache自带的一个压力、性能测试工具,用于模拟多个并发访问,测试服务器的性能。
使用示例:
ab -n 1000 -c 50 http://127.0.0.1:8080/index.html
gRPC 压测工具:ghz
ghz是一个命令行程序,用于负载测试和gRPC服务的基准测试。Simple gRPC benchmarking and load testing tool
ghz --insecure \
--proto=./proto/greet.proto \
--call unary.Greeter.greet \
-c 50 \
-n 100000 \
-d '{"name":"Joe"}' \
0.0.0.0:3456
HTTP, WebSockets, gRPC 压测工具:k6(重点推荐)
k6支持HTTP, WebSockets, gRPC。k6使用JavaScript作为脚本语言,内置了丰富的功能和模块,能够满足各种复杂的HTTP测试需求。。
创建一个测试脚本hello-world.js:
import http from 'k6/http';
export default function () {
http.get('https://www.baidu.com/');
}
模拟 100 个虚拟用户(VU),连续压测 30 秒:
k6 run --vus 100 --duration 30s hello-world.js
MySQL自带压测工具:MySQL-SLAP
MySQL 自带的测试工具,用于生成 SQL 负载并测量性能。下面的测试50并发、一共执行10000 次请求、重复10次:
$ mysqlslap --concurrency=50 --number-of-queries=10000 --iterations=10 --query="SELECT * FROM your_table" --create-schema=your_db --user=root --password=yourpassword
Benchmark
Average number of seconds to run all queries: 0.045 seconds # 重复10次测试的平均
Minimum number of seconds to run all queries: 0.030 seconds
Maximum number of seconds to run all queries: 0.060 seconds
Number of clients running queries: 50