diff --git a/content/en/docs/userguide/circuit_breaker.md b/content/en/docs/userguide/circuit_breaker.md new file mode 100644 index 0000000..1359d51 --- /dev/null +++ b/content/en/docs/userguide/circuit_breaker.md @@ -0,0 +1,253 @@ +--- +draft: false +linktitle: Circuit Breaker +menu: + docs: + parent: user guide + weight: 22 +title: Use Circuit Breaker +toc: true +type: docs +--- + +### Preparation + +1. Ensure KMesh is installed in your Kubernetes cluster (see [Quick Start Guide](https://kmesh.net/en/docs/setup/quickstart/)) + +2. Deploy a sample microservice application + +3. Verify the default namespace is managed by KMesh + +### Circuit Breaker Configuration + +##### Deploy a Sample Application + +Let's use a simple microservice setup to demonstrate circuit breaking: + +```bash +kubectl apply -f - <active_connections >= cbs->max_connections) { + // Reject connection + return -1; + } + // Bind socket to cluster + return 0; +} +``` + +### Advanced Configuration Example + +```yaml +apiVersion: kmesh.net/v1alpha1 +kind: CircuitBreaker +metadata: + name: complex-service-circuit-breaker +spec: + services: + - name: service-a + rules: + - priority: HIGH + maxConnections: 50 + - name: service-b + rules: + - priority: MEDIUM + maxConnections: 100 +``` + +### Troubleshooting + +##### Common Issues +- Unexpected connection rejections +- High error rates +- Performance degradation + +##### Debugging Steps + +```bash +# Check circuit breaker configuration +kubectl describe circuitbreaker sample-service-circuit-breaker + +# View detailed logs +kubectl logs -n kmesh -l app=kmesh circuit-breaker -c circuit-breaker + +# Check cluster status +kmesh get clusters +``` + +### Best Practices + +1. Start with conservative limits +2. Gradually adjust based on service performance +3. Monitor circuit breaker metrics +4. Use priority-based configurations + +### Performance Considerations + +- Kernel-native implementation +- Minimal overhead +- Lock-free atomic updates +- eBPF map-based tracking + +### Cleanup + +Remove the circuit breaker and sample application: + +```bash +kubectl delete circuitbreaker sample-service-circuit-breaker +kubectl delete deployment sample-service +kubectl delete service sample-service +``` + +### Limitations + +- Currently focuses on TCP connections +- Kernel version dependencies +- Per-cluster granularity + +### Sample Code Snippet + +```go +// Circuit Breaker Configuration Example +circuitBreaker := &CircuitBreakers{ + Priority: RoutingPriority_HIGH, + MaxConnections: 100, + MaxPendingRequests: 50, + MaxRequests: 200, + MaxRetries: 3, +} +``` \ No newline at end of file