使用wrk压测es
作者:互联网
wrk算是一款很小巧但强大的压测工具,最近在看es的负载问题,便想到用wrk压测下es看看它的性能容量如何。
直接上代码:
wrk -t 25 -c25 -d 60s --latency "http://172.30.1.98:9200/index-sevice-1/_search" --script=query.lua wrk -t 25 -c25 -d 60s --latency "http://172.30.1.98:9200/index-sevice-1/_search" --script=query.offset.2000.lua
# cat query.lua 文件内容如下:
wrk.method = "POST" wrk.body='{ "from": 0, "size": 20, "query": { "bool": { "must": [ { "bool": { "must": { "term": { "is_deleted": 0 } } } }, { "bool": { "should": [ { "term": { "status": 0 } }, { "bool": { "must": [ { "term": { "status": 1 } }, { "range": { "created_at": { "from": null, "to": 1622008118, "include_lower": true, "include_upper": true } } } ] } } ] } } ] } }, "sort": [ { "published_at": { "order": "desc" } } ] }' wrk.headers["Content-Type"] ="application/json"
# cat query.offset.2000.lua 文件内容如下:
wrk.method = "POST" wrk.body='{ "from": 2000, "size": 20, "query": { "bool": { "must": [ { "bool": { "must": { "term": { "is_deleted": 0 } } } }, { "bool": { "should": [ { "term": { "status": 0 } }, { "bool": { "must": [ { "term": { "status": 1 } }, { "range": { "created_at": { "from": null, "to": 1622008118, "include_lower": true, "include_upper": true } } } ] } } ] } } ] } }, "sort": [ { "published_at": { "order": "desc" } } ] }' wrk.headers["Content-Type"] ="application/json"
压测结果如下:
# wrk -t 10 -c10 -d 60s --latency "http://172.30.1.98:9200/index-sevice-1/_search" --script=query.offset.2000.lua Running 60s test @ http://172.30.1.98:9200/index-sevice-1/_search 10 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 774.22ms 49.87ms 887.70ms 76.67% Req/Sec 1.00 0.00 1.00 100.00% Latency Distribution 50% 756.16ms 75% 786.47ms 90% 874.86ms 99% 882.95ms 120 requests in 10.01s, 1.79MB read Requests/sec: 11.99 Transfer/sec: 183.22KB # wrk -t 10 -c10 -d 60s --latency "http://172.30.1.98:9200/index-sevice-1/_search" --script=query.lua Running 60s test @ http://172.30.1.98:9200/index-sevice-1/_search 10 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 341.71ms 12.77ms 379.69ms 67.93% Req/Sec 2.55 0.50 3.00 55.17% Latency Distribution 50% 339.29ms 75% 347.50ms 90% 359.81ms 99% 376.65ms 290 requests in 10.02s, 4.33MB read Requests/sec: 28.95 Transfer/sec: 442.19KB
我这里只是个演示,用的es的配置比较低,压测的时间也比较短,但是也能反映出不同query的性能差异了。 可以看出, ES在offset 深分页的场景下, 性能是不太给力的,尽量避免这种用法。
TIPS:
如果es是开启了密码认证,wrk的压测命令需要加个-H参数,类似:
wrk -t 2 -c2 -d 5s -H "Authorization:Basic ZWxhc3RpYzplbGFzdGljCg==" --latency "http://1.2.3.4/index-service-1/_search" --script=query.lua
其中-H的内容是base64加密后的用户名密码,例如我这里就是 echo 'elastic:elastic'|base64 的结果填到上面的-H 的内容部分。
wrk或者es querydsl 这里就不过多介绍了,大家感兴趣的,可以去官方网站查阅文档。
标签:index,压测,wrk,--,bool,ms,query,es 来源: https://blog.51cto.com/lee90/2821281