All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure a connection pool for circuit breaking

Last Updated:Oct 23, 2026

Circuit breaking is a traffic management strategy that protects a system from further damage during a failure or overload. In traditional Java services, you can use frameworks like Resilience4j to implement circuit breaking. However, Istio provides circuit breaking at the network level, which eliminates the need to integrate it into the application code of each service. You can configure a connection pool to implement circuit breaking, which improves system stability and reliability, and protects destination services from abnormal requests.

Prerequisites

You have added a cluster to a Service Mesh (ASM) instance.

Connection pool parameters

Before you enable circuit breaking, you must create a destination rule to configure circuit breaking for the destination service. For a description of the fields in a destination rule, see Destination Rule.

The connectionPool field defines parameters related to circuit breaking. The following table describes the common connection pool parameters.

Parameter

Type

Required

Description

Default

tcp.maxConnections

int32

No

The maximum number of HTTP/1.1 or TCP connections to a destination host. This limit applies independently to each sidecar proxy on the client and server. A single client pod cannot create more connections than this limit, and a single server pod cannot accept more. The total connections the destination service can accept is calculated as: min(number of client pods, number of server pods) * maxConnections.

2³²-1

http.http1MaxPendingRequests

int32

No

The maximum number of requests that can be queued while waiting for a ready connection from the connection pool.

1024

http.http2MaxRequests

int32

No

The maximum number of active requests to a backend service.

1024

In a simple scenario with one client and one destination service instance (in a Kubernetes environment, an instance is equivalent to a pod), the parameter configuration is straightforward. However, production environments often involve more complex scenarios:

  • One client instance and multiple destination service instances.

  • Multiple client instances and a single destination service instance.

  • Multiple client instances and multiple destination service instances.

You must adjust these parameters for different scenarios to ensure the connection pool performs reliably under high load. The following sections show how to configure the connection pool for these scenarios, helping you understand the client and server constraints and choose a suitable circuit breaking policy for your production environment.

Example

This topic uses two Python scripts: one represents the destination service (server) and the other represents the client that calls the service.

  • The server script uses the Flask framework to create an application and defines an API endpoint at the /hello route. When the endpoint is accessed, the server sleeps for 5 seconds and then returns a response containing the string "Hello World!".

    Server script

    #! /usr/bin/env python3
    from flask import Flask
    import time
    
    app = Flask(__name__)
    
    @app.route('/hello')
    def get():
        time.sleep(5)
        return 'hello world!'
    
    if __name__ == '__main__':
        app.run(debug=True, host='0.0.0.0', port='9080', threaded = True)
  • The client script runs in an infinite loop, sending batches of 10 parallel requests to the server endpoint. To synchronize request batches across multiple client pods, the script uses the system clock to trigger sends at 0, 20, and 40 seconds past the minute.

    Client script

    #! /usr/bin/env python3
    import requests
    import time
    import sys
    from datetime import datetime
    import _thread
    
    def timedisplay(t):
      return t.strftime("%H:%M:%S")
    
    def get(url):
      try:
        stime = datetime.now()
        start = time.time()
        response = requests.get(url)
        etime = datetime.now()
        end = time.time()
        elapsed = end-start
        sys.stderr.write("Status: " + str(response.status_code) + ", Start: " + timedisplay(stime) + ", End: " + timedisplay(etime) + ", Elapsed Time: " + str(elapsed)+"\n")
        sys.stdout.flush()
      except Exception as myexception:
        sys.stderr.write("Exception: " + str(myexception)+"\n")
        sys.stdout.flush()
    
    time.sleep(30)
    
    while True:
      sc = int(datetime.now().strftime('%S'))
      time_range = [0, 20, 40]
    
      if sc not in time_range:
        time.sleep(1)
        continue
    
      sys.stderr.write("\n----------Info----------\n")
      sys.stdout.flush()
    
      # Send 10 requests in parallel
      for i in range(10):
        _thread.start_new_thread(get, ("http://circuit-breaker-sample-server:9080/hello", ))
    
      time.sleep(2)

