This is the 13th day of my participation in Gwen Challenge

[a].

You may have a bad day, but that doesn’t mean you’ll have a bad life.

[Warm tips]

Following on from the previous article 🏹 [Hystrix Technical Guide] (1) Basic usage and configuration instructions

  • I recommend it heremartinfowlerFuse introduction and authoritative guide, interested partners can study ha.

  • Main introduction related: official website description

  • about[How Hystrix works]The introduction of

[Background]

  • As the scale and complexity of distributed systems increase, the requirements for availability of distributed systems become higher and higher. Among the various high availability design patterns, “fuses, isolation, downgrades, limiting” are frequently used. The related technology, Hystrix itself is not a new technology, but it is the most classic technology system! .

  • Hystrix is designed to achieve fusible downgrades, thus improving system availability.

  • Hystrix is a Java service component library that implements circuit breaker mode and hatch mode on the call side to improve system fault tolerance by avoiding cascading failures for highly available designs.

  • Hystrix implements a resource isolation mechanism

[Fuse state]

  • Closed: Closed indicates that the service caller sends each request to the service provider.

  • Open: indicates the open state, which means that the circuit breaker will be enabled if the exception rate of the service provider or the number of concurrent requests exceeds the set threshold. After the circuit breaker is enabled, all requests of the service caller will not be sent to the service provider, but directly use the local service degradation method.

  • Half – open: Hystrix also has a self-recovery mechanism, which means that when the circuit breaker of the service provider is in the open state, a time window will be opened, that is, after a certain period of time or the time for the next request is longer than the time window. Hystrix sends the request to the service provider again, changing the state to half-open on success, remaining open on failure, and refreshing the time window.

[Configuration Introduction]

Main reference: github.com/Netflix/Hys…

The previous article 🏹 [Hystrix Technical Guide] (1) Basic use and configuration mainly introduces the related use methods, as well as some related combat configuration, this article will specifically introduce the configuration.

The priority of the Hystrix property in 4

  1. Built-in Global default from code

If none of the following parameters is set, this parameter is used by default.

  1. Dynamic Global Default Property

The global default can be changed through property configuration, which is referred to as “default property”.

  1. Built-in Instance default from code

In code, the value of the property set is referred to as “instance default”.

  1. Dynamically configuring Instance Properties

Property values can be dynamically configured for specific instances instead of the previous three, which are referred to as “instance properties”.

Priority: 1 < 2 < 3 < 4

[Command properties]

execution.isolation.strategy

To set the isolation policy for hystrixCommand-run (), you have two options:

  • THREAD – In a fixed size THREAD pool, executed by a single THREAD, the number of concurrent requests is limited by the THREAD pool size.

  • SEMAPHORE – Executed in the calling thread, using semaphores to limit concurrency.

  • Default value: the THREAD (ExecutionIsolationStrategy. THREAD)

  • Optional values: THREAD, SEMAPHORE

The default properties: hystrix.com mand. Default. Execution. The isolation. The strategy instance attributes: hystrix.command.HystrixCommandKey.execution.isolation.strategyCopy the code

Example default Settings:


// to use thread isolation

HystrixCommandProperties.Setter()

.withExecutionIsolationStrategy(ExecutionIsolationStrategy.THREAD)

// to use semaphore isolation

HystrixCommandProperties.Setter()

.withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE)

Copy the code

execution.isolation.thread.timeoutInMilliseconds

Sets a TIMEOUT limit for the caller to wait for the command to execute, after which HystrixCommand is marked as TIMEOUT and the fallback logic is performed.

Note: The timeout will apply to hystrixcommand-queue () even if the caller does not call get() to get the Future object.

Default value: 1000 (ms)

Default properties: Hystrix.com mand. Default. Execution. The isolation. Thread. TimeoutInMilliseconds instance attributes: hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMillisecondsCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(int value)
Copy the code

execution.timeout.enabled

Sets whether hystrixCommand-run () is executed with a timeout limit.

  • Default value: true
The default properties: hystrix.com mand. Default. Execution. A timeout. Enabled instance attributes: hystrix.com mand. HystrixCommandKey. Execution. A timeout. EnabledCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withExecutionTimeoutEnabled(boolean value)
Copy the code

execution.isolation.thread.interruptOnTimeout

Sets whether execution of hystrixCommand-run () is interrupted when a timeout occurs.

  • Default value: true
The default properties: hystrix.com mand. Default. Execution. The isolation. Thread. InterruptOnTimeout instance attributes: hystrix.command.HystrixCommandKey.execution.isolation.thread.interruptOnTimeoutCopy the code

Example default Settings:

HystrixCommandProperties.Setter()
.withExecutionIsolationThreadInterruptOnTimeout(boolean value)
Copy the code

execution.isolation.thread.interruptOnCancel

Set execution of hystrixCommand-run () but can respond to interrupts when the cancel action occurs.

  • Default value: false
The default properties: hystrix.com mand. Default. Execution. The isolation. Thread. InterruptOnCancel instance attributes: hystrix.command.HystrixCommandKey.execution.isolation.thread.interruptOnCancelCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withExecutionIsolationThreadInterruptOnCancel(boolean value)
Copy the code

execution.isolation.semaphore.maxConcurrentRequests

Set when using ExecutionIsolationStrategy. SEMAPHORE, HystrixCommand. The run () method allows the maximum number of requests. If the maximum number of concurrent requests is reached, subsequent requests will be rejected.

The semaphore should be a small part of the container (such as Tomcat) thread pool, not equal to or slightly smaller than the container thread pool size, otherwise it will not be protected.

  • Default value: 10
The default properties: hystrix.com mand. Default. Execution. The isolation. The semaphore. MaxConcurrentRequests instance attributes: hystrix.command.HystrixCommandKey.execution.isolation.semaphore.maxConcurrentRequestsCopy the code

Example default Settings:

HystrixCommandProperties.Setter()
.withExecutionIsolationSemaphoreMaxConcurrentRequests(int value)
Copy the code

The fallback method

The following attributes control HystrixCommand. GetFallback (). These properties of ExecutionIsolationStrategy. THREAD and ExecutionIsolationStrategy. SEMAPHORE are effective.

fallback.isolation.semaphore.maxConcurrentRequests

Set HystrixCommand produced by the calling thread. The getFallback () method allows the maximum number of requests. If the maximum number of concurrent requests is reached, subsequent requests are rejected, and if no rollback is implemented, an exception is thrown.

  • Default value: 10
The default properties: hystrix.com mand. Default. The fallback. Isolation. Semaphore. MaxConcurrentRequests instance attributes: hystrix.command.HystrixCommandKey.fallback.isolation.semaphore.maxConcurrentRequestsCopy the code

Example default:

HystrixCommandProperties.Setter()
.withFallbackIsolationSemaphoreMaxConcurrentRequests(int value)
Copy the code

fallback.enabled

This attribute decision when fault or refuse to occur, a call will try HystrixCommand. GetFallback ().

  • Default value: true
The default properties: hystrix.com mand. Default. The fallback. Enabled instance attributes: hystrix.com mand. HystrixCommandKey. Fallback. EnabledCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withFallbackEnabled(boolean value)
Copy the code

Circuit Breaker

circuitBreaker.enabled

Set whether the circuit breaker works.

  • Default value: true
Default attributes: hystrix.com mand. Default. The circuitBreaker. Enabled instance attributes: hystrix.com mand. HystrixCommandKey. CircuitBreaker. EnabledCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withCircuitBreakerEnabled(boolean value)
Copy the code

circuitBreaker.requestVolumeThreshold

Set the minimum number of requests to open circuit breakers in a scrolling window.

For example, if the value is 20 and 19 requests are received within a window (say 10 seconds), the breaker will not open even if all 19 requests fail.

Default value: 20

The default properties: hystrix.com mand. Default. The circuitBreaker. RequestVolumeThreshold instance attributes: hystrix.command.HystrixCommandKey.circuitBreaker.requestVolumeThresholdCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(int value)
Copy the code

circuitBreaker.sleepWindowInMilliseconds

Set the time between when the loop is opened, reject the request, and retry the request and decide whether the loop should remain open.

  • Default: 5000 (ms)
