Skip to content

配置

sleepWindowInMilliseconds

如果熔断被触发,在 circuitBreakerSleepWindowInMilliseconds 的时间内,便不再对外调用接口,而是直接调用本地的一个降级方法

默认值 5000ms
大多数情况下配置为 1000ms

This property sets the amount of time, after tripping the circuit, to reject requests before allowing attempts again to determine if the circuit should again be closed.

requestVolumeThreshold

一个统计窗口 10 秒内请求数量。达到这个请求数量后才去判断是否要开启熔断。默认值是20

This property sets the minimum number of requests in a rolling window that will trip the circuit.

For example, if the value is 20, then if only 19 requests are received in the rolling window (say a window of 10 seconds) the circuit will not trip open even if all 19 failed.

errorPercentThreshold

错误百分比,请求数量大于等于RequestVolumeThreshold并且错误率到达这个百分比后就会启动熔断默认值是50

This property sets the error percentage at or above which the circuit should trip open and start short-circuiting requests to fallback logic.

execution.isolation.thread.timeoutInMilliseconds

执行 command 的超时时间。默认时间是1000毫秒

This property sets the time in milliseconds after which the caller will observe a timeout and walk away from the command execution. Hystrix marks the HystrixCommand as a TIMEOUT, and performs fallback logic

execution.isolation.semaphore.maxConcurrentRequests

默认值 10

This property sets the maximum number of requests allowed to a HystrixCommand.run() method when you are using ExecutionIsolationStrategy.SEMAPHORE.

If this maximum concurrent limit is hit then subsequent requests will be rejected.

maxQueueSize

This property sets the maximum queue size of the BlockingQueue implementation.

If you set this to -1 then SynchronousQueue will be used, otherwise a positive value will be used with LinkedBlockingQueue.

默认值 -1

hystrix-go

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
var (
    // DefaultTimeout is how long to wait for command to complete, in milliseconds
    DefaultTimeout = 1000
    // DefaultMaxConcurrent is how many commands of the same type can run at the same time
    DefaultMaxConcurrent = 10
    // DefaultVolumeThreshold is the minimum number of requests needed before a circuit can be tripped due to health
    DefaultVolumeThreshold = 20
    // DefaultSleepWindow is how long, in milliseconds, to wait after a circuit opens before testing for recovery
    DefaultSleepWindow = 5000
    // DefaultErrorPercentThreshold causes circuits to open once the rolling measure of errors exceeds this percent of requests
    DefaultErrorPercentThreshold = 50
)

type Settings struct {
    Timeout                time.Duration
    MaxConcurrentRequests  int
    RequestVolumeThreshold uint64
    SleepWindow            time.Duration
    ErrorPercentThreshold  int
}

chatgpt 问答

Q: 请求量最高 10 分钟能达到 1M, hystrix requestVolumeThreshold 应该设置为多少
A: 在请求量最高 10 分钟能达到 1M 的情况下,如果要设置requestVolumeThreshold参数,需要根据以下因素进行考虑:
系统的资源情况:如果系统的资源充足,可以适当增加requestVolumeThreshold的值,以便更好地控制系统的容错能力。
系统的稳定性和可用性:如果系统的稳定性和可用性较为重要,建议将requestVolumeThreshold的值设置为一个较小的值,以便更快地触发断路器。
断路器的阈值和时间窗口:除了requestVolumeThreshold参数之外,还需要考虑断路器的阈值和时间窗口等参数,以便更好地控制断路器的触发和恢复。
基于以上因素,建议将requestVolumeThreshold参数设置为100左右,这样可以在滚动时间窗口内快速触发断路器,以避免系统崩溃或不可用。当然,具体的值还需要根据实际情况进行调整和优化。