Fusing parameter configuration of HystrixCommandProperties

The following is the fuse parameter configuration of HystrixCommandProperties.
HystrixCommandProperties.Setter commandProperties =HystrixCommandProperties.Setter()
......
.withCircuitBreakerEnabled(true)//default is true
.withCircuitBreakerForceClosed(false)//default is false
.withCircuitBreakerForceOpen(false)//default is false
.withCircuitBreakerErrorThresholdPercentage(50)//default 50%
.withCircuitBreakerRequestVolumeThreshold(20) //The default is 20
.withCircuitBreakerSleepWindowInMilliseconds(5000)//The default is 5s
The specific configuration meaning is as follows.
withCircuitBreakerEnabled: Whether to enable the circuit breaker mechanism, the default is true.
withCircuitBreakerForceClosed: Whether the fuse switch is forcibly closed. If the fuse switch is forcibly closed, the request will not be downgraded. In some special scenarios, this switch can be dynamically configured. The default is false.
withCircuitBreakerForceOpen: Whether to force open the fuse switch, if the fuse switch is forced to open, the request is forced to downgrade and call getFallback processing, which can be opened by dynamic configuration to achieve some special requirements, the default is false.
withCircuitBreakerErrorThresholdPercentage: If the failure rate exceeds this configuration within a sampling time window, the fuse switch will be automatically turned on to implement downgrade processing, that is, fast failure. The default configuration downsampling period is 10s, and the failure rate is 50%.
withCircuitBreakerRequestVolumeThreshold: When the fuse is disconnected and closed, before the failure rate judgment is made, at least N requests must be made in a sampling period to perform sampling statistics. The purpose is to have enough sampling to make the failure rate calculation correct. The default is 20.
withCircuitBreakerSleepWindowInMilliseconds: The retry time window after circuit breaker, and only one retry is allowed within this time window. That is, after the fuse switch is turned on, one retry is allowed in this time window. If the retry is successful, the Health sampling statistics will be reset and the fuse switch will be closed to achieve fast recovery. Otherwise, the fuse switch will remain open and the execution will fail quickly.
After the fuse, it will downgrade and call getFallback for processing (fallbackEnabled=true). You can judge whether the fuse is blown through the following method of Command.
isCircuitBreakerOpen: Whether the fuse switch is open is judged by "circuitBreakerForceOpen().get()|| (!circuitBreakerForceClosed().get() && circuitBreaker.isOpen())".
isResponseShortCircuited: isCircuitBreakerOpen=true, and returns true when getFallback is called.
3 Sampling statistics
Hystrix stores sampling data in memory, and supports the following two kinds of sampling.
BucketedCounterStream: Counting statistics, such as recording the number of failures, timeouts, thread pool rejections, and semaphore rejections within a certain time window, recording N groups. When writing data, it is written to the Nth group, and the first N-1 groups of data are used for statistics, because the Nth group changes at any time when statistics are first started. Then the sampling grouping can be rolled based on time.

The rollover time window for sampling statistics is 10s, with 1 packet (bucket) per second, that is, sampling once per second. Each packet records the statistics of the current bucket's success, failure, timeout, and thread rejection.
RollingConcurrencyStream: Statistics of the maximum concurrency, such as the maximum concurrency of Command/ThreadPool.
RollingDistributionStream: Delay percentage statistics, similar to HystrixRollingNumber, the difference is that it is a percentile statistics. For example, each group records P (such as 100) values, the first N-1 groups of data are used for statistics, the data in the group are sorted from small to large, and then accumulated, the value at the p-th position is the p percentile, through It can implement P50, P99, and P999, and Hystrix is ​​used to count the distribution of delays. The latest version of Hystrix uses the HdrHistogram library for statistics.
3.1 Command, ThreadPool count/maximum concurrent sampling statistics
HystrixThreadPoolProperties.Setter threadPoolProperties = HystrixThreadPoolProperties.Setter()
 …
.withMetricsRollingStatisticalWindowInMilliseconds(1000)
.withMetricsRollingStatisticalWindowBuckets(10);
HystrixCommandProperties.Setter commandProperties =HystrixCommandProperties.Setter()
...
.withMetricsRollingStatisticalWindowInMilliseconds(10000)
.withMetricsRollingStatisticalWindowBuckets(10);
withMetricsRollingStatisticalWindowBuckets(10); withMetricsRollingStatisticalWindow
withMetricsRollingStatisticalWindowBuckets: Configure the total number of buckets in the rollover time window to be used for statistics. The default is 10. For example, if the time window is 10000 and the number of buckets is 10, the sampling statistics interval is one bucket per second.
3.2 Command health sampling statistics
HystrixCommandProperties.Setter commandProperties =HystrixCommandProperties.Setter()
……
.withMetricsRollingStatisticalWindowInMilliseconds(10000)
.withMetricsHealthSnapshotIntervalInMilliseconds(500);
withMetricsRollingStatisticalWindowInMilliseconds: Same as above.
withMetricsHealthSnapshotIntervalInMilliseconds: The snapshot frequency for recording health usage statistics, the default is 500ms, that is, a sampling statistics interval of 500ms, then the number of buckets is 10000/500=20.
This statistic is used in the fusing mechanism. If the frequency of calculating fusing is very high, the sampling frequency should be controlled. If it is too frequent, the CPU will be computationally intensive, such as a cycle of 10ms, because the first N-1 buckets will be processed. Statistics, the calculation and accumulation will consume CPU. So choose Hystrix to pay attention to the performance consumption and tuning here. If this is the performance bottleneck, you can scrap the statistics, or implement your own downgraded components according to the Hystrix idea.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326332546&siteId=291194637