The default properties: hystrix.com mand. Default. The circuitBreaker. SleepWindowInMilliseconds instance attributes: hystrix.command.HystrixCommandKey.circuitBreaker.sleepWindowInMillisecondsCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withCircuitBreakerSleepWindowInMilliseconds(int value)
Copy the code

circuitBreaker.errorThresholdPercentage

Sets the error rate for opening the loop and starting the fallback logic.

  • Default value: 50
The default properties: hystrix.com mand. Default. The circuitBreaker. ErrorThresholdPercentage instance attributes: hystrix.command.HystrixCommandKey.circuitBreaker.errorThresholdPercentageCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withCircuitBreakerErrorThresholdPercentage(int value)
Copy the code

circuitBreaker.forceOpen

If this property is set to true, the force breaker is turned on and all requests are rejected.

This property priority than circuitBreaker forceClosed high.

  • Default value: false
The default properties: hystrix.com mand. Default. The circuitBreaker. ForceOpen instance attributes: hystrix.com mand. HystrixCommandKey. CircuitBreaker. ForceOpenCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withCircuitBreakerForceOpen(boolean value)
Copy the code

circuitBreaker.forceClosed

If this property is set to true, the force breaker enters the off state, allowing all requests regardless of the error rate.

  • Default value: false
The default properties: hystrix.com mand. Default. The circuitBreaker. ForceClosed instance attributes: hystrix.command.HystrixCommandKey.circuitBreaker.forceClosedCopy the code

Example Default Settings

HystrixCommandProperties.Setter().withCircuitBreakerForceClosed(boolean value)
Copy the code

Request context

requestCache.enabled

Set HystrixCommand. GetCacheKey () whether to enable by HystrixRequestCache by offering to repeat the request cache data function.

  • Default value: true
The default properties: hystrix.com mand. Default. RequestCache. Enabled instance attributes: hystrix.com mand. HystrixCommandKey. RequestCache. EnabledCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withRequestCacheEnabled(boolean value)
Copy the code

requestLog.enabled

Sets whether HystrixCommand executions and events should be logged to the HystrixRequestLog.

Default value: true

The default properties: hystrix.com mand. Default. The requestLog. Enabled instance attributes: hystrix.com mand. HystrixCommandKey. RequestLog. EnabledCopy the code

Example default Settings:

HystrixCommandProperties.Setter().withRequestLogEnabled(boolean value)
Copy the code

Compressor properties

The following properties control the HystrixCollapser behavior.

maxRequestsInBatch

Sets the maximum number of requests allowed in a batch before triggering execution.

  • Default value: integer.max_value
Default attributes: hystrix collapser. Default. MaxRequestsInBatch instance attributes: hystrix. Collapser. HystrixCollapserKey. MaxRequestsInBatchCopy the code

Example Default Settings

HystrixCollapserProperties.Setter().withMaxRequestsInBatch(int value)
Copy the code

timerDelayInMilliseconds

Sets the number of milliseconds between batch creation and execution.

  • Default value: 10
The default properties: hystrix collapser. Default. TimerDelayInMilliseconds instance attributes: hystrix.collapser.HystrixCollapserKey.timerDelayInMillisecondsCopy the code

Example Default Settings

HystrixCollapserProperties.Setter().withTimerDelayInMilliseconds(int value)
Copy the code

requestCache.enabled

Set whether request caching works on calls to hystrixcollapser.execute () and hystrixcollapser.queue ().

  • Default value: true
Default attributes: hystrix collapser. Default. RequestCache. Enabled instance attributes: hystrix. Collapser. HystrixCollapserKey. RequestCache. EnabledCopy the code

Example Default Settings

HystrixCollapserProperties.Setter().withRequestCacheEnabled(boolean value)
Copy the code

Thread pool properties

coreSize

Set the core thread pool size.

  • Default value: 10
Default attributes: hystrix threadpool. Default. CoreSize instance attributes: hystrix. Threadpool. HystrixThreadPoolKey. CoreSizeCopy the code

Example default Settings:

HystrixThreadPoolProperties.Setter().withCoreSize(int value)
Copy the code

maximumSize

