hystrix.command.default和hystrix.threadpool.default中的default為默認CommandKey
Command Properties
Execution相關(guān)的屬性的配置:
hystrix.command.default.execution.isolation.strategy 隔離策略看彼,默認是Thread, 可選Thread|Semaphore
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 命令執(zhí)行超時時間祭陷,默認1000ms
hystrix.command.default.execution.timeout.enabled 執(zhí)行是否啟用超時,默認啟用true
hystrix.command.default.execution.isolation.thread.interruptOnTimeout 發(fā)生超時是是否中斷壤追,默認true
hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests 最大并發(fā)請求數(shù)宴咧,默認10,該參數(shù)當使用ExecutionIsolationStrategy.SEMAPHORE策略時才有效。如果達到最大并發(fā)請求數(shù)硕蛹,請求會被拒絕。理論上選擇semaphore size的原則和選擇thread size一致硕并,但選用semaphore時每次執(zhí)行的單元要比較小且執(zhí)行速度快(ms級別)妓美,否則的話應(yīng)該用thread。
semaphore應(yīng)該占整個容器(tomcat)的線程池的一小部分鲤孵。
Fallback相關(guān)的屬性
這些參數(shù)可以應(yīng)用于Hystrix的THREAD和SEMAPHORE策略
hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests 如果并發(fā)數(shù)達到該設(shè)置值壶栋,請求會被拒絕和拋出異常并且fallback不會被調(diào)用。默認10
hystrix.command.default.fallback.enabled 當執(zhí)行失敗或者請求被拒絕普监,是否會嘗試調(diào)用hystrixCommand.getFallback() 贵试。默認true
Circuit Breaker相關(guān)的屬性
hystrix.command.default.circuitBreaker.enabled 用來跟蹤circuit的健康性,如果未達標則讓request短路凯正。默認true
hystrix.command.default.circuitBreaker.requestVolumeThreshold 一個rolling window內(nèi)最小的請求數(shù)毙玻。如果設(shè)為20,那么當一個rolling window的時間內(nèi)(比如說1個rolling window是10秒)收到19個請求廊散,即使19個請求都失敗桑滩,也不會觸發(fā)circuit break。默認20
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds 觸發(fā)短路的時間值允睹,當該值設(shè)為5000時运准,則當觸發(fā)circuit break后的5000毫秒內(nèi)都會拒絕request,也就是5000毫秒后才會關(guān)閉circuit缭受。默認5000
hystrix.command.default.circuitBreaker.errorThresholdPercentage錯誤比率閥值胁澳,如果錯誤率>=該值,circuit會被打開米者,并短路所有請求觸發(fā)fallback韭畸。默認50
hystrix.command.default.circuitBreaker.forceOpen 強制打開熔斷器,如果打開這個開關(guān)蔓搞,那么拒絕所有request胰丁,默認false
hystrix.command.default.circuitBreaker.forceClosed 強制關(guān)閉熔斷器 如果這個開關(guān)打開,circuit將一直關(guān)閉且忽略circuitBreaker.errorThresholdPercentage
Metrics相關(guān)參數(shù)
hystrix.command.default.metrics.rollingStats.timeInMilliseconds 設(shè)置統(tǒng)計的時間窗口值的喂分,毫秒值锦庸,circuit break 的打開會根據(jù)1個rolling window的統(tǒng)計來計算。若rolling window被設(shè)為10000毫秒妻顶,則rolling window會被分成n個buckets酸员,每個bucket包含success蜒车,failure,timeout幔嗦,rejection的次數(shù)的統(tǒng)計信息酿愧。默認10000
hystrix.command.default.metrics.rollingStats.numBuckets 設(shè)置一個rolling window被劃分的數(shù)量,若numBuckets=10邀泉,rolling window=10000嬉挡,那么一個bucket的時間即1秒。必須符合rolling window % numberBuckets == 0汇恤。默認10
hystrix.command.default.metrics.rollingPercentile.enabled 執(zhí)行時是否enable指標的計算和跟蹤庞钢,默認true
hystrix.command.default.metrics.rollingPercentile.timeInMilliseconds 設(shè)置rolling percentile window的時間,默認60000
hystrix.command.default.metrics.rollingPercentile.numBuckets 設(shè)置rolling percentile window的numberBuckets因谎。邏輯同上基括。默認6
hystrix.command.default.metrics.rollingPercentile.bucketSize 如果bucket size=100,window=10s财岔,若這10s里有500次執(zhí)行风皿,只有最后100次執(zhí)行會被統(tǒng)計到bucket里去。增加該值會增加內(nèi)存開銷以及排序的開銷匠璧。默認100
hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds 記錄health 快照(用來統(tǒng)計成功和錯誤綠)的間隔桐款,默認500ms
Request Context 相關(guān)參數(shù)
hystrix.command.default.requestCache.enabled 默認true,需要重載getCacheKey()夷恍,返回null時不緩存
hystrix.command.default.requestLog.enabled 記錄日志到HystrixRequestLog魔眨,默認true
Collapser Properties 相關(guān)參數(shù)
hystrix.collapser.default.maxRequestsInBatch 單次批處理的最大請求數(shù),達到該數(shù)量觸發(fā)批處理酿雪,默認Integer.MAX_VALUE
hystrix.collapser.default.timerDelayInMilliseconds 觸發(fā)批處理的延遲遏暴,也可以為創(chuàng)建批處理的時間+該值,默認10
hystrix.collapser.default.requestCache.enabled 是否對HystrixCollapser.execute() and HystrixCollapser.queue()的cache执虹,默認true
ThreadPool 相關(guān)參數(shù)
線程數(shù)默認值10適用于大部分情況(有時可以設(shè)置得更型鼗印),如果需要設(shè)置得更大袋励,那有個基本得公式可以follow:
requests per second at peak when healthy × 99th percentile latency in seconds + some breathing room
每秒最大支撐的請求數(shù) (99%平均響應(yīng)時間 + 緩存值)
比如:每秒能處理1000個請求,99%的請求響應(yīng)時間是60ms当叭,那么公式是:
(0.060+0.012)
基本得原則時保持線程池盡可能小茬故,他主要是為了釋放壓力,防止資源被阻塞蚁鳖。
當一切都是正常的時候磺芭,線程池一般僅會有1到2個線程激活來提供服務(wù)
hystrix.threadpool.default.coreSize 并發(fā)執(zhí)行的最大線程數(shù),默認10
hystrix.threadpool.default.maxQueueSize BlockingQueue的最大隊列數(shù)醉箕,當設(shè)為-1钾腺,會使用SynchronousQueue徙垫,值為正時使用LinkedBlcokingQueue。該設(shè)置只會在初始化時有效放棒,之后不能修改threadpool的queue size姻报,除非reinitialising thread executor。默認-1间螟。
hystrix.threadpool.default.queueSizeRejectionThreshold 即使maxQueueSize沒有達到吴旋,達到queueSizeRejectionThreshold該值后,請求也會被拒絕厢破。因為maxQueueSize不能被動態(tài)修改荣瑟,這個參數(shù)將允許我們動態(tài)設(shè)置該值。if maxQueueSize == -1摩泪,該字段將不起作用
hystrix.threadpool.default.keepAliveTimeMinutes 如果corePoolSize和maxPoolSize設(shè)成一樣(默認實現(xiàn))該設(shè)置無效笆焰。如果通過plugin(https://github.com/Netflix/Hystrix/wiki/Plugins)使用自定義實現(xiàn),該設(shè)置才有用见坑,默認1.
hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds 線程池統(tǒng)計指標的時間嚷掠,默認10000
hystrix.threadpool.default.metrics.rollingStats.numBuckets 將rolling window劃分為n個buckets,默認10