1. Sequence in which the configuration takes effect

  1. The following configuration priority is from low to high, that is, none of the attributes is configured, so the global default is used
  2. The following figure shows multiple configurations for a particular configuration, with different priorities

1. Global default configuration

  1. Such as timeout (execution. The isolation. Thread. TimeoutInMilliseconds) default 1000 ms, the lowest priority
  2. If the timeout period is not set in any of the following ways, the default configuration takes effect
  3. Equivalent to the Default Value shown above

2. Define the global configuration using the Properties file

Equivalent to the Default Property shown above

hystrix.command.default.execution.isolation.strategy
=1000
Copy the code

3. Instance configuration

Three ways to configure an instance

HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(int value) public HystrixCommandInstance(int id) {  super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(500))); this.id = id; } public HystrixCommandInstance(int id) { super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"), 500); this.id = id; }Copy the code

4. Dynamic configuration of instances

  1. For a particular hystrix configurations of the command, such as the following configuration hystrix.com mand. SubscriberGetAccount. Execution. The isolation. Thread. TimeoutInMilliseconds
  2. Highest priority
  3. Equivalent to the Instance Property shown above

Hystrix configuration

1. Command configuration

1.1 execution

Is used to control how hystrixcommand-run () is executed

1.1.1 execution. The isolation. The strategy
  1. Hystrix’s isolation policy
  2. The options are THREAD and SEMAPHORE. The default value is THREAD
  3. THREAD runs commands using threads from the THREAD pool, SEMAPHORE runs commands using user threads
1.1.2 execution. The isolation. Thread. TimeoutInMilliseconds

The default value is 1000ms

1.1.3 execution. A timeout. Enabled

Whether command times out. The default value is true

1.1.4 execution. The isolation. Thread. InterruptOnTimeout

Sets whether threads are allowed to interrupt when timeout is enabled. Default is true

1.1.5 execution. The isolation. Thread. InterruptOnCancel

Sets whether threads can be cancelled when interrupted. Default is true

1.1.6 execution. The isolation. Semaphore. MaxConcurrentRequests
  1. This takes effect when the isolation policy is SEMAPHORE
  2. Set the number of threads running at the same time. Default is 10

1.2 Fallback

This configuration is used to control the running of the getFallback method

1.2.1 fallback. Isolation. Semaphore. MaxConcurrentRequests

Set the maximum number of concurrent calls to the getFallback method. Default is 10

1.2.2 fallback. Enabled

Whether to allow failed transfer. The default value is true

1.3 the breaker

1.3.1 circuitBreaker.enabled

Whether to enable the circuit breaker. The default value is true

1.3.2 circuitBreaker.requestVolumeThreshold

Set the maximum number of requests in a scrolling window (10 seconds by default) beyond which the breaker will turn on. The default value is 20

1.3.3 circuitBreaker.sleepWindowInMilliseconds

Set the sleep time for re-initiating requests after the circuit breaker is turned on. The default sleep time is 5000ms

1.3.4 circuitBreaker.errorThresholdPercentage

Set the maximum percentage of errors in a scrolling window (default: 10 seconds), greater than which the breaker will turn on, default: 50%

1.3.5 circuitBreaker.forceOpen

Whether to forcibly open a circuit breaker. The default value is false

1.3.6 circuitBreaker.forceClosed

Whether to forcibly disable the circuit breaker. The default value is False

1.4 the Metrics

This part of the configuration is related to the indicator capture of command execution

1.4.1 metrics. RollingStats. TimeInMilliseconds
  1. Set the time of the scroll window for indicator calculation. The default is 10 seconds
  2. In other words, the maximum number of requests and error ratio are calculated according to the scrolling window
  3. The scrolling window is stored in buckets. For example, there are 10 buckets in every 10 seconds by default. Any bucket that exceeds the scrolling window will be invalidated

1.4.2 metrics. RollingStats. NumBuckets

Set the number of buckets to be computed by the scrolling window. The default is 10

1.4.3 metrics. RollingPercentile. Enabled

Sets whether the command call delay is calculated. The default is true

1.4.4 metrics. RollingPercentile. TimeInMilliseconds
  1. Set the size of the scroll window when calculating latency. Default is 60000ms
  2. He also does the calculation in buckets, similar to the calculation of maximum requests
1.4.5 metrics. RollingPercentile. NumBuckets

Set the number of buckets for scrolling Windows when calculating latency. Default is 6

1.4.6 metrics. RollingPercentile. BucketSize

Set the maximum bucket value in the scroll window when calculating latency. The default value is 100

1.4.7 metrics. HealthSnapshot. IntervalInMilliseconds

Calculate the interval between the current circuit breaker health status. The default interval is 500ms

1.5 the Request Context

1.5.1 requestCache.enabled

This parameter specifies whether to enable request caching. The default value is true

1.5.2 requestLog.enabled

Specifies whether to log to HystrixRequestLog. The default value is true

2. Collapser configuration

2.1 maxRequestsInBatch

Set the maximum number of requests that can be combined and sent at a time. The default value is integer.max_value

2.2 timerDelayInMilliseconds

Set the interval for sending merged requests. The default is 10ms

2.3 requestCache.enabled

Configure Collapser’s cache to take effect

3. Thread pool configuration

  1. The recommended thread pool size in Hystrix is 99th x 0.2+ idle threads, for example, 10 for the following threads
  2. The following configuration is actually a Java thread pool configuration

3.1 coreSize

Number of core threads, default is 10

3.2 maximumSize

Maximum number of threads. Default: 10

3.3 maxQueueSize

Maximum number of queues. This configuration can only be initialized once

3.4 queueSizeRejectionThreshold

Minimum number of requests rejected by the thread pool, default 5

3.5 keepAliveTimeMinutes

The length of time a thread remains idle. The default is 1 minute

3.6 allowMaximumSizeToDivergeFromCoreSize

Whether to allow the maximum thread to be larger than the core thread, i.e., to take effect. The default is false