Deploy the sample application

  1. Create a YAML file with the following content and run the kubectl apply -f ${YAML_FILE_NAME}.yaml command to deploy the sample application.

    YAML code

    ##################################################################################################
    #  circuit-breaker-sample-server services
    ##################################################################################################
    apiVersion: v1
    kind: Service
    metadata:
      name: circuit-breaker-sample-server
      labels:
        app: circuit-breaker-sample-server
        service: circuit-breaker-sample-server
    spec:
      ports:
      - port: 9080
        name: http
      selector:
        app: circuit-breaker-sample-server
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: circuit-breaker-sample-server
      labels:
        app: circuit-breaker-sample-server
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: circuit-breaker-sample-server
          version: v1
      template:
        metadata:
          labels:
            app: circuit-breaker-sample-server
            version: v1
        spec:
          containers:
          - name: circuit-breaker-sample-server
            image: registry.cn-hangzhou.aliyuncs.com/acs/istio-samples:circuit-breaker-sample-server.v1
            imagePullPolicy: Always
            ports:
            - containerPort: 9080
    ---
    ##################################################################################################
    #  circuit-breaker-sample-client services
    ##################################################################################################
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: circuit-breaker-sample-client
      labels:
        app: circuit-breaker-sample-client
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: circuit-breaker-sample-client
          version: v1
      template:
        metadata:
          labels:
            app: circuit-breaker-sample-client
            version: v1
        spec:
          containers:
          - name: circuit-breaker-sample-client
            image: registry.cn-hangzhou.aliyuncs.com/acs/istio-samples:circuit-breaker-sample-client.v1
            imagePullPolicy: Always
            
  2. Run the following command to view the client and server pods.

    kubectl get po |grep circuit  

    Expected output:

    circuit-breaker-sample-client-d4f64d66d-fwrh4   2/2     Running   0             1m22s
    circuit-breaker-sample-server-6d6ddb4b-gcthv    2/2     Running   0             1m22s

Without an explicit destination rule to set limits, the server can handle all 10 concurrent client requests, and all requests receive a 200 status code. The following is an example of the client logs:

----------Info----------
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.016539812088013
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.012614488601685
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.015984535217285
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.015599012374878
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.012874364852905
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.018714904785156
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.010422468185425
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.012431621551514
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.011001348495483
Status: 200, Start: 02:39:20, End: 02:39:25, Elapsed Time: 5.01432466506958

Configure the connection pool

To enable a circuit breaking rule in the service mesh, define a destination rule for the destination service.

Create a destination rule with the following content. For more information, see Manage destination rules. This destination rule sets the maximum number of TCP connections to the destination service to 5.

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: circuit-breaker-sample-server
spec:
  host: circuit-breaker-sample-server
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 5

