41 lines
1.2 KiB
Markdown
41 lines
1.2 KiB
Markdown
---
|
||
title: "Circuit Breaker"
|
||
type: concept
|
||
tags: []
|
||
sources: [engineering-autonomous-optimization-architect]
|
||
last_updated: 2026-05-01
|
||
---
|
||
|
||
# Circuit Breaker
|
||
|
||
## Definition
|
||
|
||
熔断器模式(Circuit Breaker)——当某个 LLM API 端点连续失败超过预设阈值时,自动切断对该端点的路由,将流量切换到降级路径,同时向人工告警。
|
||
|
||
## Mechanism
|
||
|
||
1. **Closed(正常)**:所有请求正常路由到目标端点
|
||
2. **Open(熔断)**:端点连续失败超过阈值,立即切断路由,所有请求跳过该端点
|
||
3. **Half-Open(半开)**:经过冷却期后,放行少量请求试探端点是否恢复
|
||
|
||
## Trigger Conditions
|
||
|
||
- 端点流量异常激增(500%+,可能为恶意 bot 攻击)
|
||
- 连续出现 HTTP 402(需要付费)/ 429(速率限制)错误
|
||
- 单次请求成本超过安全上限(如 $0.05/次)
|
||
|
||
## Example
|
||
|
||
```typescript
|
||
if (provider.failures > securityLimits.maxRetries) {
|
||
tripCircuitBreaker(provider);
|
||
routeToFallback(provider);
|
||
alertAdmin(`Circuit breaker tripped: ${provider.name}`);
|
||
}
|
||
```
|
||
|
||
## Related
|
||
|
||
- [[Autonomous-Optimization-Architect]]:使用熔断器保护 AI 路由系统的核心组件
|
||
- [[AI-FinOps]]:熔断器是 FinOps 成本控制的最后防线
|