【发布时间】:2016-04-20 05:41:12
【问题描述】:
我将 Hystrix 用于其断路器功能,我注意到当满足所需条件时断路器不会立即跳闸。
例如使用以下配置:
withCircuitBreakerRequestVolumeThreshold(2),
withCircuitBreakerErrorThresholdPercentage(50)
如果我同步执行以下命令集(假设 C1-C3 具有相同的 CommandKey)C3 的行为方式我发现是出乎意料的:
// C1: Execute no-op command -- Error threshold 0%, Volume threshold 1
// C2: Execute exception throwing command -- Error threshold 50%, Volume threshold 2
// ---- Breaker should be tripped ----
// C3: Execute no-op command -- This command executes! But the circuit should be tripped!
我发现如果我在 C3 之前检查 HystrixCommandMetrics,HealthMetrics 显示滚动窗口中没有执行任何命令。
但是,如果我在 C3 之前添加 Thread.Sleep(2_000),那么指标会按我预期的那样显示,并且 C3 会像我预期的 FailureType.SHORTCIRCUIT 那样失败。
Hystrix 中的指标不是“实时”的吗?也就是说,它们是否由单独的线程管理?如果是这样的话,也许我不应该假设断路器会立即跳闸。
作为后续,有没有办法强制指标生效?
【问题讨论】: