詳細信息,見官方文檔。
Hystrix屬性的4中優(yōu)先級
1. 內(nèi)置全局默認值(Global default from code)
如果下面3種都沒有設(shè)置掀淘,默認是使用此種,后面用“默認值”代指這種油昂。
2. 動態(tài)全局默認屬性(Dynamic global default property)
可以通過屬性配置來更改全局默認值革娄,后面用“默認屬性”代指這種倾贰。
3. 內(nèi)置實例默認值(Instance default from code)
在代碼中,設(shè)置的屬性值拦惋,后面用“實例默認”來代指這種匆浙。
4. 動態(tài)配置實例屬性(Dynamic instance property)
可以針對特定的實例,動態(tài)配置屬性值厕妖,來代替前面三種首尼,后面用“實例屬性”來代指這種。
優(yōu)先級:1 < 2 < 3 < 4
命令屬性
執(zhí)行
execution.isolation.strategy
設(shè)置HystrixCommand.run()的隔離策略言秸,有兩種選項:
THREAD —— 在固定大小線程池中软能,以單獨線程執(zhí)行,并發(fā)請求數(shù)受限于線程池大小举畸。
SEMAPHORE —— 在調(diào)用線程中執(zhí)行查排,通過信號量來限制并發(fā)量。
默認值:THREAD(ExecutionIsolationStrategy.THREAD)
可選值:THREAD抄沮,SEMAPHORE
默認屬性:hystrix.command.default.execution.isolation.strategy
實例屬性:
hystrix.command.HystrixCommandKey.execution.isolation.strategy
實例默認的設(shè)置:
// to use thread isolation
HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(ExecutionIsolationStrategy.THREAD)
// to use semaphore isolation
HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE)
execution.isolation.thread.timeoutInMilliseconds
設(shè)置調(diào)用者等待命令執(zhí)行的超時限制跋核,超過此時間,HystrixCommand被標記為TIMEOUT叛买,并執(zhí)行回退邏輯砂代。
注意:超時會作用在HystrixCommand.queue(),即使調(diào)用者沒有調(diào)用get()去獲得Future對象聪全。
默認值:1000(毫秒)
默認屬性:hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
實例屬性:hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withExecutionTimeoutInMilliseconds(int value)
execution.timeout.enabled
設(shè)置HystrixCommand.run()的執(zhí)行是否有超時限制泊藕。
默認值:true
默認屬性:hystrix.command.default.execution.timeout.enabled
實例屬性:hystrix.command.HystrixCommandKey.execution.timeout.enabled
實例默認的設(shè)置:
HystrixCommandProperties.Setter()
.withExecutionTimeoutEnabled(boolean value)
execution.isolation.thread.interruptOnTimeout
設(shè)置HystrixCommand.run()的執(zhí)行是否在超時發(fā)生時被中斷。
默認值:true
默認屬性:hystrix.command.default.execution.isolation.thread.interruptOnTimeout
實例屬性:hystrix.command.HystrixCommandKey.execution.isolation.thread.interruptOnTimeout
實例默認的設(shè)置:
HystrixCommandProperties.Setter()
.withExecutionIsolationThreadInterruptOnTimeout(boolean value)
execution.isolation.thread.interruptOnCancel
設(shè)置HystrixCommand.run()的執(zhí)行但取消動作發(fā)生時候可以響應(yīng)中斷难礼。
默認值:false
默認屬性:hystrix.command.default.execution.isolation.thread.interruptOnCancel
實例屬性:hystrix.command.HystrixCommandKey.execution.isolation.thread.interruptOnCancel
實例默認的設(shè)置:
HystrixCommandProperties.Setter()
.withExecutionIsolationThreadInterruptOnCancel(boolean value)
execution.isolation.semaphore.maxConcurrentRequests
設(shè)置當使用ExecutionIsolationStrategy.SEMAPHORE時娃圆,HystrixCommand.run()方法允許的最大請求數(shù)。如果達到最大并發(fā)數(shù)時蛾茉,后續(xù)請求會被拒絕讼呢。
信號量應(yīng)該是容器(比如Tomcat)線程池一小部分,不能等于或者略小于容器線程池大小谦炬,否則起不到保護作用悦屏。
默認值:10
默認屬性:hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests
實例屬性:hystrix.command.HystrixCommandKey.execution.isolation.semaphore.maxConcurrentRequests
實例默認的設(shè)置:
HystrixCommandProperties.Setter()
.withExecutionIsolationSemaphoreMaxConcurrentRequests(int value)
回退
下面的屬性控制HystrixCommand.getFallback()執(zhí)行。這些屬性對ExecutionIsolationStrategy.THREAD和ExecutionIsolationStrategy.SEMAPHORE都有效键思。
fallback.isolation.semaphore.maxConcurrentRequests
設(shè)置調(diào)用線程產(chǎn)生的HystrixCommand.getFallback()方法的允許最大請求數(shù)目础爬。
如果達到最大并發(fā)數(shù)目,后續(xù)請求將會被拒絕吼鳞,如果沒有實現(xiàn)回退看蚜,則拋出異常。
默認值:10
默認屬性:hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests
實例屬性:hystrix.command.HystrixCommandKey.fallback.isolation.semaphore.maxConcurrentRequests
實例默認:
HystrixCommandProperties.Setter()
.withFallbackIsolationSemaphoreMaxConcurrentRequests(int value)
fallback.enabled
該屬性決定當故障或者拒絕發(fā)生時赔桌,一個調(diào)用將會去嘗試HystrixCommand.getFallback()供炎。
默認值:true
默認屬性:hystrix.command.default.fallback.enabled
實例屬性:hystrix.command.HystrixCommandKey.fallback.enabled
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withFallbackEnabled(boolean value)
斷路器(Circuit Breaker)
circuitBreaker.enabled
設(shè)置斷路器是否起作用渴逻。
默認值:true
默認屬性:hystrix.command.default.circuitBreaker.enabled
實例屬性:hystrix.command.HystrixCommandKey.circuitBreaker.enabled
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withCircuitBreakerEnabled(boolean value)
circuitBreaker.requestVolumeThreshold
設(shè)置在一個滾動窗口中,打開斷路器的最少請求數(shù)音诫。
比如:如果值是20惨奕,在一個窗口內(nèi)(比如10秒),收到19個請求竭钝,即使這19個請求都失敗了梨撞,斷路器也不會打開。
默認值:20
默認屬性:hystrix.command.default.circuitBreaker.requestVolumeThreshold
實例屬性:hystrix.command.HystrixCommandKey.circuitBreaker.requestVolumeThreshold
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withCircuitBreakerRequestVolumeThreshold(int value)
circuitBreaker.sleepWindowInMilliseconds
設(shè)置在回路被打開蜓氨,拒絕請求到再次嘗試請求并決定回路是否繼續(xù)打開的時間聋袋。
默認值:5000(毫秒)
默認屬性:hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds
實例屬性:hystrix.command.HystrixCommandKey.circuitBreaker.sleepWindowInMilliseconds
實例默認的設(shè)置:
HystrixCommandProperties.Setter()
.withCircuitBreakerSleepWindowInMilliseconds(int value)
circuitBreaker.errorThresholdPercentage
設(shè)置打開回路并啟動回退邏輯的錯誤比率。
默認值:50
默認屬性:hystrix.command.default.circuitBreaker.errorThresholdPercentage
實例屬性:hystrix.command.HystrixCommandKey.circuitBreaker.errorThresholdPercentage
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withCircuitBreakerErrorThresholdPercentage(int value)
circuitBreaker.forceOpen
如果該屬性設(shè)置為true穴吹,強制斷路器進入打開狀態(tài)幽勒,將會拒絕所有的請求。
該屬性優(yōu)先級比circuitBreaker.forceClosed高港令。
默認值:false
默認屬性:hystrix.command.default.circuitBreaker.forceOpen
實例屬性:hystrix.command.HystrixCommandKey.circuitBreaker.forceOpen
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withCircuitBreakerForceOpen(boolean value)
circuitBreaker.forceClosed
如果該屬性設(shè)置為true啥容,強制斷路器進入關(guān)閉狀態(tài),將會允許所有的請求顷霹,無視錯誤率咪惠。
默認值:false
默認屬性:hystrix.command.default.circuitBreaker.forceClosed
實例屬性:hystrix.command.HystrixCommandKey.circuitBreaker.forceClosed
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withCircuitBreakerForceClosed(boolean value)
請求上下文
requestCache.enabled
設(shè)置HystrixCommand.getCacheKey()是否啟用,由HystrixRequestCache通過請求緩存提供去重復(fù)數(shù)據(jù)功能淋淀。
默認值:true
默認屬性:hystrix.command.default.requestCache.enabled
實例屬性:hystrix.command.HystrixCommandKey.requestCache.enabled
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withRequestCacheEnabled(boolean value)
requestLog.enabled
設(shè)置HystrixCommand執(zhí)行和事件是否要記錄日志到HystrixRequestLog遥昧。
默認值:true
默認屬性:hystrix.command.default.requestLog.enabled
實例屬性:hystrix.command.HystrixCommandKey.requestLog.enabled
實例默認的設(shè)置:HystrixCommandProperties.Setter()
.withRequestLogEnabled(boolean value)
壓縮器屬性
下面的屬性可以控制HystrixCollapser行為。
maxRequestsInBatch
設(shè)置觸發(fā)批處理執(zhí)行之前朵纷,在批處理中允許的最大請求數(shù)炭臭。
默認值:Integer.MAX_VALUE
默認屬性:hystrix.collapser.default.maxRequestsInBatch
實例屬性:hystrix.collapser.HystrixCollapserKey.maxRequestsInBatch
實例默認的設(shè)置:HystrixCollapserProperties.Setter()
.withMaxRequestsInBatch(int value)
timerDelayInMilliseconds
設(shè)置批處理創(chuàng)建到執(zhí)行之間的毫秒數(shù)。
默認值:10
默認屬性:hystrix.collapser.default.timerDelayInMilliseconds
實例屬性:hystrix.collapser.HystrixCollapserKey.timerDelayInMilliseconds
實例默認的設(shè)置:HystrixCollapserProperties.Setter()
.withTimerDelayInMilliseconds(int value)
requestCache.enabled
設(shè)置請求緩存是否對HystrixCollapser.execute()和HystrixCollapser.queue()的調(diào)用起作用袍辞。
默認值:true
默認屬性:hystrix.collapser.default.requestCache.enabled
實例屬性:hystrix.collapser.HystrixCollapserKey.requestCache.enabled
實例默認的設(shè)置:HystrixCollapserProperties.Setter()
.withRequestCacheEnabled(boolean value)
線程池屬性
coreSize
設(shè)置核心線程池大小鞋仍。
默認值:10
默認屬性:hystrix.threadpool.default.coreSize
實例屬性:hystrix.threadpool.HystrixThreadPoolKey.coreSize
實例默認的設(shè)置:HystrixThreadPoolProperties.Setter()
.withCoreSize(int value)
maximumSize
1.5.9新增屬性,設(shè)置線程池最大值搅吁。這個是在不開始拒絕HystrixCommand的情況下支持的最大并發(fā)數(shù)威创。這個屬性起作用的前提是設(shè)置了allowMaximumSizeToDrivergeFromCoreSize。1.5.9之前谎懦,核心線程池大小和最大線程池大小總是相同的肚豺。
maxQueueSize
設(shè)置BlockingQueue最大的隊列值。
如果設(shè)置為-1界拦,那么使用SynchronousQueue详炬,否則正數(shù)將會使用LinkedBlockingQueue。
如果需要去除這些限制,允許隊列動態(tài)變化呛谜,可以參考queueSizeRejectionThreshold屬性。
修改SynchronousQueue和LinkedBlockingQueue需要重啟枪萄。
默認值:-1
默認屬性:hystrix.threadpool.default.maxQueueSize
實例屬性:hystrix.threadpool.HystrixThreadPoolKey.maxQueueSize
實例默認的設(shè)置:HystrixThreadPoolProperties.Setter()
.withMaxQueueSize(int value)
queueSizeRejectionThreshold
設(shè)置隊列拒絕的閾值——一個人為設(shè)置的拒絕訪問的最大隊列值隐岛,即使maxQueueSize還沒有達到。
當將一個線程放入隊列等待執(zhí)行時瓷翻,HystrixCommand使用該屬性聚凹。
注意:如果maxQueueSize設(shè)置為-1,該屬性不可用齐帚。
默認值:5
默認屬性:hystrix.threadpool.default.queueSizeRejectionThreshold
實例屬性:hystrix.threadpool.HystrixThreadPoolKey.queueSizeRejectionThreshold
實例默認的設(shè)置:HystrixThreadPoolProperties.Setter()
.withQueueSizeRejectionThreshold(int value)
keepAliveTimeMinutes
設(shè)置存活時間妒牙,單位分鐘。如果coreSize小于maximumSize对妄,那么該屬性控制一個線程從實用完成到被釋放的時間湘今。
默認值:1
默認屬性:hystrix.threadpool.default.keepAliveTimeMinutes
實例屬性:hystrix.threadpool.HystrixThreadPoolKey.keepAliveTimeMinutes
實例默認的設(shè)置:HystrixThreadPoolProperties.Setter()
.withKeepAliveTimeMinutes(int value)
allowMaximumSizeToDivergeFromCoreSize
在1.5.9中新增的屬性。該屬性允許maximumSize起作用剪菱。屬性值可以等于或者大于coreSize值摩瞎,設(shè)置coreSize小于maximumSize的線程池能夠支持maximumSize的并發(fā)數(shù),但是會將不活躍的線程返回到系統(tǒng)中去孝常。(詳見KeepAliveTimeMinutes)
默認值:false
默認屬性:hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize
實例屬性:hystrix.threadpool.HystrixThreadPoolKey.allowMaximumSizeToDivergeFromCoreSize
實例默認的設(shè)置:HystrixThreadPoolProperties.Setter()
.withAllowMaximumSizeToDivergeFromCoreSize(boolean value)
metrics.rollingStats.timeInMilliseconds
設(shè)置統(tǒng)計的滾動窗口的時間段大小旗们。該屬性是線程池保持指標時間長短。
默認值:10000(毫秒)
默認屬性:hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds
實例屬性:hystrix.threadpool.HystrixThreadPoolKey.metrics.rollingStats.timeInMilliseconds
實例默認的設(shè)置:HystrixThreadPoolProperties.Setter()
.withMetricsRollingStatisticalWindowInMilliseconds(int value)
metrics.rollingStats.numBuckets
設(shè)置滾動的統(tǒng)計窗口被分成的桶(bucket)的數(shù)目构灸。
注意:”metrics.rollingStats.timeInMilliseconds % metrics.rollingStats.numBuckets == 0"必須為true上渴,否則會拋出異常。
默認值:10
可能的值:任何能被metrics.rollingStats.timeInMilliseconds整除的值喜颁。
默認屬性:hystrix.threadpool.default.metrics.rollingStats.numBuckets
實例屬性:hystrix.threadpool.HystrixThreadPoolProperties.metrics.rollingStats.numBuckets
實例默認的設(shè)置:HystrixThreadPoolProperties.Setter()
.withMetricsRollingStatisticalWindowBuckets(int value)