Detailed explanation of Spring Cloud Hystrix Command attributes

Preface

When we use springcloud, we will inevitably use Hystrix. Let's make a note on the attribute configuration;

Configuration

There are mainly the following types of attribute configuration:

The configuration prefix is hystrix.command.default

Execution configuration:

  • execution.isolation.strategy : This attribute is used to set the execution isolation strategy, there are two options as follows:

    • THREAD : through the thread pool isolation strategy, execute on a separate thread, and its concurrency limit is limited by the number of threads in the thread pool (default)
    • SEMAPHONE : Through the strategy of semaphore isolation, it is executed on the calling thread, and its concurrency limit is limited by the semaphore count.
  • execution.isolation.thread.timeoutInMilliseconds : This property is used to configure the timeout time of HystrixCommand execution, the unit is milliseconds, the default value is 1000, beyond this time configuration, Hystrix will execute the command as TIMEOUT and enter the service degradation processing logic
  • execution.timeout.enabled : This property is used to configure whether the HystrixCommand execution starts timeout, the default value is true, if it is set to false, the configuration of the execution.isolation.thread.timeoutInMilliseconds property will not work
  • execution.isolation.thread.interruptOnTimeout : This property is used to configure whether HystrixCommand needs to be interrupted when the execution of HystrixCommand times out, the default value is true
  • execution.isolation.semaphore.maxConcurrentRequests : When the isolation strategy uses a semaphore, this property is used to configure the size of the semaphore. When the maximum number of concurrent requests reaches the set value, subsequent requests will be rejected

fallback placement:

  • fallback.enabled : This property is used to set whether the service degradation policy is enabled, the default value is true, if it is set to false, when the request fails or rejection occurs, HystrixCommand.getFallback() will not be called to execute the service degradation logic

circuitBreaker configuration:

  • circuitBreaker.enabled : This attribute is used to determine whether to use a circuit breaker to track its health indicators and fusing requests when the service request command fails, the default value is true
  • circuitBreaker.requestVolumeThreshold : This attribute is used to set the minimum number of circuit breaker requests in the rolling time window. For example: with the default value of 20, if only 19 requests are received within the rolling time window (the default value is 10 seconds), even if all 19 requests fail, the circuit breaker will not open.
  • circuitBreaker.sleepWindowInMilliseconds : This property is used to set the sleep time window after the circuit breaker is opened. The default value is 5000 milliseconds. After the sleep time window ends, the circuit breaker will be set to the "half open" state, and the request command for fusing will be tried. If it still fails, the circuit breaker will continue to be set to the "open" state, and if it succeeds, it will be set to " Disabled.
  • circuitBreaker.errorThresholdPercentage : This attribute is used to set the error percentage condition for opening the circuit breaker. For example, when the default value is 50, it means that in the rolling time window, if the number of requests exceeds the threshold of circuitBreaker.requestVolumeThreshold, if the percentage of the number of error requests exceeds 50, the circuit breaker is set to the "open" state, otherwise Set it to the "off" state.
  • circuitBreaker.forceOpen : This attribute is used to set the circuit breaker to be forced to enter the "open" state, and all requests will be rejected. This attribute has priority over circuitBreaker.forceClosed
  • circuitBreaker.forceClosed : This attribute is used to set the circuit breaker to be forced to enter the "closed" state, and all requests will be received.

Metrics configuration:

This configuration property is related to the capture of indicator information during the execution of HystrixCommand and HystrixObservableCommand

  • metrics.rollingStats.timeInMilliseconds : This attribute is used to set the length of the rolling time window, in milliseconds. This time is used for the duration of information collected when the circuit breaker judges the health. The default value is 10000. When the circuit breaker value collects indicator information, it will be divided into multiple "buckets" according to the length of the set time window to accumulate various metric values, and each "bucket" records the collected indicators over a period of time.
  • metrics.rollingStats.numBuckets : This attribute is used to set the number of "buckets" when rolling time window statistical indicator information, the default value is 10. The setting of metrics.rollingStats.timeInMilliseconds parameter must be divisible by this parameter, otherwise an exception will be thrown.

    metrics.rollingPercentile.enabled: This attribute is used to set whether to use percentiles to track and calculate the delay of command execution. The default value is true. If it is set to false, all summary statistics will return -1

  • metrics.rollingPercentile.timeInMilliseconds : This attribute is used to set the duration of the rolling window for percentile statistics, unit: milliseconds, the default value is 60000
  • metrics.rollingPercentile.numBuckets : This attribute is used to set the number of "buckets" used in the percentile statistics window, the default value is 6
  • metrics.rollingPercentile.bucketSize : This attribute is used to set the maximum number of executions retained in each "bucket" during the execution process. If the number of executions exceeding the set value occurs in the rolling time window, restart from the initial position Write, for example: set to 100, the rolling window is 10 seconds, if 500 executions occur in a "bucket" within 10 seconds, then only the statistics of the last 100 executions are kept in the "bucket", the default value is 100
  • metrics.healthSnapshot.intervalInMilliseconds : This attribute is used to set the interval waiting time for collecting health snapshots (requested success and error percentages) that affect the state of the circuit breaker, the default value is 500

requestContext configuration:

  • requestCache.enabled : This attribute is used to configure whether to enable request caching
  • requestLog.enabledg : This attribute is used to set whether the execution of HystrixCommand and events are printed to HystrixRequestLog, the default value is true

The configuration prefix is hystrix.collapser.default

  • maxRequestsInBatch : This attribute is used to set the maximum number of requests allowed in one request merge batch, the default value is Integer.MAX_VALUE
  • timerDelayInMilliseconds : This attribute is used to set the delay time of each command in the batch process, in milliseconds, the default value is 10.
  • requestCache.enabled : This attribute is used to set whether to enable request caching during batch processing, the default value is true

The configuration prefix is hystrix.threadpool.default

  • coreSize : This attribute is used to set the number of core threads in the command thread pool. This value is the maximum concurrent command execution. The default value is 10
  • maxQueueSize : This attribute is used to set the maximum queue size of the thread pool. When set to -1, the thread pool will use the queue implemented by SynchronousQueue, otherwise it will use the queue implemented by LinkedBlockingQueue, the default value is -1
  • queueSizeRejectionThreshold : This attribute is used to set the rejection threshold for the queue. Requests can be rejected even if the queue does not reach the maximum value. This attribute is mainly a supplement to the LinkedBlockingQueue queue. The default value is 5. When the maxQueueSize attribute is -1, this attribute is invalid
  • metrics.rollingPercentile.timeInMilliseconds : This attribute is used to set the duration of the rolling window of thread pool statistics, unit: milliseconds, the default value is 10000
  • metrics.rollingPercentile.numBuckets : This attribute is used to set the number of "buckets" used in the thread pool statistics window, the default value is 10

(Finish)

Guess you like

Origin blog.csdn.net/qq_36850813/article/details/102816065