Scenario 1: 1 client and 1 destination pod

  1. Start the client pod and monitor its logs.

    For a clearer result, restart the client. You will see logs similar to the following:

    ----------Info----------
    Status: 200, Start: 02:49:40, End: 02:49:45, Elapsed Time: 5.0167787075042725
    Status: 200, Start: 02:49:40, End: 02:49:45, Elapsed Time: 5.011920690536499
    Status: 200, Start: 02:49:40, End: 02:49:45, Elapsed Time: 5.017078161239624
    Status: 200, Start: 02:49:40, End: 02:49:45, Elapsed Time: 5.018405437469482
    Status: 200, Start: 02:49:40, End: 02:49:45, Elapsed Time: 5.018689393997192
    Status: 200, Start: 02:49:40, End: 02:49:50, Elapsed Time: 10.018936395645142
    Status: 200, Start: 02:49:40, End: 02:49:50, Elapsed Time: 10.016417503356934
    Status: 200, Start: 02:49:40, End: 02:49:50, Elapsed Time: 10.019930601119995
    Status: 200, Start: 02:49:40, End: 02:49:50, Elapsed Time: 10.022735834121704
    Status: 200, Start: 02:49:40, End: 02:49:55, Elapsed Time: 15.02303147315979

    All requests succeed. However, in each batch, only 5 requests have a response time of about 5 seconds. The other requests are slower, taking 10 seconds or more. This result shows that using only tcp.maxConnections queues excess requests. By default, the limit for this pending request queue is 1024.

  2. Update the destination rule to allow only one pending request. For more information, see Manage destination rules.

    To achieve true circuit breaking (fail-fast behavior), you also need to set http.http1MaxPendingRequests to limit the number of queued requests. The default value for this parameter is 1024. If you set it to 0, it reverts to the default value. Therefore, you must set it to at least 1.

    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
      name: circuit-breaker-sample-server
    spec:
      host: circuit-breaker-sample-server
      trafficPolicy:
        connectionPool:
          tcp:
            maxConnections: 5
          http:
            http1MaxPendingRequests: 1
  3. Restart the client pod to avoid skewed results and continue to observe the logs.

    The following is an example of the logs:

    ----------Info----------
    Status: 503, Start: 02:56:40, End: 02:56:40, Elapsed Time: 0.005339622497558594
    Status: 503, Start: 02:56:40, End: 02:56:40, Elapsed Time: 0.007254838943481445
    Status: 503, Start: 02:56:40, End: 02:56:40, Elapsed Time: 0.0044133663177490234
    Status: 503, Start: 02:56:40, End: 02:56:40, Elapsed Time: 0.008964776992797852
    Status: 200, Start: 02:56:40, End: 02:56:45, Elapsed Time: 5.018309116363525
    Status: 200, Start: 02:56:40, End: 02:56:45, Elapsed Time: 5.017424821853638
    Status: 200, Start: 02:56:40, End: 02:56:45, Elapsed Time: 5.019804954528809
    Status: 200, Start: 02:56:40, End: 02:56:45, Elapsed Time: 5.01643180847168
    Status: 200, Start: 02:56:40, End: 02:56:45, Elapsed Time: 5.025975227355957
    Status: 200, Start: 02:56:40, End: 02:56:50, Elapsed Time: 10.01716136932373

    As expected, 4 requests are immediately throttled, 5 requests are sent to the destination service, and 1 request is queued.

  4. Run the following command to check the number of active connections established between the client's Istio proxy and the destination service pod.

    kubectl exec $(kubectl get pod --selector app=circuit-breaker-sample-client --output jsonpath='{.items[0].metadata.name}') -c istio-proxy -- curl -X POST http://localhost:15000/clusters | grep circuit-breaker-sample-server | grep cx_active

    Expected output:

    outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local::172.20.192.124:9080::cx_active::5

    The output shows that 5 active connections are established between the client's Istio proxy and the destination service pod.

Scenario 2: 1 client and multiple destination pods

