Hystrix配置簡單說明(官方文檔簡譯)

詳細信息,見官方文檔

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.THREADExecutionIsolationStrategy.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)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末稠氮,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子洛巢,更是在濱河造成了極大的恐慌括袒,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,888評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件稿茉,死亡現(xiàn)場離奇詭異锹锰,居然都是意外死亡,警方通過查閱死者的電腦和手機漓库,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,677評論 3 399
  • 文/潘曉璐 我一進店門恃慧,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人渺蒿,你說我怎么就攤上這事痢士。” “怎么了茂装?”我有些...
    開封第一講書人閱讀 168,386評論 0 360
  • 文/不壞的土叔 我叫張陵怠蹂,是天一觀的道長善延。 經(jīng)常有香客問我,道長城侧,這世上最難降的妖魔是什么易遣? 我笑而不...
    開封第一講書人閱讀 59,726評論 1 297
  • 正文 為了忘掉前任,我火速辦了婚禮嫌佑,結(jié)果婚禮上豆茫,老公的妹妹穿的比我還像新娘。我一直安慰自己屋摇,他們只是感情好揩魂,可當我...
    茶點故事閱讀 68,729評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著炮温,像睡著了一般火脉。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上茅特,一...
    開封第一講書人閱讀 52,337評論 1 310
  • 那天忘分,我揣著相機與錄音,去河邊找鬼白修。 笑死妒峦,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的兵睛。 我是一名探鬼主播肯骇,決...
    沈念sama閱讀 40,902評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼祖很!你這毒婦竟也來了笛丙?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,807評論 0 276
  • 序言:老撾萬榮一對情侶失蹤假颇,失蹤者是張志新(化名)和其女友劉穎胚鸯,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體笨鸡,經(jīng)...
    沈念sama閱讀 46,349評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡姜钳,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,439評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了形耗。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片哥桥。...
    茶點故事閱讀 40,567評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖激涤,靈堂內(nèi)的尸體忽然破棺而出拟糕,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 36,242評論 5 350
  • 正文 年R本政府宣布送滞,位于F島的核電站侠草,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏犁嗅。R本人自食惡果不足惜梦抢,卻給世界環(huán)境...
    茶點故事閱讀 41,933評論 3 334
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望愧哟。 院中可真熱鬧,春花似錦哼蛆、人聲如沸蕊梧。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,420評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽肥矢。三九已至,卻和暖如春叠洗,著一層夾襖步出監(jiān)牢的瞬間甘改,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,531評論 1 272
  • 我被黑心中介騙來泰國打工灭抑, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留十艾,地道東北人。 一個月前我還...
    沈念sama閱讀 48,995評論 3 377
  • 正文 我出身青樓腾节,卻偏偏與公主長得像忘嫉,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子案腺,可洞房花燭夜當晚...
    茶點故事閱讀 45,585評論 2 359

推薦閱讀更多精彩內(nèi)容