In this lesson, we explore implementing a circuit breaker pattern to help prevent service disruptions during high-load scenarios. By configuring strict rules, we can ensure that our services maintain stability even when overwhelmed by excessive requests.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Removing Unnecessary Subsets
First, remove the subsets from the product page’s DestinationRule and VirtualService. This is achieved by applying the following configuration:Configuring Traffic Policies with Strict Rules
Next, we implement a strict circuit breaker by configuring the traffic policy. In this configuration:- The HTTP section limits:
- The maximum number of pending requests to 1.
- The maximum requests handled per connection to 1.
- The TCP section restricts the maximum number of connections to 1.
In this configuration, limiting connections and request queues ensures that when the load exceeds these parameters, the circuit breaker triggers, protecting the service from overload.
Testing the Circuit Breaker with HTLOAD
To evaluate the circuit breaker, we use HTLOAD (via its h2load command) to generate concurrent HTTP calls.Single Concurrent Client Test
Start by sending 1,000 HTTP requests with a single concurrent client. The-n flag specifies the total number of requests, while -c sets the concurrency level:
Increasing Concurrency
While a single concurrent client may succeed, increasing the concurrency will test the resilience of the circuit breaker. Below are examples of tests with higher concurrency:-
Test with 1 Concurrent Client (Repeat):
-
Test with 2 Concurrent Clients:
If the service begins to hang while processing a request, the remaining requests will be denied:
-
Test with 3 Concurrent Clients:
More requests are denied as the concurrency increases:
-
Test with 4 Concurrent Clients:
With 4 concurrent clients, the service handles only 46 connections before the circuit breaker denies further requests:
Under the strict circuit breaker configuration, you’ll observe that the product page starts to fail and deny requests under higher concurrency. This behavior is critical to prevent service overload and maintain overall system stability.
Observing Telemetry
Telemetry data captured from the service mesh confirms that the product page fails gracefully when the load exceeds the set limits. This indicates that the circuit breaker is effectively rejecting excessive requests, thereby ensuring the continuous stability of your service under high load conditions.