Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A complete set of Hystrix attributes

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Overview

In this paper, the coverage priority of Hystrix configuration parameters, the types of configurable parameters and configuration items are introduced in detail.

The following types of properties can be configured by Hystrix:

Execution: controls how HystrixCommand.run () is executed

Fallback: controls how HystrixCommand.getFallback () executes

Circuit Breaker: control the behavior of circuit breakers

Metrics: captures configuration properties related to HystrixCommand and HystrixObservableCommand execution information

Request Context: sets the properties of the request context

Collapser Properties: sets the properties for requesting a merge

Thread Pool Properties: setting the properties of a thread pool

Override priority of the Hystrix parameter

Each Hystrix parameter can be configured in four places, and the priority is as follows from low to high. If the same attribute is configured everywhere, the high priority value will override the low priority value.

1 built-in global default value: the value written in the code

2 dynamic global default properties: configure global values through a properties file

3 default value of built-in instance: the value of the instance written in the code

4 dynamically configure instance properties: configure the value of a specific instance through the properties file

3 detailed explanation of Hystrix configuration properties

The following types of properties can be configured by Hystrix:

Execution: controls how HystrixCommand.run () is executed

Fallback: controls how HystrixCommand.getFallback () executes

Circuit Breaker: control the behavior of circuit breakers

Metrics: captures configuration properties related to HystrixCommand and HystrixObservableCommand execution information

Request Context: sets the properties of the request context

Collapser Properties: sets the properties for requesting a merge

Thread Pool Properties: setting the properties of a thread pool

3.1. Execution

The following properties control how HystrixCommand.run () is executed

Execution.isolation.strategy

Represents the isolation policy for the execution of HystrixCommand.run (), which has the following two strategies

1 THREAD: executes on separate threads, and concurrent requests are limited by the number of threads in the thread pool

2 SEMAPHORE: executes on the calling thread, and concurrent requests are limited by semaphore count

By default, it is recommended that HystrixCommands use thread quarantine policy and HystrixObservableCommand use semaphore quarantine policy.

It is only for calls with high concurrency (hundreds of calls per second for a single instance) that you need to change HystrixCommands's isolation policy to semaphore. Semaphore isolation policies are usually only used for non-network calls

Default value: THREAD

/ / set default values for all instances

Hystrix.command.default.execution.isolation.strategy=..

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.execution.isolation.strategy=...

Execution.isolation.thread.timeoutInMilliseconds

Set the timeout time that the caller executes (in milliseconds)

Default value: 1000

/ / set default values for all instances

Hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds=...

Execution.timeout.enabled

Indicates whether the timeout setting is turned on.

Default value: true

/ / set default values for all instances

Hystrix.command.default.execution.timeout.enabled=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.execution.timeout.enabled=...

Execution.isolation.thread.interruptOnTimeout

Indicates whether the setting interrupts the execution of HystrixCommand.run () when it times out

Default value: true

/ / set default values for all instances

Hystrix.command.default.execution.isolation.thread.interruptOnTimeout=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.execution.isolation.thread.interruptOnTimeout=...

Execution.isolation.thread.interruptOnCancel

Indicates whether the setting interrupts the execution of HystrixCommand.run () when canceling task execution

Default value: false

/ / set default values for all instances

Hystrix.command.default.execution.isolation.thread.interruptOnCancel=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.execution.isolation.thread.interruptOnCancel

Execution.isolation.semaphore.maxConcurrentRequests

When HystrixCommand.run () uses SEMAPHORE's isolation policy, set the maximum concurrency

Default value: 10

/ / set default values for all instances

Hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.execution.isolation.semaphore.maxConcurrentRequests=...

3.2. Fallback

The following properties control how HystrixCommand.getFallback () is executed. These attributes work on both the isolation policy THREAD and SEMAPHORE.

Fallback.isolation.semaphore.maxConcurrentRequests

This property sets the maximum number of concurrent requests allowed from the calling thread to the HystrixCommand.getFallback () method

If the maximum concurrency is reached, the next request will be rejected and an exception will be thrown.

Default value: 10

/ / set default values for all instances

Hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.fallback.isolation.semaphore.maxConcurrentRequests=...

one

two

three

four

Fallback.enabled

Whether to enable the fallback function

Default value: true

/ / set default values for all instances

Hystrix.command.default.fallback.enabled=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.fallback.enabled=...

3.3. Circuit Breaker

Control the behavior of circuit breakers

1. CircuitBreaker.enabled

Whether to turn on the circuit breaker function

Default value: true

/ / set default values for all instances

Hystrix.command.default.circuitBreaker.enabled=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.circuitBreaker.enabled=...

CircuitBreaker.requestVolumeThreshold