1.5.9 Added Properties to set the maximum value of the thread pool. This is the maximum number of concurrent requests that can be supported without starting to reject HystrixCommand. This property is the premise of work set up allowMaximumSizeToDrivergeFromCoreSize. Before 1.5.9, the core thread pool size and the maximum thread pool size were always the same.

maxQueueSize

Sets the maximum queue value of BlockingQueue.

  • If set to -1, SynchronousQueue is used, otherwise positive numbers will be LinkedBlockingQueue.

  • If you need to remove these restrictions, allowing the queue dynamic change, you can refer to queueSizeRejectionThreshold properties.

Modifying SynchronousQueue and LinkedBlockingQueue requires a restart.

Default value: -1

Default attributes: hystrix threadpool. Default. MaxQueueSize instance attributes: hystrix. Threadpool. HystrixThreadPoolKey. MaxQueueSizeCopy the code

Example default Settings:

HystrixThreadPoolProperties.Setter().withMaxQueueSize(int value)
Copy the code

queueSizeRejectionThreshold

Set queue rejection threshold – the maximum queue value that a person sets to deny access, even if maxQueueSize has not yet been reached.

HystrixCommand uses this property when a thread is queued for execution.

Note: If maxQueueSize is set to -1, this property is not available.

  • Default value: 5
The default properties: hystrix threadpool. Default. QueueSizeRejectionThreshold instance attributes: hystrix.threadpool.HystrixThreadPoolKey.queueSizeRejectionThresholdCopy the code

Example default Settings:

HystrixThreadPoolProperties.Setter().withQueueSizeRejectionThreshold(int value)
Copy the code

keepAliveTimeMinutes

Set the keepalive time, in minutes. If coreSize is less than maximumSize, this property controls the time a thread takes from utility completion to release.

  • Default value: 1
Default attributes: hystrix threadpool. Default. KeepAliveTimeMinutes instance attributes: hystrix. Threadpool. HystrixThreadPoolKey. KeepAliveTimeMinutesCopy the code

Example default Settings:

HystrixThreadPoolProperties.Setter().withKeepAliveTimeMinutes(int value)
Copy the code

allowMaximumSizeToDivergeFromCoreSize

Properties added in 1.5.9. This property allows maximumSize to take effect. Property value can be equal to or greater than the coreSize value. A thread pool whose coreSize is less than maximumSize supports the concurrency of maximumSize, but returns inactive threads to the system. (see KeepAliveTimeMinutes)

Default value: false

The default properties: hystrix threadpool. Default. AllowMaximumSizeToDivergeFromCoreSize

Instance attributes: hystrix threadpool. HystrixThreadPoolKey. AllowMaximumSizeToDivergeFromCoreSize

Instance of the default Settings: HystrixThreadPoolProperties. Setter ()

.withAllowMaximumSizeToDivergeFromCoreSize(boolean value)

metrics.rollingStats.timeInMilliseconds

Set the size of the time period for the statistics scroll window. This property is the length of time the thread pool holds the indicator.

Default value: 10000 (ms)

Default attributes: hystrix threadpool. Default. The metrics. RollingStats. TimeInMilliseconds

Instance attributes: hystrix threadpool. HystrixThreadPoolKey. Metrics. RollingStats. TimeInMilliseconds

Instance of the default Settings: HystrixThreadPoolProperties. Setter ()

.withMetricsRollingStatisticalWindowInMilliseconds(int value)

metrics.rollingStats.numBuckets

Sets the number of buckets that the scrolling statistics window is split into.

Note: “the metrics. RollingStats. TimeInMilliseconds % metrics. The rollingStats. NumBuckets = = 0” must be true, otherwise it will throw an exception.

Default value: 10

Possible values: any can be metrics. RollingStats. TimeInMilliseconds aliquot of values.

Default attributes: hystrix threadpool. Default. The metrics. RollingStats. NumBuckets

Instance attributes: hystrix threadpool. HystrixThreadPoolProperties. Metrics. RollingStats. NumBuckets

Instance of the default Settings: HystrixThreadPoolProperties. Setter ()

.withMetricsRollingStatisticalWindowBuckets(int value)