graphql-mesh 压测分析
作者:互联网
mesh 简介
如官方介绍,mesh是一个强大的数据源聚合工具,可以方便的聚合graphql 接口和非graphql接口
背景
团队使用graphql-mesh聚合后端接口和数据,之前一直处于内测,流量不大,现在计划引流,流量会爆发式增长,所以需要测试服务的承压能力,作为关键节点的mesh自然需要压测,以下是针对mesh的压测分析
环境
- windows10
- Docker version 20.10.6, build 370c289
- node 14
- graphql-mesh master/0.2.15
- easy-monitor v2
压测
环境参数:cpus 1 ,mem 512M
mesh 聚合方式:federation
Service list
- accounts http://localhost:9871/graphql
- reviews http://localhost:9872/graphql
- products http://localhost:9873/graphql
- inventory http://localhost:9874/graphql
压测参数
`ab -n 1000000 -c 100 -p ./body.json "http://localhost:8888/graphql"`
`ab -n 1000000 -c 300 -p ./body.json "http://localhost:8888/graphql"`
`ab -n 1000000 -c 500 -p ./body.json "http://localhost:8888/graphql"`
`ab -n 1000000 -c 1000 -p ./body.json "http://localhost:8888/graphql"`
Query
{
"query": "query TestQuery {\n users {\n id\n username\n name\n reviews {\n id\n body\n product {\n inStock\n name\n price\n shippingEstimate\n upc\n weight\n }\n }\n }\n topProducts {\n inStock\n name\n price\n shippingEstimate\n upc\n weight\n reviews {\n id\n body\n author {\n id\n username\n name\n }\n }\n }\n}\n",
"variables": {}
}
响应结果
请求总数 1000000
并发10
所有请求全部正常响应
50% 的请求 6 ms以内响应
99%的请求 71 ms以内响应
100%请求 275 ms以内响应
总耗时:1171.386 s
Server Software:
Server Hostname: localhost
Server Port: 8888
Document Path: /graphql
Document Length: 392 bytes
Concurrency Level: 10
Time taken for tests: 1171.386 seconds
Complete requests: 1000000
Failed requests: 0
Non-2xx responses: 1000000
Total transferred: 610000000 bytes
Total body sent: 631000000
HTML transferred: 392000000 bytes
Requests per second: 853.69 [#/sec] (mean)
Time per request: 11.714 [ms] (mean)
Time per request: 1.171 [ms] (mean, across all concurrent requests)
Transfer rate: 508.55 [Kbytes/sec] received
526.05 kb/s sent
1034.60 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 1 12 15.5 6 275
Waiting: 1 10 14.3 5 275
Total: 1 12 15.5 6 275
Percentage of the requests served within a certain time (ms)
50% 6
66% 6
75% 7
80% 7
90% 47
95% 50
98% 59
99% 71
100% 275 (longest request)
请求总数 1000000
并发100
所有请求全部正常响应
50% 的请求 100 ms以内响应
99%的请求 186 ms以内响应
100%请求 350 ms以内响应
总耗时:1093.896
s
Server Software:
Server Hostname: localhost
Server Port: 8888
Document Path: /graphql
Document Length: 392 bytes
Concurrency Level: 100
Time taken for tests: 1093.896 seconds
Complete requests: 1000000
Failed requests: 0
Non-2xx responses: 1000000
Total transferred: 610000000 bytes
Total body sent: 631000000
HTML transferred: 392000000 bytes
Requests per second: 914.16 [#/sec] (mean)
Time per request: 109.390 [ms] (mean)
Time per request: 1.094 [ms] (mean, across all concurrent requests)
Transfer rate: 544.57 [Kbytes/sec] received
563.32 kb/s sent
1107.89 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 7
Processing: 4 109 26.7 99 350
Waiting: 2 85 31.5 90 302
Total: 4 109 26.7 100 350
Percentage of the requests served within a certain time (ms)
50% 100
66% 103
75% 107
80% 112
90% 157
95% 177
98% 183
99% 186
100% 350 (longest request)
请求总数 1000000
并发300
所有请求全部正常响应
50% 的请求 312 ms以内响应
99%的请求 413 ms以内响应
100%请求 589 ms以内响应
总耗时:1096.317
s
Server Software:
Server Hostname: localhost
Server Port: 8888
Document Path: /graphql
Document Length: 392 bytes
Concurrency Level: 300
Time taken for tests: 1096.317 seconds
Complete requests: 1000000
Failed requests: 0
Non-2xx responses: 1000000
Total transferred: 610000000 bytes
Total body sent: 631000000
HTML transferred: 392000000 bytes
Requests per second: 912.14 [#/sec] (mean)
Time per request: 328.895 [ms] (mean)
Time per request: 1.096 [ms] (mean, across all concurrent requests)
Transfer rate: 543.37 [Kbytes/sec] received
562.07 kb/s sent
1105.44 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.0 1 15
Processing: 12 328 39.1 311 586
Waiting: 7 234 74.8 235 574
Total: 12 329 39.1 312 589
Percentage of the requests served within a certain time (ms)
50% 312
66% 336
75% 370
80% 375
90% 384
95% 390
99% 413
100% 589 (longest request)
请求总数 1000000
并发500
所有请求全部正常响应
50% 的请求 544 ms以内响应
99%的请求 656 ms以内响应
100%请求 1158 ms以内响应
总耗时:1095.781 s
Server Software:
Server Hostname: localhost
Server Port: 8888
Document Path: /graphql
Document Length: 392 bytes
Concurrency Level: 500
Time taken for tests: 1095.781 seconds
Complete requests: 1000000
Failed requests: 0
Non-2xx responses: 1000000
Total transferred: 610000000 bytes
Total body sent: 631000000
HTML transferred: 392000000 bytes
Requests per second: 912.59 [#/sec] (mean)
Time per request: 547.891 [ms] (mean)
Time per request: 1.096 [ms] (mean, across all concurrent requests)
Transfer rate: 543.63 [Kbytes/sec] received
562.35 kb/s sent
1105.98 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
98% 399
Connect: 0 2 1.6 1 15
Processing: 13 546 46.1 542 1158
Waiting: 5 392 117.8 408 813
Total: 13 548 46.1 544 1158
Percentage of the requests served within a certain time (ms)
50% 544
66% 577
75% 583
80% 586
90% 594
95% 601
98% 618
99% 656
100% 1158 (longest request)
请求总数 1000000
并发1000
所有请求全部正常响应
50% 的请求 1096 ms以内响应
99%的请求 1288 ms以内响应
100%请求 2933 ms以内响应
总耗时:1095.781 s
Server Software:
Server Hostname: localhost
Server Port: 8888
Document Path: /graphql
Document Length: 392 bytes
Concurrency Level: 1000
Time taken for tests: 1101.761 seconds
Complete requests: 1000000
Failed requests: 0
Non-2xx responses: 1000000
Total transferred: 610000000 bytes
Total body sent: 631000000
HTML transferred: 392000000 bytes
Requests per second: 907.64 [#/sec] (mean)
Time per request: 1101.761 [ms] (mean)
Time per request: 1.102 [ms] (mean, across all concurrent requests)
Transfer rate: 540.68 [Kbytes/sec] received
559.30 kb/s sent
1099.98 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 2.1 2 19
Processing: 24 1099 113.0 1094 2925
Waiting: 5 864 159.9 877 2099
Total: 24 1101 113.0 1096 2933
Percentage of the requests served within a certain time (ms)
50% 1096
66% 1110
75% 1123
80% 1137
90% 1180
95% 1198
98% 1260
99% 1288
100% 2933 (longest request)
Mesh 监控分析
Cpu 耗时占比
并发数 | gc | idle | program | Validate and execute the query | pubSubHandler | parserOnHeadersComplete | onconnection | processTicksAndRejections |
10 | 12% | 5.4% | 3.8% | 36.7% | 7.7% | 15.6% | 3.5% | 11.4% |
100 | 13.3% | 4.9% | 3.3% | 37.1% | 7.8% | 15.8% | 2.2% | 11.6% |
300 | 13.3% | 5.0% | 3.3% | 37.2% | 7.6% | 15.7% | 2.1% | 11.6% |
500 | 13.3% | 4.8% | 3.4% | 37% | 7.6% | 15.6% | 2.3% | 11.9% |
1000 | 13.4% | 4.8% | 3.2% | 37.1% | 7.7% | 15.2% | 2.2% | 12% |
2000 | client: Too many open files |
附图
结论
并发数持续增长,单个请求响应时间明显增加,
在一定并发范围内,各阶段消耗的cpu时间,基本维持稳定,graphql parse 和 validate 最耗时,占比37%左右
并发数在1000以内,所有请求成功响应
随着并发数量增加,请求响应时间明显增加,响应超时和失败的风险增加
mesh 便捷强大,可以省去一些聚合工作,但是node出身的他,还是不适合cpu密集型工作(graphql解析,聚合,校验),在高并发量的业务中,mesh不是很适合
参考
标签:请求,压测,1000000,mesh,graphql,ms,requests,mean 来源: https://blog.csdn.net/u014636124/article/details/118603613