This property sets the minimum number of requests in the scrolling window that will trip the circuit breaker

If this property value is 20, the circuit breaker will not be turned on if only 19 requests are received and all of them fail during the window time (for example, within 10s).

Default value: 20

/ / set default values for all instances

Hystrix.command.default.circuitBreaker.requestVolumeThreshold=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.circuitBreaker.requestVolumeThreshold=...

one

two

three

four

five

3. CircuitBreaker.sleepWindowInMilliseconds

After the circuit breaker tripped, within the time of this value, the hystrix will reject the new request, and only after this time will the circuit breaker open the gate.

Default value: 5000

/ / set default values for all instances

Hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.circuitBreaker.sleepWindowInMilliseconds=...

CircuitBreaker.errorThresholdPercentage

Sets the threshold for the percentage of failures. If the failure ratio exceeds this value, the circuit breaker trips and enters the fallback logic

Default value: 50

/ / set default values for all instances

Hystrix.command.default.circuitBreaker=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.circuitBreaker.errorThresholdPercentage=...

CircuitBreaker.forceOpen

If true is set, all requests will be rejected if the circuit breaker is forced to trip. This value overrides the value of circuitBreaker.forceClosed

Default value: false

/ / set default values for all instances

Hystrix.command.default.circuitBreaker.forceOpen=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.circuitBreaker.forceOpen=...

CircuitBreaker.forceClosed

If true is set, the circuit breaker is forced to turn off, and all requests are allowed to be executed, regardless of whether the number of failures reaches the circuitBreaker.errorThresholdPercentage value.

Default value: false

/ / set default values for all instances

Hystrix.command.default.circuitBreaker.forceClosed=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.circuitBreaker.forceClosed=...

3.4. Metrics

Capture configuration properties related to HystrixCommand and HystrixObservableCommand execution information

Metrics.rollingStats.timeInMilliseconds

Set the time length of the statistical scrolling window

If the value is 10s and the window is divided into 10 buckets, each bucket represents a time of 1s, the statistics are as follows:

Default value: 10000

/ / set default values for all instances

Hystrix.command.default.metrics.rollingStats.timeInMilliseconds=10000

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.metrics.rollingStats.timeInMilliseconds=10000

Metrics.rollingStats.numBuckets

Set the number of buckets in the statistical scrolling window

Note: the following configuration must be true, otherwise an exception will be thrown.

Metrics.rollingStats.timeInMilliseconds% metrics.rollingStats.numBuckets = = 0

one

For example, 10000Universe 10 and 10000lap20 are the correct configuration, but 10000Universe is wrong.

In highly concurrent environments, the length of time per barrel is recommended to be greater than 100ms

Default value: 10

/ / set default values for all instances

Hystrix.command.default.metrics.rollingStats.numBuckets=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.metrics.rollingStats.numBuckets=...

Metrics.rollingPercentile.enabled

Sets whether the execution delay is tracked and counted in the percentage of failure. If set to false, all statistics return-1

Default value: true

/ / set default values for all instances

Hystrix.command.default.metrics.rollingPercentile.enabled=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.metrics.rollingPercentile.enabled=...

Metrics.rollingPercentile.timeInMilliseconds

This property sets the duration of the statistical scrolling percentage window

Default value: 60000

/ / set default values for all instances

Hystrix.command.default.metrics.rollingPercentile.timeInMilliseconds=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.metrics.rollingPercentile.timeInMilliseconds=...

Metrics.rollingPercentile.numBuckets

Set the number of buckets in the statistical scrolling percentage window

Note: the following configuration must be true, otherwise an exception will be thrown.

Metrics.rollingPercentile.timeInMilliseconds% metrics.rollingPercentile.numBuckets = = 0

one

For example, 60000Universe 6, 60000Universe 60 is the correct configuration, but 10000 Universe is incorrect.

In highly concurrent environments, the length of time per barrel is recommended to be greater than 1000ms

Default value: 6

/ / set default values for all instances

Hystrix.command.default.metrics.rollingPercentile.numBuckets=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.metrics.rollingPercentile.numBuckets=...

Metrics.rollingPercentile.bucketSize

This property sets the maximum execution time saved for each bucket. If the number of barrels is 100s, the statistics window is 10s. If there are 500execution times in these 10s, only the last 100th execution will be counted in bucket.

Default value: 100

/ / set default values for all instances

Hystrix.command.default.metrics.rollingPercentile.bucketSize=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.metrics.rollingPercentile.bucketSize=...

Metrics.healthSnapshot.intervalInMilliseconds

Sampling interval

Default value: 500

/ / set default values for all instances

Hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.metrics.healthSnapshot.intervalInMilliseconds=...

3.5. Request Context

This property controls the context of the Hystrix used by HystrixCommand