This section verifies whether the connection limit applies per-pod or per-service, using one client pod and three destination service pods.

  • If the limit applies per-pod, the total capacity would be 15 connections (3 pods × 5 connections/pod).

    Because only 10 requests are sent, no throttling or queuing would occur, and all requests would succeed in about 5 seconds.

  • If the connection limit is applied at the service level, the total number of connections is limited to 5, regardless of the number of pods for the destination service.

    In this case, we would expect to see 4 requests immediately throttled, 5 requests sent to the destination service, and 1 request queued.

  1. Run the following command to scale the destination service Deployment to multiple replicas (for example, 3).

    kubectl scale deployment/circuit-breaker-sample-server  --replicas=3
  2. Restart the client pod and monitor its logs.

    The following is an example of the logs:

    ----------Info----------
    Status: 503, Start: 03:06:20, End: 03:06:20, Elapsed Time: 0.011791706085205078
    Status: 503, Start: 03:06:20, End: 03:06:20, Elapsed Time: 0.0032286643981933594
    Status: 503, Start: 03:06:20, End: 03:06:20, Elapsed Time: 0.012153387069702148
    Status: 503, Start: 03:06:20, End: 03:06:20, Elapsed Time: 0.011871814727783203
    Status: 200, Start: 03:06:20, End: 03:06:25, Elapsed Time: 5.012892484664917
    Status: 200, Start: 03:06:20, End: 03:06:25, Elapsed Time: 5.013102769851685
    Status: 200, Start: 03:06:20, End: 03:06:25, Elapsed Time: 5.016939163208008
    Status: 200, Start: 03:06:20, End: 03:06:25, Elapsed Time: 5.014261484146118
    Status: 200, Start: 03:06:20, End: 03:06:25, Elapsed Time: 5.01246190071106
    Status: 200, Start: 03:06:20, End: 03:06:30, Elapsed Time: 10.021712064743042

    The similar throttling and queuing indicate that the client's connection pool limit is applied to the service as a whole and is not increased by adding more destination service instances.

  3. After running for a while, run the following command to check the number of active connections between the client's Istio proxy and the destination service pods.

    kubectl exec $(kubectl get pod --selector app=circuit-breaker-sample-client --output jsonpath='{.items[0].metadata.name}') -c istio-proxy -- curl -X POST http://localhost:15000/clusters | grep circuit-breaker-sample-server | grep cx_active

    Expected output:

    outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local::172.20.192.124:9080::cx_active::2
    outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local::172.20.192.158:9080::cx_active::2
    outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local::172.20.192.26:9080::cx_active::2

    The output shows a total of 6 active connections, not 5, distributed across the destination service pods. This demonstrates that connection limits are not always strictly enforced, a known behavior noted in the Envoy and Istio documentation.

