我的问题是关于“cluster.CircuitBreakers.Thresholds.max_connections”在Envoy中的真正含义。
envoy doc中的cluster.CircuitBreakers.Thresholds.max_connections解释为:
Envoy将对上游群集进行的最大连接数。如果未指定,则默认值为1024。
Istio使用特使作为边车。最近我们尝试了断路器样品,但总是发现有比我们配置的更多的连接。
所以我们进行另一个测试如下所示:
服务舱:
[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>
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
}
]
}
}
]
结果:
[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]
来自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)
来自envoy集群的连接信息:
[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有什么误解吗?
正如加勒特在评论中提到的:
max_connections
或max_requests
指的是php池中每个children
在重新生成之前可以采取的连接数,并且通常可以在/etc/etc/php/{version}/fpm/pool.d/www.conf
中找到max_children
是基于机器的内存,一些有助于我理解的示例教程是Max Requests / Children
我想,你用1个线程(即1个HTTP连接)调用了客户端,但它并行发送请求(默认情况下是10个批量)
在envoy中,max_connections适用于http1连接,在您的情况下,您只有一个http连接。
试着看看max_request
,它可能适用于与http2密切相关的线程。
希望这可以帮助!!
SSH到客户端pod的节点,并执行到istio-proxy容器
docker exec --privileged --user root -it <istio-proxy-container-id> bash
使用以下命令查找envoy make to upstream的tcp连接
ss -pe | grep 8080 | grep envoy