http 压测一般用 wrk
https://github.com/wg/wrk
wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html
grpc压测用 ghz
wrk搭配lua脚本,个性化压测
https://github.com/wg/wrk/tree/master/scripts
对于一些动态构建的请求,比如:认证、校验、MD加密、http请求参数化, ab、http_load、siege都不能满足需求,倒是jmeter、wrk可以。 更多的lua示例可以参照github wrk请求压测,调用lua分下面3个阶段:setup、running、done
wrk的全局属性, 可以直接拿到lua中使用的
wrk = {
scheme = “http”,
host = “localhost”,
port = nil,
method = “GET”,
path = “/”,
headers = {},
body = nil,
thread =
}
wrk的全局方法, 可以直接拿到lua中使用的
– 生成整个request的string,例如:返回
– GET / HTTP/1.1
– Host: tool.lu
function wrk.format(method, path, headers, body)
– 获取域名的IP和端口,返回table,例如:返回 {127.0.0.1:80}
function wrk.lookup(host, service)
– 判断addr是否能连接,例如:127.0.0.1:80
,返回 true 或 false
function wrk.connect(addr)
Setup阶段 setup是在线程创建之后,启动之前。
function setup(thread)
– thread提供了1个属性,3个方法
– thread.addr 设置请求需要打到的ip
– thread:get(name) 获取线程全局变量
– thread:set(name, value) 设置线程全局变量
– thread:stop() 终止线程
Running阶段
function init(args)
– 每个线程仅调用1次,args 用于获取命令行中传入的参数, 例如 –env=pre
function delay()
– 每个线程调用多次,发送下一个请求之前的延迟, 单位为ms
function request()
– 每个线程调用多次,返回http请求
function response(status, headers, body)
– 每个线程调用多次,返回http响应
Done阶段
可以用于自定义结果报表,整个过程中只执行一次
function done(summary, latency, requests)
latency.min – minimum value seen
latency.max – maximum value seen
latency.mean – average value seen
latency.stdev – standard deviation
latency:percentile(99.0) – 99th percentile value
latency(i) – raw value and count
summary = {
duration = N, – run duration in microseconds
requests = N, – total completed requests
bytes = N, – total bytes received
errors = {
connect = N, – total socket connection errors
read = N, – total socket read errors
write = N, – total socket write errors
status = N, – total HTTP status codes > 399
timeout = N – total request timeouts
}
}
wrk -t400 -c400 -d60s -s wrk.lua http://127.0.0.1:8080
https://q474818917.github.io/2017/05/17/wrk-benchmark/#wrk
http://xiaorui.cc/archives/5098
https://www.liwenzhou.com/posts/Go/benchmark_tool/
https://github.com/link1st/go-stress-testing
https://github.com/bojand/ghz
./ghz –skipTLS –insecure –protoset ./bundle.protoset
-B ./grpc_payload –call tensorflow.serving.PredictionService/Predict \
127.0.0.1:8500
参数的含义
–skipTLS –insecure 我的服务端不支持 tls 验证,所以需要跳过 tls 验证,如果你需要可以开
–protoset ./bundle.protoset 指定刚才用 protoc 生成出来的 protoset 文件
-B ./grpc_payload 这个 grpc_payload 是我在自己 grpc 客户端里 Marshal 出来的祖传二进制,就是前面说用 h2load 失败的那个,废物利用了一下,如果你参数比较简单,可以用-D传个 json 文件进去让它自己转成 pb
–call tensorflow.serving.PredictionService/Predict调用的方法名,改成你自己的方法名
127.0.0.1:8500目标 gRPC 服务的 ip 和端口
https://ghz.sh/docs/examples
https://github.com/bojand/ghz
https://farer.org/2020/02/20/grpc-load-testing-with-ghz/
https://www.cnblogs.com/ExMan/p/13892450.html
https://www.lijiaocn.com/categories/%E6%96%B9%E6%B3%95.html
https://github.com/scguoi/grpctesting
https://ghz.sh/
https://www.icode9.com/content-4-739742.html
https://segmentfault.com/a/1190000020211494