Scenario 3: Multiple clients and 1 destination pod

  1. Adjust the replica counts for the client and destination service:

    kubectl scale deployment/circuit-breaker-sample-server --replicas=1 
    kubectl scale deployment/circuit-breaker-sample-client --replicas=3
  2. Restart the client pods and monitor their logs.

    Client logs

    Client 1
    
    ----------Info----------
    Status: 503, Start: 03:10:40, End: 03:10:40, Elapsed Time: 0.008828878402709961
    Status: 503, Start: 03:10:40, End: 03:10:40, Elapsed Time: 0.010806798934936523
    Status: 503, Start: 03:10:40, End: 03:10:40, Elapsed Time: 0.012855291366577148
    Status: 503, Start: 03:10:40, End: 03:10:40, Elapsed Time: 0.004465818405151367
    Status: 503, Start: 03:10:40, End: 03:10:40, Elapsed Time: 0.007823944091796875
    Status: 503, Start: 03:10:40, End: 03:10:40, Elapsed Time: 0.06221342086791992
    Status: 503, Start: 03:10:40, End: 03:10:40, Elapsed Time: 0.06922149658203125
    Status: 503, Start: 03:10:40, End: 03:10:40, Elapsed Time: 0.06859922409057617
    Status: 200, Start: 03:10:40, End: 03:10:45, Elapsed Time: 5.015282392501831
    Status: 200, Start: 03:10:40, End: 03:10:50, Elapsed Time: 9.378434181213379
    
    Client 2
    
    ----------Info----------
    Status: 503, Start: 03:11:00, End: 03:11:00, Elapsed Time: 0.007795810699462891
    Status: 503, Start: 03:11:00, End: 03:11:00, Elapsed Time: 0.00595545768737793
    Status: 503, Start: 03:11:00, End: 03:11:00, Elapsed Time: 0.013380765914916992
    Status: 503, Start: 03:11:00, End: 03:11:00, Elapsed Time: 0.004278898239135742
    Status: 503, Start: 03:11:00, End: 03:11:00, Elapsed Time: 0.010999202728271484
    Status: 200, Start: 03:11:00, End: 03:11:05, Elapsed Time: 5.015426874160767
    Status: 200, Start: 03:11:00, End: 03:11:05, Elapsed Time: 5.0184690952301025
    Status: 200, Start: 03:11:00, End: 03:11:05, Elapsed Time: 5.019806146621704
    Status: 200, Start: 03:11:00, End: 03:11:05, Elapsed Time: 5.0175628662109375
    Status: 200, Start: 03:11:00, End: 03:11:05, Elapsed Time: 5.031521558761597
    
    Client 3
    
    ----------Info----------
    Status: 503, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.012019157409667969
    Status: 503, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.012546539306640625
    Status: 503, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.013760805130004883
    Status: 503, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.014089822769165039
    Status: 503, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.014792442321777344
    Status: 503, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.015463829040527344
    Status: 503, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.01661539077758789
    Status: 200, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.02904224395751953
    Status: 200, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.03912043571472168
    Status: 200, Start: 03:13:20, End: 03:13:20, Elapsed Time: 0.06436014175415039

    The number of 503 errors on each client increases. The destination service as a whole limits the total concurrent requests from all clients to 5.

  3. View the client proxy logs.

    Client proxy logs

    {"authority":"circuit-breaker-sample-server:9080","bytes_received":"0","bytes_sent":"81","downstream_local_address":"192.168.142.207:9080","downstream_remote_address":"172.20.192.31:44610","duration":"0","istio_policy_status":"-","method":"GET","path":"/hello","protocol":"HTTP/1.1","request_id":"d9d87600-cd01-421f-8a6f-dc0ee0ac8ccd","requested_server_name":"-","response_code":"503","response_flags":"UO","route_name":"default","start_time":"2023-02-28T03:14:00.095Z","trace_id":"-","upstream_cluster":"outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local","upstream_host":"-","upstream_local_address":"-","upstream_service_time":"-","upstream_transport_failure_reason":"-","user_agent":"python-requests/2.21.0","x_forwarded_for":"-"}
    
    {"authority":"circuit-breaker-sample-server:9080","bytes_received":"0","bytes_sent":"81","downstream_local_address":"192.168.142.207:9080","downstream_remote_address":"172.20.192.31:43294","duration":"58","istio_policy_status":"-","method":"GET","path":"/hello","protocol":"HTTP/1.1","request_id":"931d080a-3413-4e35-91f4-0c906e7ee565","requested_server_name":"-","response_code":"503","response_flags":"URX","route_name":"default","start_time":"2023-02-28T03:12:20.995Z","trace_id":"-","upstream_cluster":"outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local","upstream_host":"172.20.192.84:9080","upstream_local_address":"172.20.192.31:58742","upstream_service_time":"57","upstream_transport_failure_reason":"-","user_agent":"python-requests/2.21.0","x_forwarded_for":"-"}
    

    You can see two different types of log entries for the throttled requests (503 errors). The RESPONSE_FLAGS field includes the values UO and URX.

    • UO: Upstream overflow (circuit breaking).

    • URX: The request was rejected because the upstream retry limit (HTTP) or maximum connection attempts (TCP) was reached.

    Based on the values of other fields in the logs, such as DURATION, UPSTREAM_HOST, and UPSTREAM_CLUSTER, we can draw a further conclusion:

    Requests with the UO flag are throttled locally by the client proxy, while requests with the URX flag are rejected by the destination service proxy.

  4. Verify the conclusion from the previous step by checking the logs of the destination service proxy.

    Destination service proxy logs

    {"authority":"circuit-breaker-sample-server:9080","bytes_received":"0","bytes_sent":"81","downstream_local_address":"172.20.192.84:9080","downstream_remote_address":"172.20.192.31:59510","duration":"0","istio_policy_status":"-","method":"GET","path":"/hello","protocol":"HTTP/1.1","request_id":"7684cbb0-8f1c-44bf-b591-40c3deff6b0b","requested_server_name":"outbound_.9080_._.circuit-breaker-sample-server.default.svc.cluster.local","response_code":"503","response_flags":"UO","route_name":"default","start_time":"2023-02-28T03:14:00.095Z","trace_id":"-","upstream_cluster":"inbound|9080||","upstream_host":"-","upstream_local_address":"-","upstream_service_time":"-","upstream_transport_failure_reason":"-","user_agent":"python-requests/2.21.0","x_forwarded_for":"-"}
    {"authority":"circuit-breaker-sample-server:9080","bytes_received":"0","bytes_sent":"81","downstream_local_address":"172.20.192.84:9080","downstream_remote_address":"172.20.192.31:58218","duration":"0","istio_policy_status":"-","method":"GET","path":"/hello","protocol":"HTTP/1.1","request_id":"2aa351fa-349d-4283-a5ea-dc74ecbdff8c","requested_server_name":"outbound_.9080_._.circuit-breaker-sample-server.default.svc.cluster.local","response_code":"503","response_flags":"UO","route_name":"default","start_time":"2023-02-28T03:12:20.996Z","trace_id":"-","upstream_cluster":"inbound|9080||","upstream_host":"-","upstream_local_address":"-","upstream_service_time":"-","upstream_transport_failure_reason":"-","user_agent":"python-requests/2.21.0","x_forwarded_for":"-"}

    As expected, the logs of the destination service proxy show a 503 response code. This is why the client proxy logs contain "response_code":"503" and "response_flags":"URX".

