概述重试与超时在网络抖动与瞬时错误时提升成功率。通过故障注入验证策略效果,并在非幂等路径禁用或收紧重试以避免副作用。关键实践与参数超时: 路由级别 `timeout=5s`重试: `attempts=3` `perTryTimeout=2s` `retryOn=5xx,connect-failure,gateway-error`连接池: 设置请求与等待上限幂等控制: 对写操作关闭或限制重试示例/配置/实现apiVersion: networking.istio.io/v1beta1

kind: DestinationRule

metadata:

name: api-dr

spec:

host: api.svc.cluster.local

trafficPolicy:

connectionPool:

http:

http1MaxPendingRequests: 200

maxRequestsPerConnection: 100

---

apiVersion: networking.istio.io/v1beta1

kind: VirtualService

metadata:

name: api-vs

spec:

hosts: ["api.svc.cluster.local"]

http:

- match: [{ uri: { prefix: "/read" } }]

timeout: 5s

retries:

attempts: 3

perTryTimeout: 2s

retryOn: "5xx,connect-failure,gateway-error"

route:

- destination: { host: api.svc.cluster.local, port: { number: 80 } }

- match: [{ uri: { prefix: "/write" } }]

route:

- destination: { host: api.svc.cluster.local, port: { number: 80 } }

retries:

attempts: 0

---

apiVersion: networking.istio.io/v1beta1

kind: VirtualService

metadata:

name: api-fault

spec:

hosts: ["api.svc.cluster.local"]

http:

- match: [{ uri: { prefix: "/read" } }]

fault:

delay:

percentage: { value: 50 }

fixedDelay: 2s

route:

- destination: { host: api.svc.cluster.local, port: { number: 80 } }

验证延迟场景: 在故障注入下读路径成功率提升且延迟受控非幂等保护: 写路径无重试避免重复写入资源影响: 请求与连接上限内无队列拥塞指标记录: 采集重试次数与超时比例注意事项重试仅在幂等或安全路径启用超时需与上游与客户端协同故障注入在灰度环境执行设置告警监控重试激增

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部