RequestCache.enabled

Whether to enable the request caching function

Default value: true

/ / set default values for all instances

Hystrix.command.default.requestCache.enabled=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.requestCache.enabled=...

RequestLog.enabled

Indicates whether to turn on the log, and prints the situation and events of HystrixCommand execution

Default value: true

/ / set default values for all instances

Hystrix.command.default.requestLog.enabled=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.command.HystrixCommandKey.requestLog.enabled=...

3.6. Collapser Properties###

Set the properties that request a merge

MaxRequestsInBatch

Set the maximum number of requests executed in batch at the same time

Default value: Integer.MAX_VALUE

/ / set default values for all instances

Hystrix.collapser.default.maxRequestsInBatch=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.collapser.HystrixCollapserKey.maxRequestsInBatch=...

TimerDelayInMilliseconds

How long will it take to create the batch before triggering the real request

Default value: 10

/ / set default values for all instances

Hystrix.collapser.default.timerDelayInMilliseconds=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.collapser.HystrixCollapserKey.timerDelayInMilliseconds=...

RequestCache.enabled

Whether to turn on request caching for HystrixCollapser.execute () and HystrixCollapser.queue ()

Default value: true

/ / set default values for all instances

Hystrix.collapser.default.requestCache.enabled=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.collapser.HystrixCollapserKey.requestCache.enabled=...

3.7. Thread Pool Properties

Set the thread pool behavior of Hystrix Commands, and in most cases the number of threads is 10.

The formula for calculating the number of thread pools is as follows:

Number of requests per second at peak x 99% command execution time + respite

one

The main principle for setting the number of thread pools is to keep the thread pool as small as possible, because it is the main tool to lighten the load and prevent resources from being blocked in the event of a delay.

CoreSize

Sets the size of the core of the thread pool

Default value: 10

/ / set default values for all instances

Hystrix.threadpool.default.coreSize=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.threadpool.HystrixThreadPoolKey.coreSize=...

MaximumSize

Sets the size of the largest thread pool, which works only when allowMaximumSizeToDivergeFromCoreSize is set

Default value: 10

/ / set default values for all instances

Hystrix.threadpool.default.maximumSize=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.threadpool.HystrixThreadPoolKey.maximumSize=...

one

two

three

four

MaxQueueSize

Sets the value of the largest BlockingQueue queue. If you set-1, the SynchronousQueue queue is used, and if you set a positive number, the LinkedBlockingQueue queue is used

Default value:-1

/ / set default values for all instances

Hystrix.threadpool.default.maxQueueSize=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.threadpool.HystrixThreadPoolKey.maxQueueSize=...

QueueSizeRejectionThreshold

Because the maxQueueSize value cannot be dynamically modified, you can dynamically modify the waiting queue length by setting this value. That is, when the number of queues waiting is greater than queueSizeRejectionThreshold (but the maxQueueSize value is not reached), subsequent requests are denied entry to the queue.

If you set-1, the property has no effect.

Default value: 5

/ / set default values for all instances

Hystrix.threadpool.default.queueSizeRejectionThreshold=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.threadpool.HystrixThreadPoolKey.queueSizeRejectionThreshold=...

KeepAliveTimeMinutes

After setting how long a thread is out of service, you need to release (maximumSize-coreSize) a thread.

Default value: 1

/ / set default values for all instances

Hystrix.threadpool.default.keepAliveTimeMinutes=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.threadpool.HystrixThreadPoolKey.keepAliveTimeMinutes=...

6. AllowMaximumSizeToDivergeFromCoreSize

MaximumSize works only when the allowMaximumSizeToDivergeFromCoreSize value is set to true.

Default value: false

/ / set default values for all instances

Hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize=....

/ / set the value of this property for instance HystrixCommandKey

Hystrix.threadpool.HystrixThreadPoolKey.allowMaximumSizeToDivergeFromCoreSize=...

Metrics.rollingStats.timeInMilliseconds

Set the time to scroll the window

Default value: 10000

/ / set default values for all instances

Hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.threadpool.HystrixThreadPoolKey.metrics.rollingStats.timeInMilliseconds=...

Metrics.rollingStats.numBuckets

Sets the number of buckets divided into scrolling static windows

The configured value must meet the following conditions:

Metrics.rollingStats.timeInMilliseconds% metrics.rollingStats.numBuckets = = 0

one

Default value: 10

It is recommended that the length of time of each barrel is greater than 100ms

/ / set default values for all instances

Hystrix.threadpool.default.metrics.rollingStats.numBuckets=...

/ / set the value of this property for instance HystrixCommandKey

Hystrix.threadpool.HystrixThreadPoolProperties.metrics.rollingStats.numBuckets=...

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report