Each client proxy enforces its 5-connection limit, queuing or locally throttling excess requests (flagged UO). At the start of a batch, the three client proxies can attempt up to 15 concurrent requests. However, the single destination service proxy also enforces a 5-connection limit, accepting only 5 total requests and rejecting the rest. These rejections from the destination proxy appear in client proxy logs with a URX response flag.

The following diagram illustrates this scenario:

image

Scenario 4: Multiple clients and multiple destination pods

Increasing the number of destination service replicas increases the total request capacity, as each new replica's proxy can handle 5 concurrent requests. This allows you to observe the interplay between client-side and server-side limits.

  1. Run the following commands to increase the number of destination service replicas to 2 and the number of client replicas to 3.

    kubectl scale deployment/circuit-breaker-sample-server --replicas=2
    kubectl scale deployment/circuit-breaker-sample-client --replicas=3

    You can see that 10 of the 30 requests generated by all three client proxies in one batch are successful.

  2. Run the following command to increase the number of destination service replicas to 3.

    kubectl scale deployment/circuit-breaker-sample-server --replicas=3

    You can see 15 successful requests.

  3. Run the following command to increase the number of destination service replicas to 4.

    kubectl scale deployment/circuit-breaker-sample-server --replicas=4

    Even when the destination service is scaled from 3 to 4 replicas, the number of successful requests remains 15. The client side has become the bottleneck: the three client proxies can only send a combined total of 15 concurrent requests (5 each).

Related operations

Metrics for connection pool circuit breaking

Connection pool circuit breaking is achieved by limiting the maximum number of TCP connections to a destination host. It produces a series of related metrics to help determine if a circuit breaker has been tripped. The following table describes some of these metrics:

Metric

Type

Description

envoy_cluster_circuit_breakers_default_cx_open

Gauge

1 if the connection pool circuit breaker is tripped; 0 otherwise.

envoy_cluster_circuit_breakers_default_rq_pending_open

Gauge

1 if the pending request queue is full; 0 otherwise.

