首页 > 解决方案 > 为什么 istio 的 maxRequestPerConnection 对 http/1.1 请求有影响?

问题描述

我只是在使用 istio 学习服务网格,我发现了一个奇怪的行为。为了理解maxRequestsPerConnectionIstio DestinationRuleCRD,我编写了下面的清单并应用它。

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: httpbin
spec:
  host: httpbin
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 1
      http:
        http1MaxPendingRequests: 1
        maxRequestsPerConnection: 1

然后,我使用 fortio 发送请求。结果如下:

yunoMacBook-Air:labo8 yu$ kubectl exec "$FORTIO_POD" -c fortio -- /usr/bin/fortio load -c 5 -qps 0 -n 1000 -loglevel Error http://httpbin:8000/get
07:12:01 I logger.go:127> Log level is now 4 Error (was 2 Info)
Fortio 1.11.3 running at 0 queries per second, 2->2 procs, for 1000 calls: http://httpbin:8000/get
Aggregated Function Time : count 1000 avg 0.0036879818 +/- 0.004588 min 0.000379697 max 0.034176044 sum 3.68798183
# target 50% 0.00234783
# target 75% 0.0032551
# target 90% 0.008
# target 99% 0.025
# target 99.9% 0.032784
Sockets used: 876 (for perfect keepalive, would be 5)
Jitter: false
Code 200 : 126 (12.6 %)
Code 503 : 874 (87.4 %)
All done 1000 calls (plus 0 warmup) 3.688 ms avg, 1170.1 qps
yunoMacBook-Air:labo8 yu$

之后,我将maxRequestsPerConnection值更改为 10:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: httpbin
spec:
  (...)
        maxRequestsPerConnection: 10

我再次使用相同的设置发送请求。

yunoMacBook-Air:labo8 yu$ kubectl exec "$FORTIO_POD" -c fortio -- /usr/bin/fortio load -c 5 -qps 0 -n 1000 -loglevel Error http://httpbin:8000/get
07:11:07 I logger.go:127> Log level is now 4 Error (was 2 Info)
Fortio 1.11.3 running at 0 queries per second, 2->2 procs, for 1000 calls: http://httpbin:8000/get
Aggregated Function Time : count 1000 avg 0.0039736575 +/- 0.004068 min 0.000404827 max 0.030141552 sum 3.97365754
# target 50% 0.00231923
# target 75% 0.00475
# target 90% 0.0104667
# target 99% 0.0192
# target 99.9% 0.025
Sockets used: 723 (for perfect keepalive, would be 5)
Jitter: false
Code 200 : 281 (28.1 %)
Code 503 : 719 (71.9 %)
All done 1000 calls (plus 0 warmup) 3.974 ms avg, 1098.3 qps
yunoMacBook-Air:labo8 yu$

200 率增加,我不明白为什么会这样。据我了解,fortio 使用http/1.1时,只有一个 HTTP 请求在一个 TCP 连接中http/1.1。所以我希望我得到相同的结果。

你能告诉我为什么会这样吗?

标签: istio

解决方案


首先要做的事情:HTTP/1.1 确实允许每个带有Keep-Alive标头的连接的多个请求。这是默认行为(RFC 2616,第 8.1 节)。


文档有点不清楚。

maxRequestsPerConnection描述状态:

每个连接到后端的最大请求数。将此参数设置为 1 将禁用保持活动。默认为 0,表示“无限制”,最大为 2^29。

设置maxRequestsPerConnection1禁用Keep-Alive。将其设置为任何其他值(值 > 1)会Keep-Alive重新打开。

将此字段设置为适当的值(不太高也不太低)是配置 Istio 的难点,并且取决于您的应用程序需求和流量。


推荐阅读