SpringCloud微服務專案實戰 - 限流、熔斷、降級處理
阿新 • • 發佈:2021-06-17
# Hystrix 預設載入的配置檔案 - 限流、 熔斷 hystrix: # 執行緒池大小 threadpool: default: coreSize: 1 maxQueueSize: 200 queueSizeRejectionThreshold: 2 # 限流策略 #如果沒有定義HystrixThreadPoolKey,HystrixThreadPoolKey會預設定義為HystrixCommandGroupKey的值 userGroup: coreSize: 1 maxQueueSize: -1 queueSizeRejectionThreshold: 800 userThreadPool: coreSize: 1 maxQueueSize: -1 queueSizeRejectionThreshold: 800 # 執行策略 # 資源隔離模式,預設thread。還有一種叫訊號量 command: default: execution: isolation: strategy: THREAD # 是否開啟超時 timeout: enabled: true # 超時時間,預設1000毫秒 isolation: thread: timeoutInMilliseconds: 15000 # 超時時中斷執行緒 interruptOnTimeout: true # 取消時候中斷執行緒 interruptOnFutureCancel: false # 訊號量模式下,最大併發量 semaphore: maxConcurrentRequests:2 # 降級策略 # 是否開啟服務降級 fallback: enabled: true # fallback執行併發量 isolation: semaphore: maxConcurrentRequests: 100 # 熔斷策略 # 啟用/禁用熔斷機制 circuitBreaker: enabled: true # 強制開啟熔斷 forceOpen: false # 強制關閉熔斷 forceClosed: false # 前提條件,一定時間內發起一定數量的請求。也就是5秒鐘內(這個5秒對應下面的滾動視窗長度)至少請求4次,熔斷器才發揮起作用。預設20 requestVolumeThreshold: 4 # 錯誤百分比。達到或超過這個百分比,熔斷器開啟。比如:5秒內有4個請求,2個請求超時或者失敗,就會自動開啟熔斷 errorThresholdPercentage: 50 # 10秒後,進入半開啟狀態(熔斷開啟,間隔一段時間後,會讓一部分的命令去請求服務提供者,如果結果依舊是失敗,則又會進入熔斷狀態,如果成功,就關閉熔斷)。預設5秒 sleepWindowInMilliseconds: 10000 # 度量策略 # 5秒為一次統計週期,術語描述:滾動視窗的長度為5秒 metrics: rollingStats: timeInMilliseconds: 5000 # 統計週期內 度量桶的數量,必須被timeInMilliseconds整除。作用: numBuckets: 10 # 是否收集執行時間,並計算各個時間段的百分比 rollingPercentile: enabled: true # 設定執行時間統計週期為多久,用來計算百分比 timeInMilliseconds: 60000 # 執行時間統計週期內,度量桶的數量 numBuckets: 6 # 執行時間統計週期內,每個度量桶最多統計多少條記錄。設定為50,有100次請求,則只會統計最近的10次 bucketSize: 100 # 資料取樣時間間隔 healthSnapshot: intervalInMilliseconds: 500 # 設定是否快取請求,request-scope內快取 requestCache: enabled: false # 設定HystrixCommand執行和事件是否列印到HystrixRequestLog中 equestLog: enabled:false userCommandKey: execution: isolation: thread: timeoutInMilliseconds: 5000 ———————————————— 版權宣告:本文為CSDN博主「鍵盤客」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。 原文連結:https://blog.csdn.net/u011134780/article/details/107171958/