Configure the sidecar proxy's proxyStatsMatcher field to report these metrics, then use Prometheus to collect and view them.

  1. Configure the sidecar proxy to report circuit breaking metrics by using proxyStatsMatcher. When configuring proxyStatsMatcher, select Regular Expression Match and set the value to .*circuit_breaker.*. For more information, see Custom Envoy metrics (proxyStatsMatcher).

  2. Redeploy the circuit-breaker-sample-server and circuit-breaker-sample-client Deployments. For more information, see Redeploy workloads.

  3. Follow the steps above to configure connection pool circuit breaking and send requests.

  4. Run the following command to view the connection pool circuit breaking metrics for the circuit-breaker-sample-client service.

    kubectl exec -it deploy/circuit-breaker-sample-client -c istio-proxy -- curl localhost:15090/stats/prometheus | grep circuit_breaker | grep circuit-breaker-sample-server

    Expected output:

    kubectl exec -it deploy/circuit-breaker-sample-client -c istio-proxy -- curl localhost:15090/stats/prometheus | grep circuit_breaker | grep circuit-breaker-sample-server
    envoy_cluster_circuit_breakers_default_cx_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 1
    envoy_cluster_circuit_breakers_default_cx_pool_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_default_remaining_cx{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_default_remaining_cx_pools{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 18446744073709551613
    envoy_cluster_circuit_breakers_default_remaining_pending{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 1
    envoy_cluster_circuit_breakers_default_remaining_retries{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 4294967295
    envoy_cluster_circuit_breakers_default_remaining_rq{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 4294967295
    envoy_cluster_circuit_breakers_default_rq_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_default_rq_pending_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_default_rq_retry_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_high_cx_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_high_cx_pool_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_high_rq_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_high_rq_pending_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0
    envoy_cluster_circuit_breakers_high_rq_retry_open{cluster_name="outbound|9080||circuit-breaker-sample-server.default.svc.cluster.local"} 0

Metric collection and alerting

After configuring the relevant metrics, you can configure Prometheus to collect them and set up alert rules based on key metrics to ensure timely notification when circuit breaking occurs. The following example shows how to configure metric collection and alerting for connection pool circuit breaking by using Managed Service for Prometheus.

  1. In Managed Service for Prometheus, integrate or upgrade the Alibaba Cloud ASM component in your data plane cluster. This allows it to collect the exposed circuit breaking metrics. For more information about how to update integrated components, see Manage integrations. (Skip this step if you already use a self-managed Prometheus as described in Monitor ASM instances with a self-managed Prometheus instance.)

  2. Create an alert rule for connection pool circuit breaking. For more information, see Create a rule with a custom PromQL statement. The following table provides an example of how to fill in the key parameters for the alert rule. You can configure the other parameters based on your needs.

Parameter

Example

Description

Custom PromQL Statement

(sum by(cluster_name, pod_name,namespace) (envoy_cluster_circuit_breakers_default_cx_open)) != 0

This query uses the envoy_cluster_circuit_breakers_default_cx_open metric to detect if circuit breaking is active in the cluster. The cluster_name (upstream service), pod_name, and namespace labels identify the exact location of the event.

Alert Message

Connection pool circuit breaking has occurred. The number of TCP connections established by the proxy has reached the maximum limit! Namespace: {{$labels.namespace}}, Pod where circuit breaking was triggered: {{$labels.pod_name}}, Upstream service info: {{ $labels.cluster_name }}

This example alert message shows the pod that triggered the circuit breaking, the upstream service it connects to, and the pod's namespace.

Connection pool constraints

The following table describes the constraints that connection pool configurations place on clients and destination services.

Role

Description

Client

Each client proxy enforces the limit independently. A limit of 100 means each proxy allows 100 concurrent requests before it begins local throttling. With N clients, the total concurrent requests can reach 100 * N.

The client proxy limit applies to the entire destination service, not to individual replicas of the service. Even if the destination service has 200 active pods, the throttling limit per client proxy remains 100.

Destination service

Each destination service proxy also enforces the limit. If a service has 50 pods and a limit of 100, each pod can accept up to 100 concurrent requests before it throttles them and returns 503 errors.