Istio 是服务网格众多方案中最流行、最具代表性的,或者说是当前事实上的标准。Mesh 通过网络代理的方式,将网络流量做代理转发,结合控制面实现流量调度、可观测性以及安全的统一管控。
Mesh 为微服务架构提供了全新的解决方案,也被称为微服务的 2.0 时代,那么相对于 1.0 时代以 Spring Cloud 为代表的微服务框架有什么差异?无论新项目架构选型,还是旧项目架构的升级都是需要要回答的问题。从架构设计、功能、性能等方面有很多细节需要对比和权衡,本文主要针对 **Mesh 与微服务框架在 RPC 性能 ** 进行对比。
有关性能在 Istio 官网有详尽的案例和报告可以参考: Istio 1.16 性能总结 ,测试场景中介绍: ”包含了 1000 个服务和 2000 个 sidecar,全网格范围内,QPS 为 70,000“,以这样规模测试后得出的基本结论是比较全面的:
- ① 通过代理的 QPS 有 1000 时,Envoy 使用了 0.5 vCPU 和 50 MB 内存。
- ② 网格总的 QPS 为 1000 时,istio-telemetry服务使用了 0.6 vCPU。
- ③ Pilot 使用了 1 vCPU 和 1.5 GB 内存。
- ④ 90% 的情况 Envoy 代理只增加了 6.3 ms 的延迟。
其中 ④ 是本次对比主要关注的,Mesh 在引入代理后必然增加 RPC 调用的基础延迟,本文不会做 Istio 这样全面的对比,主要结合一个简单的微服务用例,通过接口压测的方式进行更加直观的对比。为了保证基准的一致,选用基于同一框架的三个微服务进行测试,框架同时支持两种架构:
- 
Spring Cloud 模式的服务发现+客户端负载的 RPC 调用 
- 
基于 Istio 代理的 RPC 调用 
- 服务为基于 gRPC 框架和 grpc-gateway 的 Go 服务
- 既支持基于 go-micro 的 Etcd 和 K8S 等注册中心的服务发现,也支持 Istio 模式
- 测试分别使用 K8S 做注册中心和 Istio 做对比
- Istio 服务网格部署示例,只需要 Apply deploy/k8s/istio/*.yaml,其它文件夹不需要
- K8S 注册中心部署示例,Apply deploy/k8s/go-micro/*.yaml
测试场景
- 每个服务两个节点
- Istio 流量入口统一走 Ingress gateway,微服务流量入口通过Nginx Ingress
- 接口调用流程如下图,分别为 Istio 和微服务流程:
压测方式
使用 hey 压测工具模拟接口调用,压测结束后统计接口延迟,测试重点是对比基础延迟,所以不会做大的压力测试,主要关注 P99 P95、P90 、P50的延迟,单次压测时间 60S,QPS 分别为:20(4x5)、60(4x15)、100(4x25)
测试示例数据如下:
hey -z 60s -c 4 -q 5 -host istio.k8s.hbchen.com 'http://172.25.183.53:30127/v1/example/call/hbchen'
Summary:
  Total:        60.0088 secs
  Slowest:      0.1923 secs
  Fastest:      0.0028 secs
  Average:      0.0059 secs
  Requests/sec: 19.9971
  
  Total data:   1158000 bytes
  Size/request: 965 bytes
...
Status code distribution:
  [200] 1200 responses
测试过程
Istio 环境
QPS 20
hey -z 60s -c 4 -q 5 -host istio.k8s.hbchen.com 'http://172.25.183.53:30559/v1/example/call/hbchen'
ummary:
  Total:        60.0152 secs
  Slowest:      0.0594 secs
  Fastest:      0.0076 secs
  Average:      0.0117 secs
  Requests/sec: 19.9949
  
Response time histogram:
  0.008 [1]     |
  0.013 [997]   |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.018 [158]   |■■■■■■
  0.023 [22]    |■
  0.028 [14]    |■
  0.033 [3]     |
  0.039 [1]     |
  0.044 [2]     |
  0.049 [0]     |
  0.054 [0]     |
  0.059 [2]     |
Latency distribution:
  10% in 0.0095 secs
  25% in 0.0102 secs
  50% in 0.0109 secs
  75% in 0.0120 secs
  90% in 0.0143 secs
  95% in 0.0168 secs
  99% in 0.0251 secs
Details (average, fastest, slowest):
  DNS+dialup:   0.0000 secs, 0.0076 secs, 0.0594 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0000 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0002 secs
  resp wait:    0.0116 secs, 0.0074 secs, 0.0578 secs
  resp read:    0.0000 secs, 0.0000 secs, 0.0002 secs
Status code distribution:
  [200] 1200 responses
QPS 60
hey -z 60s -c 4 -q 15 -host istio.k8s.hbchen.com 'http://172.25.183.53:30559/v1/example/call/hbchen'
Summary:
  Total:        60.0171 secs
  Slowest:      0.2395 secs
  Fastest:      0.0069 secs
  Average:      0.0114 secs
  Requests/sec: 59.8496
  
Response time histogram:
  0.007 [1]     |
  0.030 [3576]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.053 [11]    |
  0.077 [0]     |
  0.100 [0]     |
  0.123 [0]     |
  0.146 [0]     |
  0.170 [0]     |
  0.193 [0]     |
  0.216 [0]     |
  0.240 [4]     |
Latency distribution:
  10% in 0.0089 secs
  25% in 0.0096 secs
  50% in 0.0104 secs
  75% in 0.0117 secs
  90% in 0.0143 secs
  95% in 0.0168 secs
  99% in 0.0240 secs
Details (average, fastest, slowest):
  DNS+dialup:   0.0000 secs, 0.0069 secs, 0.2395 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0000 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0002 secs
  resp wait:    0.0113 secs, 0.0068 secs, 0.2394 secs
  resp read:    0.0000 secs, 0.0000 secs, 0.0002 secs
Status code distribution:
  [200] 3592 responses
QPS 100
hey -z 60s -c 4 -q 25 -host istio.k8s.hbchen.com 'http://172.25.183.53:30559/v1/example/call/hbchen'
Summary:
  Total:        60.0152 secs
  Slowest:      0.0871 secs
  Fastest:      0.0064 secs
  Average:      0.0108 secs
  Requests/sec: 99.9414
  
Response time histogram:
  0.006 [1]     |
  0.014 [5492]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.023 [387]   |■■■
  0.031 [82]    |■
  0.039 [22]    |
  0.047 [4]     |
  0.055 [1]     |
  0.063 [3]     |
  0.071 [4]     |
  0.079 [1]     |
  0.087 [1]     |
Latency distribution:
  10% in 0.0084 secs
  25% in 0.0091 secs
  50% in 0.0099 secs
  75% in 0.0110 secs
  90% in 0.0136 secs
  95% in 0.0170 secs
  99% in 0.0262 secs
Details (average, fastest, slowest):
  DNS+dialup:   0.0000 secs, 0.0064 secs, 0.0871 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0000 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0002 secs
  resp wait:    0.0107 secs, 0.0063 secs, 0.0870 secs
  resp read:    0.0000 secs, 0.0000 secs, 0.0002 secs
Status code distribution:
  [200] 5998 responses
微服务框架
QPS 20
hey -z 60s -c 4 -q 5 -host istio.k8s.hbchen.com 'http://172.25.183.53:30127/v1/example/call/hbchen'
Summary:
  Total:        60.0100 secs
  Slowest:      0.2472 secs
  Fastest:      0.0028 secs
  Average:      0.0059 secs
  Requests/sec: 19.9967
  
  Total data:   1158000 bytes
  Size/request: 965 bytes
Response time histogram:
  0.003 [1]     |
  0.027 [1190]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.052 [3]     |
  0.076 [0]     |
  0.101 [3]     |
  0.125 [1]     |
  0.149 [0]     |
  0.174 [0]     |
  0.198 [0]     |
  0.223 [0]     |
  0.247 [2]     |
Latency distribution:
  10% in 0.0035 secs
  25% in 0.0040 secs
  50% in 0.0047 secs
  75% in 0.0055 secs
  90% in 0.0072 secs
  95% in 0.0098 secs
  99% in 0.0164 secs
Details (average, fastest, slowest):
  DNS+dialup:   0.0000 secs, 0.0028 secs, 0.2472 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0000 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0002 secs
  resp wait:    0.0058 secs, 0.0027 secs, 0.2470 secs
  resp read:    0.0000 secs, 0.0000 secs, 0.0001 secs
Status code distribution:
  [200] 1200 responses
QPS 60
hey -z 60s -c 5 -q 15 -host istio.k8s.hbchen.com 'http://172.25.183.53:30127/v1/example/call/hbchen'
Summary:
  Total:        60.0095 secs
  Slowest:      0.3643 secs
  Fastest:      0.0022 secs
  Average:      0.0066 secs
  Requests/sec: 74.2549
  
  Total data:   4300040 bytes
  Size/request: 965 bytes
Response time histogram:
  0.002 [1]     |
  0.038 [4429]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.075 [8]     |
  0.111 [0]     |
  0.147 [1]     |
  0.183 [1]     |
  0.219 [7]     |
  0.256 [2]     |
  0.292 [2]     |
  0.328 [2]     |
  0.364 [3]     |
Latency distribution:
  10% in 0.0035 secs
  25% in 0.0042 secs
  50% in 0.0049 secs
  75% in 0.0059 secs
  90% in 0.0081 secs
  95% in 0.0114 secs
  99% in 0.0242 secs
Details (average, fastest, slowest):
  DNS+dialup:   0.0000 secs, 0.0022 secs, 0.3643 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0000 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0003 secs
  resp wait:    0.0066 secs, 0.0021 secs, 0.3643 secs
  resp read:    0.0000 secs, 0.0000 secs, 0.0002 secs
Status code distribution:
  [200] 4456 responses
QPS 100
hey -z 60s -c 5 -q 25 -host istio.k8s.hbchen.com 'http://172.25.183.53:30127/v1/example/call/hbchen'
Summary:
  Total:        60.0095 secs
  Slowest:      0.3576 secs
  Fastest:      0.0021 secs
  Average:      0.0065 secs
  Requests/sec: 124.1470
  
  Total data:   7189250 bytes
  Size/request: 965 bytes
Response time histogram:
  0.002 [1]     |
  0.038 [7399]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.073 [32]    |
  0.109 [4]     |
  0.144 [4]     |
  0.180 [4]     |
  0.215 [0]     |
  0.251 [3]     |
  0.287 [2]     |
  0.322 [0]     |
  0.358 [1]     |
Latency distribution:
  10% in 0.0034 secs
  25% in 0.0042 secs
  50% in 0.0051 secs
  75% in 0.0062 secs
  90% in 0.0090 secs
  95% in 0.0123 secs
  99% in 0.0259 secs
Details (average, fastest, slowest):
  DNS+dialup:   0.0000 secs, 0.0021 secs, 0.3576 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0000 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0005 secs
  resp wait:    0.0064 secs, 0.0020 secs, 0.3575 secs
  resp read:    0.0000 secs, 0.0000 secs, 0.0002 secs
Status code distribution:
  [200] 7450 responses
测试结果
测试结果数据汇总如下表,可以注意对比 Istio 官方的性能总结报告:90% 的情况 Envoy 代理只增加了 6.3 ms 的延迟 ,结论基本是一致的。
| 测试项目 | P99 (ms) | P95 (ms) | P90 (ms) | P50 (ms) | 
|---|---|---|---|---|
| Istio-QPS-20 | 25.1 | 16.8 | 14.3 | 10.9 | 
| Istio-QPS-60 | 24.0 | 16.8 | 14.3 | 10.4 | 
| Istio-QPS-100 | 26.2 | 17.0 | 13.6 | 11.0 | 
| 微服务框架-QPS-20 | 16.4 | 9.8 | 7.2 | 4.7 | 
| 微服务框架-QPS-60 | 24.2 | 11.4 | 8.1 | 4.9 | 
| 微服务框架-QPS-100 | 25.9 | 12.3 | 9.0 | 5.1 | 
 
      
    




