Skip to content

Configure Hystrix

Wuyi Chen edited this page May 7, 2019 · 9 revisions

Overview

This page will cover several topics about Hystrix configuration:


Configure at Different Levels

You can apply your configuration at different Levels:

  • Class level
  • Function level

Apply at Class Level

Annotate the class with the @DefaultProperties annotation. So all the functions annotated by the @HystrixCommand annotation will share the same configuration. For example

@DefaultProperties(
    commandProperties={@HystrixProperty(
        name="execution.isolation.thread.timeoutInMilliseconds", 
        value="12000")}
)
public class LicenseService {
    /* omit the details */
}

Apply at Function Level

Annotate the function with the @HystrixCommand annotation.

@HystrixCommand(
    commandProperties={@HystrixProperty(
        name="execution.isolation.thread.timeoutInMilliseconds", 
        value="12000")}
)
public List<License> getLicensesByOrg(String organizationId) {
    return licenseRepository.findByOrganizationId(organizationId);
}

Configure on Different Properties

There are 3 types of properties you can configure:

  • Command Properties
  • Thread Pool Properties
  • Collapser Properties

Command Properties

@HystrixCommand (
    threadPoolProperties = {
        @HystrixProperty(name = "NameA",value="ValueA"),
	@HystrixProperty(name = "NameB",value="ValueB")
    }
)
public List<License> getLicensesByOrg(String organizationId) {
    return licenseRepository.findByOrganizationId(organizationId);
}

Thread Pool Properties

@HystrixCommand (
    commandProperties = {
        @HystrixProperty(name = "NameA",value="ValueA"),
	@HystrixProperty(name = "NameB",value="ValueB")
    }
)
public List<License> getLicensesByOrg(String organizationId) {
    return licenseRepository.findByOrganizationId(organizationId);
}

Collapser Properties

This properties can not be set in the @HystrixCommand annotation or the @DefaultProperties annotation.


Configuration Parameter Quick Lookup

Thread Pool Properties

Name Description Default Value
coreSize Sets the core thread-pool size. 10
maximumSize Sets the maximum thread-pool size. 10
maxQueueSize The maximum size of the queue which is in front of the thread-pool. -1
queueSizeRejectionThreshold Sets the queue size rejection threshold - an artificial maximum queue size at which rejections will occur even if maxQueueSize has not been reached. 5
keepAliveTimeMinutes Sets the keep-alive time, in minutes. 1
allowMaximumSizeToDivergeFromCoreSize Allows the configuration for maximumSize to take effect. false
metrics.rollingStats.timeInMilliseconds Sets the duration of the statistical rolling window, in milliseconds. This is how long metrics are kept for the thread pool. 10000
metrics.rollingStats.numBuckets Sets the number of buckets the rolling statistical window is divided into. 10

Command Properties

Topic Name Description Default Value
Execution execution.isolation.strategy Indicates which isolation strategy will execute with. 2 options: THREAD, SEMAPHORE. THREAD
Execution execution.isolation.thread.timeoutInMilliseconds The time in milliseconds after which the caller will observe a timeout and walk away from the command execution. 1000
Execution execution.timeout.enabled Indicates whether the execution should have a timeout or not. true
Execution execution.isolation.thread.interruptOnTimeout Indicates whether the execution should be interrupted when a timeout occurs. true
Execution execution.isolation.thread.interruptOnCancel Indicates whether the execution should be interrupted when a cancellation occurs. false
Execution execution.isolation.semaphore.maxConcurrentRequests Sets the maximum number of requests allowed to a method when you are using SEMAPHORE isolation strategy. 10
Circuit Breaker circuitBreaker.enabled Determines whether a circuit breaker will be used to track health and to short-circuit requests if it trips. true
Circuit Breaker circuitBreaker.requestVolumeThreshold Sets the minimum number of requests in a rolling window that will trip the circuit. 20
Circuit Breaker circuitBreaker.sleepWindowInMilliseconds Sets the amount of time, after tripping the circuit, to reject requests before allowing attempts again to determine if the circuit should again be closed. 5000
Circuit Breaker circuitBreaker.errorThresholdPercentage Sets the error percentage at or above which the circuit should trip open and start short-circuiting requests to fallback logic. 50
Circuit Breaker circuitBreaker.forceOpen Forces the circuit breaker into an open (tripped) state in which it will reject all requests. false
Circuit Breaker circuitBreaker.forceClosed Forces the circuit breaker into a closed state in which it will allow requests regardless of the error percentage. false
Metrics metrics.rollingStats.timeInMilliseconds Sets the duration of the statistical rolling window, in milliseconds. This is how long Hystrix keeps metrics for the circuit breaker to use and for publishing. 10000
Metrics metrics.rollingStats.numBuckets Sets the number of buckets the rolling statistical window is divided into. 10
Metrics metrics.rollingPercentile.enabled Indicates whether execution latencies should be tracked and calculated as percentiles. true
Metrics metrics.rollingPercentile.timeInMilliseconds Sets the duration of the rolling window in which execution times are kept to allow for percentile calculations, in milliseconds. 60000
Metrics metrics.rollingPercentile.numBuckets Sets the number of buckets the rollingPercentile window will be divided into. 6
Metrics metrics.rollingPercentile.bucketSize Sets the maximum number of execution times that are kept per bucket. 100
Metrics metrics.healthSnapshot.intervalInMilliseconds Sets the time to wait, in milliseconds, between allowing health snapshots to be taken that calculate success and error percentages and affect circuit breaker status. 500
Fallback fallback.isolation.semaphore.maxConcurrentRequests Sets the maximum number of requests a fallback method is allowed to make from the calling thread. 10
Fallback fallback.enabled Determines whether a call to a fallback method will be attempted when failure or rejection occurs. true
Request Context requestCache.enabled Indicates whether the getCacheKey method should be used with the request cache to provide de-duplication functionality via request-scoped caching. true
Request Context requestLog.enabled Indicates whether HystrixCommand execution and events should be logged or not. true

Collapser Properties

Name Description Default Value
maxRequestsInBatch Sets the maximum number of requests allowed in a batch before this triggers a batch execution. Integer.MAX_VALUE
timerDelayInMilliseconds Sets the number of milliseconds after the creation of the batch that its execution is triggered. 10
requestCache.enabled Indicates whether request caching is enabled for HystrixCollapser.execute() and HystrixCollapser.queue() invocations. true
Clone this wiki locally