Hystrix相關(guān)配置項整理(spring cloud Edgware.SR3版本)

以下內(nèi)容為服務(wù)使用hystrix的相關(guān)配置明細(xì)整理,高版本可能有些許差異。如有不對之處,還望指出,多謝。

以調(diào)用User為例說明如下:

相關(guān)源碼配置分別在如下兩個類中HystrixThreadPoolProperties,HystrixCommandProperties

#hystrix線程池相關(guān)配置

#設(shè)置allowMaximumSizeToDivergeFromCoreSize值為true時,線程池的maximumSize才有作用

hystrix.threadpool.User-SERVICE.allowMaximumSizeToDivergeFromCoreSize=true

hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize=false

#設(shè)置線程池的coresize核心線程池數(shù)量,默認(rèn)為10

hystrix.threadpool.User-SERVICE.coreSize = 20

hystrix.threadpool.default.coreSize = 10

#設(shè)置線程池的maximumSize數(shù)量,默認(rèn)也為10

hystrix.threadpool.User-SERVICE.maximumSize=100

hystrix.threadpool.default.maximumSize=10

#線程池中maximumSize-coresize數(shù)量之后,剩余線程的回收空閑時間,單位為分鐘,默認(rèn)為一分鐘

hystrix.threadpool.User-SERVICE.keepAliveTimeMinutes=1

hystrix.threadpool.default.keepAliveTimeMinutes= 1

#線程池中的等待隊列,默認(rèn)為-1,由SynchronousQueue作為隊列實現(xiàn),當(dāng)為正整數(shù)時,使用LinkedBlockingQueue,

hystrix.threadpool.User-SERVICE.maxQueueSize = 20

hystrix.threadpool.default.maxQueueSize=-1

#因為maxQueueSize值不能被動態(tài)修改,所有通過設(shè)置此值可以實現(xiàn)動態(tài)修改等待隊列長度。即等待的隊列的數(shù)量大于queueSizeRejectionThreshold時(但是沒有達(dá)到maxQueueSize值),則開始拒絕后續(xù)的請求進(jìn)入隊列。

#如果設(shè)置-1,則屬性不啟作用,默認(rèn)值:5

hystrix.threadpool.User-SERVICE.queueSizeRejectionThreshold = 5

hystrix.threadpool.default.queueSizeRejectionThreshold = 5

#設(shè)置滾動窗口的時間,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置,默認(rèn)為10000(10)秒滾動窗口統(tǒng)計時間

hystrix.threadpool.User-SERVICE.metrics.rollingStats.timeInMilliseconds=10000

hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds=10000

#設(shè)置滾動靜態(tài)窗口分成的桶的數(shù)量,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置,默認(rèn)為10個桶

hystrix.threadpool.User-SERVICE.metrics.rollingStats.numBuckets=10

hystrix.threadpool.default.metrics.rollingStats.numBuckets=10

#HystrixCommand相關(guān)配置,默認(rèn)隔離級別為thread,只討論thread級別相關(guān)配置項,與具體的feign客戶端定義的方法有關(guān)系,以下舉例說明

#是否開啟斷路器功能,具體到每一個方法級別,默認(rèn)啟用true,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.enabled=true

hystrix.command.default.circuitBreaker.enabled=true

#該屬性設(shè)置滾動窗口中將使斷路器跳閘的最小請求數(shù)量如果此屬性值為20,則在窗口時間內(nèi)(如10s內(nèi)),如果只收到19個請求且都失敗了,則斷路器也不會開啟,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.requestVolumeThreshold = 20

hystrix.command.default.circuitBreaker.requestVolumeThreshold = 20

#斷路器跳閘后,在此設(shè)置值的時間的內(nèi),hystrix會拒絕新的請求,只有過了這個時間斷路器才會打開閘門,默認(rèn)為5000(5秒),按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.sleepWindowInMilliseconds=5000

hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=5000

#設(shè)置失敗百分比的閾值。如果失敗比率超過這個值,則斷路器跳閘并且進(jìn)入fallback邏輯,默認(rèn)百分比為50%,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.errorThresholdPercentage=50

hystrix.command.default.circuitBreaker.errorThresholdPercentage=50

#如果設(shè)置true,則強制使斷路器跳閘,則會拒絕所有的請求.此值會覆蓋circuitBreaker.forceClosed的值,默認(rèn)為false,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.forceOpen=false

hystrix.command.default.circuitBreaker.forceOpen=false

#如果設(shè)置true,則強制使斷路器進(jìn)行關(guān)閉狀態(tài),此時會允許執(zhí)行所有請求,無論是否失敗的次數(shù)達(dá)到circuitBreaker.errorThresholdPercentage值,默認(rèn)為false,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.forceClosed=false

hystrix.command.default.circuitBreaker.forceClosed=false

