“特使”中的“最大连接数”实际上是什么意思?

时间:2018-11-27 06:13:17

标签: istio circuit-breaker envoyproxy

我的问题是Envoy中“ cluster.CircuitBreakers.Thresholds.max_connections”的真正含义。

envoy doc中的

cluster.CircuitBreakers.Thresholds.max_connections 解释为:

  

Envoy将与上游群集建立的最大连接数。如果未指定,则默认值为1024。

Istio使用特使作为辅助工具。最近,我们尝试了断路示例,但始终发现连接数超出了我们的配置。

因此我们进行如下所示的另一项测试:

  1. 在istio中添加两个服务:

    • 回显客户端:下游1个容器,将向回显服务器发送HTTP请求
    • 回显服务器:上游2个吊舱。

服务舱:

[root@k8s-master istio-1.0.3]# kubectl get pod -o wide
NAME                          READY   STATUS    RESTARTS   AGE     IP            NODE     NOMINATED NODE
echoclient-84485fbc5c-zxlv8   2/2     Running   0          8s      10.244.2.79   node02   <none>
echoserver-5655768fb9-smsvb   2/2     Running   0          23h     10.244.2.65   node02   <none>
echoserver-5655768fb9-srsq2   2/2     Running   0          7h52m   10.244.2.73   node02   <none>
  1. 为回显服务器配置的目标规则,下面显示了使节中的相应信息。 (maxConnections为2)

istio proxy-config输出:

[root@k8s-master istio-1.0.3]# istioctl proxy-config clusters echoclient-84485fbc5c-zxlv8 --fqdn echoserver.default.svc.cluster.local -o json
[
    {
        "name": "outbound|8080||echoserver.default.svc.cluster.local",
        "type": "EDS",
        "edsClusterConfig": {
            "edsConfig": {
                "ads": {}
            },
            "serviceName": "outbound|8080||echoserver.default.svc.cluster.local"
        },
        "connectTimeout": "1.000s",
        "circuitBreakers": {
            "thresholds": [
                {
                    "maxConnections": 2
                }
            ]
        }
    }
]
  1. 从回显客户端到每个服务器并发多个请求(每个线程40个请求)。

结果:

[root@k8s-master istio-1.0.3]# kubectl exec -it echoclient-84485fbc5c-zxlv8 /bin/bash
Defaulting container name to echoclient.
Use 'kubectl describe pod/echoclient-84485fbc5c-zxlv8 -n default' to see all of the containers in this pod.
[root@echoclient-84485fbc5c-zxlv8 /]# /opt/jre/bin/java -cp /opt/echoclient-1.0-SNAPSHOT-jar-with-dependencies.jar hello.HttpSender "http://echoserver:8080/echo?name=peter" 10 40 0
using num threads: 10
Starting pool-1-thread-1 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-2 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-3 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-4 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-5 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-6 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-7 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-8 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-9 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
Starting pool-1-thread-10 with numCalls=40 parallelSends=false delayBetweenCalls=0 url=http://echoserver:8080/echo?name=peter mixedRespTimes=false
pool-1-thread-7: successes=[40], failures=[0], duration=[481ms]
pool-1-thread-6: successes=[40], failures=[0], duration=[485ms]
pool-1-thread-4: successes=[40], failures=[0], duration=[504ms]
pool-1-thread-1: successes=[40], failures=[0], duration=[542ms]
pool-1-thread-9: successes=[40], failures=[0], duration=[626ms]
pool-1-thread-8: successes=[40], failures=[0], duration=[652ms]
pool-1-thread-2: successes=[40], failures=[0], duration=[684ms]
pool-1-thread-10: successes=[40], failures=[0], duration=[657ms]
pool-1-thread-5: successes=[40], failures=[0], duration=[678ms]
pool-1-thread-3: successes=[40], failures=[0], duration=[696ms]
  1. 检查从回显客户端到回显服务器的HTTP连接

来自netstat的连接信息:

[root@echoclient-84485fbc5c-zxlv8 /]# netstat -ano | grep 8080 | grep ESTABLISHED
tcp        0      0 10.244.2.79:58074       10.244.2.65:8080        ESTABLISHED off (0.00/0/0)
tcp        0      0 10.244.2.79:38076       10.244.2.73:8080        ESTABLISHED off (0.00/0/0)
tcp        0      0 10.244.2.79:58088       10.244.2.65:8080        ESTABLISHED off (0.00/0/0)
tcp        0      0 10.244.2.79:38080       10.244.2.73:8080        ESTABLISHED off (0.00/0/0)
tcp        0      0 10.244.2.79:58056       10.244.2.65:8080        ESTABLISHED off (0.00/0/0)
tcp        0      0 10.244.2.79:38094       10.244.2.73:8080        ESTABLISHED off (0.00/0/0)
tcp        0      0 10.244.2.79:38110       10.244.2.73:8080        ESTABLISHED off (0.00/0/0)
tcp        0      0 10.244.2.79:58076       10.244.2.65:8080        ESTABLISHED off (0.00/0/0)

特使群集的连接信息:

[root@echoclient-84485fbc5c-zxlv8 /]# curl -s http://localhost:15000/clusters | grep echoserver
outbound|8080||echoserver.default.svc.cluster.local::default_priority::max_connections::2
outbound|8080||echoserver.default.svc.cluster.local::default_priority::max_pending_requests::1024
outbound|8080||echoserver.default.svc.cluster.local::default_priority::max_requests::1024
outbound|8080||echoserver.default.svc.cluster.local::default_priority::max_retries::3
outbound|8080||echoserver.default.svc.cluster.local::high_priority::max_connections::1024
outbound|8080||echoserver.default.svc.cluster.local::high_priority::max_pending_requests::1024
outbound|8080||echoserver.default.svc.cluster.local::high_priority::max_requests::1024
outbound|8080||echoserver.default.svc.cluster.local::high_priority::max_retries::3
outbound|8080||echoserver.default.svc.cluster.local::added_via_api::true
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::cx_active::4
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::cx_connect_fail::0
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::cx_total::4
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::rq_active::0
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::rq_error::0
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::rq_success::200
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::rq_timeout::0
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::rq_total::200
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::health_flags::healthy
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::weight::1
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::region::
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::zone::
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::sub_zone::
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::canary::false
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.65:8080::success_rate::-1
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::cx_active::4
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::cx_connect_fail::0
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::cx_total::4
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::rq_active::0
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::rq_error::0
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::rq_success::200
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::rq_timeout::0
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::rq_total::200
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::health_flags::healthy
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::weight::1
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::region::
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::zone::
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::sub_zone::
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::canary::false
outbound|8080||echoserver.default.svc.cluster.local::10.244.2.73:8080::success_rate::-1

我们看到从echoclient到echoserver(10.244.2.65,10.244.2.73)有 8个连接,但是没有配置的maxConnections 2

为什么有8个连接却没有2个? 关于使节的maxConnections有误解吗?

3 个答案:

答案 0 :(得分:0)

如Garrett在评论中所述:

max_connectionsmax_requests是指每个children的php池在重生之前可以建立的连接数,通常可以在/etc/etc/php/{version}/fpm/pool.d/www.conf {{1}中找到}基于机器的内存,一些对我来说很有帮助的示例教程为Max Requests / Children

答案 1 :(得分:0)

我认为,您使用1个线程(即1个HTTP连接)调用了客户端,但它并行发送了请求(默认为10个批次)

在特使中, max_connections 适用于http1连接,在您的情况下,您只有一个http连接。

尝试查看 max_request ,它可能适用于与http2有密切关系的线程。

希望这会有所帮助!

答案 2 :(得分:0)

SSH到客户端pod的节点,并执行到istio-proxy容器

docker exec --privileged --user root -it <istio-proxy-container-id> bash

使用以下命令查找特使与上游的TCP连接

ss -pe | grep 8080 | grep envoy