项目大概是 WebFlux 通过 WebClient 转发http请求 中间进行逻辑处理
验收需要提供性能测试报告
使用 wrk 进行测试
目标接口原始性能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # wrk -c600 -t4 -T10 -d180 --latency http://192.168.101.164:8086 Running 3m test @ http://192.168.101.164:8086 4 threads and 600 connections Thread Stats Avg Stdev Max +/- Stdev Latency 46.19ms 46.03ms 794.41ms 92.85% Req/Sec 3.85k 771.54 7.05k 85.61% Latency Distribution 50% 35.74ms 75% 40.53ms 90% 78.09ms 99% 255.88ms 2756389 requests in 3.00m, 473.17MB read Socket errors: connect 0, read 0, write 440, timeout 0 Requests/sec: 15306.22 Transfer/sec: 2.63MB
|
Nginx转发性能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # wrk -c600 -t4 -T10 -d180 --latency http://192.168.101.233:901 Running 3m test @ http://192.168.101.233:901 4 threads and 600 connections Thread Stats Avg Stdev Max +/- Stdev Latency 524.59ms 1.04s 9.54s 93.65% Req/Sec 474.22 135.68 1.38k 74.30% Latency Distribution 50% 250.51ms 75% 312.01ms 90% 590.12ms 99% 6.14s 338358 requests in 3.00m, 90.03MB read Socket errors: connect 0, read 9830, write 2898, timeout 0 Requests/sec: 1879.47 Transfer/sec: 512.08KB
|
WebClient性能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # wrk -c600 -t4 -T10 -d180 --latency http://192.168.101.233:9195/gateway/sys/api Running 3m test @ http://192.168.101.233:9195/gateway/sys/api 4 threads and 600 connections Thread Stats Avg Stdev Max +/- Stdev Latency 3.17s 3.10s 9.84s 76.92% Req/Sec 473.03 366.87 1.79k 55.65% Latency Distribution 50% 2.32s 75% 5.89s 90% 7.60s 99% 9.78s 35926 requests in 3.00m, 8.81MB read Socket errors: connect 0, read 0, write 2669, timeout 712 Requests/sec: 199.51 Transfer/sec: 50.07KB
|
网络环境和电脑状态一直有变化 所以每次测试都有上下浮动 但是差距不会到10倍 电脑Cpu也没打满
并且项目开始是按 ShenYu 为参考 技术架构也相同 性能理应相同
但实际 WebClient 转发延迟一直在秒级 性能差到两个数量级了 看日志基本都停留在等待请求结果上
给我整不会了 开始查资料优化 WebClient 线程池什么都用上了 netty 的 ioWorkerCount 也设置了
都没有效果 又以为是Windows有什么Tcp连接数什么的问题 但是nginx性能又正常
在Linux上重新部署了一套 情况依旧
对比 Apache ShenYu 的源码一行一行比较 转发逻辑应该是相同的
ShenYu 600并发性能为
currency |
QPS |
50% latency (ms) |
75% latency (ms) |
90% latency (ms) |
99% latency (ms) |
平均响应时间(ms) |
最大响应时间(ms) |
600 并发 |
18640.47 |
15.77 |
24.77 |
38.26 |
80.31 |
20.32 |
852.06 |
差距过大
并且我的Mock接口报文只是把请求来源的header ip之类的返回出来的测试接口 理论上来说应该 延迟会更低
但是 QPS比 ShenYu 好 延迟却高了太多
修改了两天延迟还是降不下来
反复观看ShenYu的基准测试报告时发现
有这么一条 日志级别为WARN
那不就是不打日志 马上修改日志配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # wrk -c600 -t4 -T10 -d180 --latency http://192.168.101.233:9195/gateway/sys/api Running 3m test @ http://192.168.101.233:9195/gateway/sys/api 4 threads and 600 connections Thread Stats Avg Stdev Max +/- Stdev Latency 85.97ms 35.67ms 662.17ms 89.15% Req/Sec 1.79k 538.31 3.60k 70.62% Latency Distribution 50% 74.64ms 75% 89.36ms 90% 123.86ms 99% 231.92ms 1276703 requests in 3.00m, 312.91MB read Socket errors: connect 0, read 0, write 2142, timeout 0 Requests/sec: 7089.33 Transfer/sec: 1.74MB
|
性能立刻翻了两个数量级 延迟也正常了
测试环境性能波动很大 一会性能会超过Nginx 一会又低 主要是 mock的项目放同事电脑上了 看了大概就行