之前学习soul代理http服务的时候,没有对http服务被代理前后进行对比,本文对此进行补充,使用sb工具进行压测,步骤如下。
- 分别启动admin, bootstrap, http example。
- http无代理情况压测:
$ sb -u http://127.0.0.1:8188/test/findByUserId?userId=1 -c 10 -N 20
Starting at 2021/2/6 0:58:58
[Press C to stop the test]
85564 (RPS: 3483.9)
---------------Finished!----------------
Finished at 2021/2/6 0:59:22 (took 00:00:24.6934123)
Status 200: 85567
RPS: 4058.5 (requests/second)
Max: 70ms
Min: 0ms
Avg: 0.5ms
50% below 0ms
60% below 0ms
70% below 1ms
80% below 1ms
90% below 1ms
95% below 2ms
98% below 3ms
99% below 4ms
99.9% below 9ms
- 网关代理http情况
$ sb -u http://127.0.0.1:9195/http/test/findByUserId?userId=1 -c 10 -N 20
Starting at 2021/2/6 1:01:50
[Press C to stop the test]
20 (RPS: 0.8)
---------------Finished!----------------
Finished at 2021/2/6 1:02:15 (took 00:00:25.0604334)
21 (RPS: 0.8) Status 200: 21
RPS: 1 (requests/second)
Max: 17235ms
Min: 1055ms
Avg: 7042.5ms
50% below 6143ms
60% below 7096ms
70% below 9135ms
80% below 10148ms
90% below 12742ms
95% below 15217ms
98% below 17235ms
99% below 17235ms
99.9% below 17235ms
29 (RPS: 1.2)
结论
结果令人有点吃惊,有无代理性能差异巨大,网关代理后多的性能消耗考虑可能是以下一些方面:
- http请求到网关后,会经过一些列插件处理,中间消耗一点时间;
- http请求从网关转发到http服务,中间又经过一次网络转发;
- http服务响应返回网关后,还有一些处理。
上述几个方面具体影响程度还可以进一步分析,不过起码从性能对比分析可以得出一个初步的结论,如果不是确实需要(比如分布式服务场景),不应该为了引入网关而使用网关,因为网关对性能的消耗还是比较明显的。