#在默認(rèn)情況下,推薦HystrixCommands 使用 thread 隔離策略,HystrixObservableCommand 使用 semaphore 隔離策略。只有在高并發(fā)(單個實例每秒達(dá)到幾百個調(diào)用)的調(diào)用時,才需要修改HystrixCommands 的隔離策略為semaphore 。semaphore 隔離策略通常只用于非網(wǎng)絡(luò)調(diào)用

#按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.strategy = THREAD

hystrix.command.default.execution.isolation.strategy = THREAD

#設(shè)置調(diào)用者執(zhí)行的超時時間(單位毫秒),默認(rèn)為1000(1秒),可根據(jù)具體方法進(jìn)行設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.timeoutInMilliseconds=1000

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=1000

#表示是否開啟超時設(shè)置,默認(rèn)為true,開啟。按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().execution.timeout.enabled=true

hystrix.command.default.execution.timeout.enabled=true

#表示設(shè)置是否在執(zhí)行超時時,中斷HystrixCommand.run() 的執(zhí)行,默認(rèn)為true。按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.interruptOnTimeout=true

hystrix.command.default.execution.isolation.thread.interruptOnTimeout=true

#當(dāng)隔離策略為THREAD時,當(dāng)執(zhí)行線程執(zhí)行超時時,是否進(jìn)行中斷處理,即Future#cancel(true)處理,默認(rèn)為false。按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.interruptOnFutureCancel=false

hystrix.command.default.execution.isolation.thread.interruptOnFutureCancel=false

#當(dāng)HystrixCommand.run()使用SEMAPHORE的隔離策略時,設(shè)置最大的并發(fā)量,默認(rèn)為10個,由于目前只設(shè)置Thread隔離級別,暫時只做了解

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.semaphore.maxConcurrentRequests=10

hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests=10

#屬性設(shè)置從調(diào)用線程允許HystrixCommand.getFallback()方法允許的最大并發(fā)請求數(shù)如果達(dá)到最大的并發(fā)量,則接下來的請求會被拒絕并且拋出異常.默認(rèn)為10,由于目前只設(shè)置Thread隔離級別,暫時只做了解

hystrix.command.IUserClient#listAllPaymentProduct().fallback.isolation.semaphore.maxConcurrentRequests=10

hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests=10

#是否開啟fallback功能,默認(rèn)為true。按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().fallback.enabled=true

hystrix.command.default.fallback.enabled=true

#設(shè)置滾動窗口的時間,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置,默認(rèn)為10000(10)秒滾動窗口統(tǒng)計時間,針對具體的方法進(jìn)行設(shè)置,

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingStats.timeInMilliseconds=10000

hystrix.command.default.metrics.rollingStats.timeInMilliseconds=10000

#是否開啟斷路器功能,具體到每一個方法級別,默認(rèn)啟用true,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.enabled=true

hystrix.command.default.circuitBreaker.enabled=true

#設(shè)置滾動靜態(tài)窗口分成的桶的數(shù)量,按照默認(rèn)值設(shè)置即可,無需單獨設(shè)置,默認(rèn)為10個桶,具體到每一個方法設(shè)置

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingStats.numBuckets=10

hystrix.command.default.metrics.rollingStats.numBuckets=10

#設(shè)置執(zhí)行延遲是否被跟蹤,并且被計算在失敗百分比中。默認(rèn)為true,如果設(shè)置為false,則所有的統(tǒng)計數(shù)據(jù)返回-1

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.enabled=true

hystrix.command.default.metrics.rollingPercentile.enabled=true

#此屬性設(shè)置統(tǒng)計滾動百分比窗口的持續(xù)時間,默認(rèn)為60000(60秒)

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.timeInMilliseconds=60000

hystrix.command.default.metrics.rollingPercentile.timeInMilliseconds=60000

#設(shè)置統(tǒng)計滾動百分比窗口的桶數(shù)量,默認(rèn)值為6

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.numBuckets=6

hystrix.command.default.metrics.rollingPercentile.numBuckets=6

#此屬性設(shè)置每個桶保存的執(zhí)行時間的最大值,默認(rèn)值為100。如果桶數(shù)量是100,統(tǒng)計窗口為10s,如果這10s里有500次執(zhí)行,只有最后100次執(zhí)行會被統(tǒng)計到bucket里去

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.bucketSize=100

hystrix.command.default.metrics.rollingPercentile.bucketSize=100

#采樣時間間隔,默認(rèn)值為500

hystrix.command.IUserClient#listAllPaymentProduct().metrics.healthSnapshot.intervalInMilliseconds=500

hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds=500

#是否開啟請求緩存功能,默認(rèn)為true

hystrix.command.IUserClient#listAllPaymentProduct().requestCache.enabled=true

hystrix.command.default.requestCache.enabled=true

#表示是否開啟日志,打印執(zhí)行HystrixCommand的情況和事件,默認(rèn)為true

hystrix.command.IUserClient#listAllPaymentProduct().requestLog.enabled=true

hystrix.command.default.requestLog.enabled=true

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請通過簡信或評論聯(lián)系作者。

友情鏈接更多精彩內(nèi)容