以下內(nèi)容為服務使用hystrix的相關配置明細整理,高版本可能有些許差異。如有不對之處,還望指出,多謝。
以調(diào)用User為例說明如下:
相關源碼配置分別在如下兩個類中HystrixThreadPoolProperties,HystrixCommandProperties
#hystrix線程池相關配置
#設置allowMaximumSizeToDivergeFromCoreSize值為true時,線程池的maximumSize才有作用
hystrix.threadpool.User-SERVICE.allowMaximumSizeToDivergeFromCoreSize=true
hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize=false
#設置線程池的coresize核心線程池數(shù)量,默認為10
hystrix.threadpool.User-SERVICE.coreSize = 20
hystrix.threadpool.default.coreSize = 10
#設置線程池的maximumSize數(shù)量,默認也為10
hystrix.threadpool.User-SERVICE.maximumSize=100
hystrix.threadpool.default.maximumSize=10
#線程池中maximumSize-coresize數(shù)量之后,剩余線程的回收空閑時間,單位為分鐘,默認為一分鐘
hystrix.threadpool.User-SERVICE.keepAliveTimeMinutes=1
hystrix.threadpool.default.keepAliveTimeMinutes= 1
#線程池中的等待隊列,默認為-1,由SynchronousQueue作為隊列實現(xiàn),當為正整數(shù)時,使用LinkedBlockingQueue,
hystrix.threadpool.User-SERVICE.maxQueueSize = 20
hystrix.threadpool.default.maxQueueSize=-1
#因為maxQueueSize值不能被動態(tài)修改,所有通過設置此值可以實現(xiàn)動態(tài)修改等待隊列長度。即等待的隊列的數(shù)量大于queueSizeRejectionThreshold時(但是沒有達到maxQueueSize值),則開始拒絕后續(xù)的請求進入隊列。
#如果設置-1,則屬性不啟作用,默認值:5
hystrix.threadpool.User-SERVICE.queueSizeRejectionThreshold = 5
hystrix.threadpool.default.queueSizeRejectionThreshold = 5
#設置滾動窗口的時間,按照默認值設置即可,無需單獨設置,默認為10000(10)秒滾動窗口統(tǒng)計時間
hystrix.threadpool.User-SERVICE.metrics.rollingStats.timeInMilliseconds=10000
hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds=10000
#設置滾動靜態(tài)窗口分成的桶的數(shù)量,按照默認值設置即可,無需單獨設置,默認為10個桶
hystrix.threadpool.User-SERVICE.metrics.rollingStats.numBuckets=10
hystrix.threadpool.default.metrics.rollingStats.numBuckets=10
#HystrixCommand相關配置,默認隔離級別為thread,只討論thread級別相關配置項,與具體的feign客戶端定義的方法有關系,以下舉例說明
#是否開啟斷路器功能,具體到每一個方法級別,默認啟用true,按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.enabled=true
hystrix.command.default.circuitBreaker.enabled=true
#該屬性設置滾動窗口中將使斷路器跳閘的最小請求數(shù)量如果此屬性值為20,則在窗口時間內(nèi)(如10s內(nèi)),如果只收到19個請求且都失敗了,則斷路器也不會開啟,按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.requestVolumeThreshold = 20
hystrix.command.default.circuitBreaker.requestVolumeThreshold = 20
#斷路器跳閘后,在此設置值的時間的內(nèi),hystrix會拒絕新的請求,只有過了這個時間斷路器才會打開閘門,默認為5000(5秒),按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.sleepWindowInMilliseconds=5000
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=5000
#設置失敗百分比的閾值。如果失敗比率超過這個值,則斷路器跳閘并且進入fallback邏輯,默認百分比為50%,按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.errorThresholdPercentage=50
hystrix.command.default.circuitBreaker.errorThresholdPercentage=50
#如果設置true,則強制使斷路器跳閘,則會拒絕所有的請求.此值會覆蓋circuitBreaker.forceClosed的值,默認為false,按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.forceOpen=false
hystrix.command.default.circuitBreaker.forceOpen=false
#如果設置true,則強制使斷路器進行關閉狀態(tài),此時會允許執(zhí)行所有請求,無論是否失敗的次數(shù)達到circuitBreaker.errorThresholdPercentage值,默認為false,按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.forceClosed=false
hystrix.command.default.circuitBreaker.forceClosed=false
#在默認情況下,推薦HystrixCommands 使用 thread 隔離策略,HystrixObservableCommand 使用 semaphore 隔離策略。只有在高并發(fā)(單個實例每秒達到幾百個調(diào)用)的調(diào)用時,才需要修改HystrixCommands 的隔離策略為semaphore 。semaphore 隔離策略通常只用于非網(wǎng)絡調(diào)用
#按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.strategy = THREAD
hystrix.command.default.execution.isolation.strategy = THREAD
#設置調(diào)用者執(zhí)行的超時時間(單位毫秒),默認為1000(1秒),可根據(jù)具體方法進行設置
hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.timeoutInMilliseconds=1000
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=1000
#表示是否開啟超時設置,默認為true,開啟。按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().execution.timeout.enabled=true
hystrix.command.default.execution.timeout.enabled=true
#表示設置是否在執(zhí)行超時時,中斷HystrixCommand.run() 的執(zhí)行,默認為true。按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.interruptOnTimeout=true
hystrix.command.default.execution.isolation.thread.interruptOnTimeout=true
#當隔離策略為THREAD時,當執(zhí)行線程執(zhí)行超時時,是否進行中斷處理,即Future#cancel(true)處理,默認為false。按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.interruptOnFutureCancel=false
hystrix.command.default.execution.isolation.thread.interruptOnFutureCancel=false
#當HystrixCommand.run()使用SEMAPHORE的隔離策略時,設置最大的并發(fā)量,默認為10個,由于目前只設置Thread隔離級別,暫時只做了解
hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.semaphore.maxConcurrentRequests=10
hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests=10
#屬性設置從調(diào)用線程允許HystrixCommand.getFallback()方法允許的最大并發(fā)請求數(shù)如果達到最大的并發(fā)量,則接下來的請求會被拒絕并且拋出異常.默認為10,由于目前只設置Thread隔離級別,暫時只做了解
hystrix.command.IUserClient#listAllPaymentProduct().fallback.isolation.semaphore.maxConcurrentRequests=10
hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests=10
#是否開啟fallback功能,默認為true。按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().fallback.enabled=true
hystrix.command.default.fallback.enabled=true
#設置滾動窗口的時間,按照默認值設置即可,無需單獨設置,默認為10000(10)秒滾動窗口統(tǒng)計時間,針對具體的方法進行設置,
hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingStats.timeInMilliseconds=10000
hystrix.command.default.metrics.rollingStats.timeInMilliseconds=10000
#是否開啟斷路器功能,具體到每一個方法級別,默認啟用true,按照默認值設置即可,無需單獨設置
hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.enabled=true
hystrix.command.default.circuitBreaker.enabled=true
#設置滾動靜態(tài)窗口分成的桶的數(shù)量,按照默認值設置即可,無需單獨設置,默認為10個桶,具體到每一個方法設置
hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingStats.numBuckets=10
hystrix.command.default.metrics.rollingStats.numBuckets=10
#設置執(zhí)行延遲是否被跟蹤,并且被計算在失敗百分比中。默認為true,如果設置為false,則所有的統(tǒng)計數(shù)據(jù)返回-1
hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.enabled=true
hystrix.command.default.metrics.rollingPercentile.enabled=true
#此屬性設置統(tǒng)計滾動百分比窗口的持續(xù)時間,默認為60000(60秒)
hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.timeInMilliseconds=60000
hystrix.command.default.metrics.rollingPercentile.timeInMilliseconds=60000
#設置統(tǒng)計滾動百分比窗口的桶數(shù)量,默認值為6
hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.numBuckets=6
hystrix.command.default.metrics.rollingPercentile.numBuckets=6
#此屬性設置每個桶保存的執(zhí)行時間的最大值,默認值為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
#采樣時間間隔,默認值為500
hystrix.command.IUserClient#listAllPaymentProduct().metrics.healthSnapshot.intervalInMilliseconds=500
hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds=500
#是否開啟請求緩存功能,默認為true
hystrix.command.IUserClient#listAllPaymentProduct().requestCache.enabled=true
hystrix.command.default.requestCache.enabled=true
#表示是否開啟日志,打印執(zhí)行HystrixCommand的情況和事件,默認為true
hystrix.command.IUserClient#listAllPaymentProduct().requestLog.enabled=true
hystrix.command.default.requestLog.enabled=true