Hystix配置
- Execution执行
- execution.isolation.strategy: 执行策略。
- 默认值:THREAD,ExecutionIsolationStrategy.THREAD
- 可设置值:THREAD, SEMAPHORE
- 默认配置:hystrix.command.default.execution.isolation.strategy
- 实例配置:hystrix.command.实例CommandKey.execution.isolation.strategy
- 设置THREAD:HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.THREAD)
- 设置SEMAPHORE:HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE)
- execution.isolation.thread.timeoutInMilliseconds: 设置调用者等待命令执行的超时限制,超过此时间,HystrixCommand被标记为TIMEOUT,并执行回退逻辑。
- 默认值:1000
- 默认配置:hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
- 实例配置:hystrix.command.实例CommandKey.execution.isolation.thread.timeoutInMilliseconds
- 设置方式:HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(int value)
- execution.timeout.enabled: 执行是否有超时限制。
- 默认值:true
- 默认配置:hystrix.command.default.execution.timeout.enabled
- 实例配置:hystrix.command.实例CommandKey.execution.timeout.enabled
- 设置方式:HystrixCommandProperties.Setter().withExecutionTimeoutEnabled(boolean value)
- execution.isolation.thread.interruptOnTimeout:当超时的时候是否中断
- 默认值:true
- 默认配置:hystrix.command.default.execution.isolation.thread.interruptOnTimeout
- 实例配置:hystrix.command.实例CommandKey.execution.isolation.thread.interruptOnTimeout
- 设置方式:HystrixCommandProperties.Setter()
.withExecutionIsolationThreadInterruptOnTimeout(boolean value)
- execution.isolation.thread.interruptOnCancel:当发生cancel事件后是否中断
- 默认值:false
- 默认配置:hystrix.command.default.execution.isolation.thread.interruptOnCancel
- 实例配置:hystrix.command.实例CommandKey.execution.isolation.thread.interruptOnCancel
- 设置方式:HystrixCommandProperties.Setter().withExecutionIsolationThreadInterruptOnCancel(boolean value)
- execution.isolation.semaphore.maxConcurrentRequests:当使用信号量隔离的时候,此配置有效。
- 默认值:10
- 默认配置:hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests
- 实例配置:hystrix.command.实例CommandKey.execution.isolation.semaphore.maxConcurrentRequests
- 设置方式:HystrixCommandProperties.Setter().withExecutionIsolationSemaphoreMaxConcurrentRequests(int value)
- execution.isolation.strategy: 执行策略。
- Fallback 降级
- fallback.isolation.semaphore.maxConcurrentRequests:最大并发数,超过此并发则拒绝请求。
- 默认值:10
- 默认配置:hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests
- 实例配置:hystrix.command.实例CommandKey.fallback.isolation.semaphore.maxConcurrentRequests
- 设置方式:HystrixCommandProperties.Setter().withFallbackIsolationSemaphoreMaxConcurrentRequests(int value)
- fallback.enabled:是否开启降级。
- 默认值:true
- 默认配置:hystrix.command.default.fallback.enabled
- 实例配置:hystrix.command.实例CommandKey.fallback.enabled
- 设置方式:HystrixCommandProperties.Setter().withFallbackEnabled(boolean value)
- fallback.isolation.semaphore.maxConcurrentRequests:最大并发数,超过此并发则拒绝请求。
- Circuit Breaker 熔断器
- circuitBreaker.enabled:是否打开熔断器。
- 默认值:true
- 默认配置:hystrix.command.default.circuitBreaker.enabled
- 实例配置:hystrix.command.实例CommandKey.circuitBreaker.enabled
- 设置方式:HystrixCommandProperties.Setter().withCircuitBreakerEnabled(boolean value)
- circuitBreaker.requestVolumeThreshold:时间窗口内最小请求数,当小于这个请求数,即使全部失败也不会熔断。
- 默认值:20
- 默认配置:hystrix.command.default.circuitBreaker.requestVolumeThreshold
- 实例配置:hystrix.command.实例CommandKey.circuitBreaker.requestVolumeThreshold
- 设置方式:HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(int value)
- circuitBreaker.sleepWindowInMilliseconds:熔断后,请求retry的时间间隔。
- 默认值:5000
- 默认属性:hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds
- 实例配置:hystrix.command.实例CommandKey.circuitBreaker.sleepWindowInMilliseconds
- 配置方式:HystrixCommandProperties.Setter().withCircuitBreakerSleepWindowInMilliseconds(int value)
- circuitBreaker.errorThresholdPercentage:失败率阈值,超过这个失败率就会熔断
- 默认值:50
- 默认属性:hystrix.command.default.circuitBreaker.errorThresholdPercentage
- 实例配置:hystrix.command.实例CommandKey.circuitBreaker.errorThresholdPercentage
- 配置方式:HystrixCommandProperties.Setter().withCircuitBreakerErrorThresholdPercentage(int value)
- circuitBreaker.forceOpen:是否强制开启熔断,这样会导致拒绝所有请求。
- 默认值:false
- 默认属性:hystrix.command.default.circuitBreaker.forceOpen
- 实例配置:hystrix.command.实例CommandKey.circuitBreaker.forceOpen
- 配置方式:HystrixCommandProperties.Setter().withCircuitBreakerForceOpen
- circuitBreaker.forceClosed:是否强制关闭熔断,这样任何原因都无法触发熔断。注:优先级小于强制开启。
- 默认值:false
- 默认属性:hystrix.command.default.circuitBreaker.forceClosed
- 实例配置:hystrix.command.实例CommandKey.circuitBreaker.forceClosed
- 配置方式:HystrixCommandProperties.Setter().withCircuitBreakerForceClosed(boolean value)
- circuitBreaker.enabled:是否打开熔断器。
- Metrics 度量
- metrics.rollingStats.timeInMilliseconds:设置统计滚动窗口的长度,以毫秒为单位。用于监控和熔断器。
- 默认值:10000
- 默认属性:hystrix.command.default.metrics.rollingStats.timeInMilliseconds
- 实例配置:hystrix.command.实例CommandKey.metrics.rollingStats.timeInMilliseconds
- 配置方式:HystrixCommandProperties.Setter().withMetricsRollingStatisticalWindowInMilliseconds(int value)
- metrics.rollingStats.numBuckets:统计窗口的桶数量。
- 默认值:10
- 默认属性:hystrix.command.default.metrics.rollingStats.numBuckets
- 实例配置:hystrix.command.实例CommandKey.metrics.rollingStats.numBuckets
- 配置方式:HystrixCommandProperties.Setter().withMetricsRollingStatisticalWindowBuckets(int value)
- metrics.rollingPercentile.enabled:执行时间是否被跟踪,并且计算各个百分比,50%,90%等的时间。
- 默认值:true
- 默认属性:hystrix.command.default.metrics.rollingPercentile.enabled
- 实例配置:hystrix.command.实例CommandKey.metrics.rollingPercentile.enabled
- 配置方式:HystrixCommandProperties.Setter().withMetricsRollingPercentileEnabled(boolean value)
- metrics.rollingPercentile.timeInMilliseconds:执行时间在滚动窗口中保留时间,用来计算百分比。
- 默认值:60000
- 默认属性:hystrix.command.default.metrics.rollingPercentile.timeInMilliseconds
- 实例配置:hystrix.command.实例CommandKey.metrics.rollingPercentile.timeInMilliseconds
- 配置方式:HystrixCommandProperties.Setter().withMetricsRollingPercentileWindowInMilliseconds(int value)
- metrics.rollingPercentile.numBuckets:rollingPercentile窗口的桶数量。
- 默认值:6
- 默认属性:hystrix.command.default.metrics.rollingPercentile.numBuckets
- 实例配置:hystrix.command.实例CommandKey.metrics.rollingPercentile.numBuckets
- 配置方式:HystrixCommandProperties.Setter().withMetricsRollingPercentileWindowBuckets(int value)
- metrics.rollingPercentile.bucketSize:每个桶保存的执行时间的最大值。
- 默认值:100
- 默认属性:hystrix.command.default.metrics.rollingPercentile.bucketSize
- 实例配置:hystrix.command.实例CommandKey.metrics.rollingPercentile.bucketSize
- 配置方式:HystrixCommandProperties.Setter().withMetricsRollingPercentileBucketSize(int value)
- metrics.healthSnapshot.intervalInMilliseconds:采样时间间隔。
- 默认值:500
- 默认属性:hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds
- 实例配置:hystrix.command.实例CommandKey.metrics.healthSnapshot.intervalInMilliseconds
- 配置方式:HystrixCommandProperties.Setter().withMetricsHealthSnapshotIntervalInMilliseconds(int value)
- metrics.rollingStats.timeInMilliseconds:设置统计滚动窗口的长度,以毫秒为单位。用于监控和熔断器。
- Request Context 请求上下文
- requestCache.enabled:设置是否缓存请求,request-scope内缓存。
- 默认值:true
- 默认属性:hystrix.command.default.requestCache.enabled
- 实例配置:hystrix.command.实例CommandKey.requestCache.enabled
- 配置方式:HystrixCommandProperties.Setter().withRequestCacheEnabled(boolean value)
- requestLog.enabled:设置HystrixCommand执行和事件是否打印到HystrixRequestLog中 。
- 默认值:true
- 默认属性:hystrix.command.default.requestLog.enabled
- 实例配置:hystrix.command.实例CommandKey.requestLog.enabled
- 配置方式:HystrixCommandProperties.Setter().withRequestLogEnabled(boolean value)
- requestCache.enabled:设置是否缓存请求,request-scope内缓存。
- Collapser Properties 压缩器属性
- maxRequestsInBatch:请求合并的最大请求数
- 默认值:Integer.MAX_VALUE
- 默认属性:hystrix.collapser.default.maxRequestsInBatch
- 实例配置:hystrix.collapser.实例CommandKey.maxRequestsInBatch
- 配置方式:HystrixCollapserProperties.Setter().withMaxRequestsInBatch(int value)
- timerDelayInMilliseconds:请求合并的时间窗口,也就是出现第一个请求后,在该时间间隔内的请求合并,超过则进入下一个时间窗口
- 默认值:10
- 默认属性:hystrix.collapser.default.timerDelayInMilliseconds
- 实例配置:hystrix.collapser.实例CommandKey.timerDelayInMilliseconds
- 配置方式:HystrixCollapserProperties.Setter().withTimerDelayInMilliseconds(int value)
- requestCache.enabled:请求合并是否打开请求缓存
- 默认值:true
- 默认属性:hystrix.collapser.default.requestCache.enabled
- 实例配置:hystrix.collapser.实例CommandKey.requestCache.enabled
- 配置方式:HystrixCollapserProperties.Setter().withRequestCacheEnabled(int value)
- maxRequestsInBatch:请求合并的最大请求数
- Thread Pool Properties 线程池参数
- coreSize:线程池的大小
- 默认值:10
- 默认属性:hystrix.threadpool.default.coreSize
- 实例配置:hystrix.threadpool.实例PoolKey.coreSize
- 配置方式:HystrixThreadPoolProperties.Setter().withCoreSize(int value)
- maximumSize:线程池的最大大小,只会在设置了allowMaximumSizeToDivergeFromCoreSize的情况下生效,一般情况下和线程池大小相同。
- 默认值:10
- 默认属性:hystrix.threadpool.default.maximumSize
- 实例配置:hystrix.threadpool.实例PoolKey.maximumSize
- 配置方式:HystrixThreadPoolProperties.Setter().withMaximumSize(int value)
- maxQueueSize:-1代表使用SynchronousQueue,其它值代表LinkedBlockingQueue.这两个队列用于ThreadPoolExecutor
- 默认值:−1
- 默认属性:hystrix.threadpool.default.maxQueueSize
- 实例配置:hystrix.threadpool.实例PoolKey.maxQueueSize
- 配置方式:HystrixThreadPoolProperties.Setter().withMaxQueueSize(int value)
- queueSizeRejectionThreshold:队列拒绝服务的阈值
- 默认值:5
- 默认属性:hystrix.threadpool.default.queueSizeRejectionThreshold
- 实例配置:hystrix.threadpool.实例PoolKey.queueSizeRejectionThreshold
- 配置方式:HystrixThreadPoolProperties.Setter().withQueueSizeRejectionThreshold(int value)
- keepAliveTimeMinutes:如果线程池的最大值大于线程池的大小,那么这个配置用于回收多久没被使用的线程。
- 默认值:1
- 默认属性:hystrix.threadpool.default.keepAliveTimeMinutes
- 实例配置:hystrix.threadpool.实例PoolKey.keepAliveTimeMinutes
- 配置方式:HystrixThreadPoolProperties.Setter().withKeepAliveTimeMinutes(int value)
- allowMaximumSizeToDivergeFromCoreSize:线程池的最大值是否可以和线程池的值不一样
- 默认值:false
- 默认属性:hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize
- 实例配置:hystrix.threadpool.实例PoolKey.allowMaximumSizeToDivergeFromCoreSize
- 配置方式:HystrixThreadPoolProperties.Setter().withAllowMaximumSizeToDivergeFromCoreSize(boolean value)
- metrics.rollingStats.timeInMilliseconds:设置统计滚动窗口的长度,以毫秒为单位。用于监控和熔断器。滚动窗口被分隔成桶(bucket)。并进行滚动。
- 默认值:10000
- 默认属性:hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds
- 实例配置:hystrix.threadpool.实例PoolKey.metrics.rollingStats.timeInMillisecon
- 配置方式:HystrixThreadPoolProperties.Setter().withMetricsRollingStatisticalWindowInMilliseconds(int value)
- metrics.rollingStats.numBuckets:统计窗口的桶数量
- 默认值:10
- 默认属性:hystrix.threadpool.default.metrics.rollingStats.numBuckets
- 实例配置:hystrix.threadpool.实例PoolKey.metrics.rollingStats.numBuckets
- 配置方式:HystrixThreadPoolProperties.Setter().withMetricsRollingStatisticalWindowBuckets(int value)
- coreSize:线程池的大小