這篇文章主要介紹了SpringCloudHystrix線程池不足怎么辦,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
現象:
昨天突然線上很多接口獲取失敗,通過 kibana發現大量異常,具體異常信息:
...into fallback. Rejected command because thread-pool queueSize is at rejection threshold.
異常代碼出處:
@FeignClient(name = "api", fallbackFactory = LoadBalancingFallbackFactory.class)public interface LoadBalancingFeignClient { @PostMapping(value = "/api/loadBalancing/server") Result currentServer();}@Slf4j@Componentpublic class LoadBalancingFallbackFactory implements FallbackFactory<LoadBalancingFeignClient> { @Override public LoadBalancingFeignClient create(Throwable throwable) { final String msg = throwable.getMessage(); return () -> { log.error("loadBalancingFeignClient currentServer into fallback. {}", msg); return Result.error(); };**** }}
原因:
看到這里已經很明顯了,是由于hystrix線程池不夠用,直接熔斷導致的。項目apollo配置:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds = 3500hystrix.threadpool.default.maxQueueSize = 60hystrix.threadpool.default.queueSizeRejectionThreshold = 40
hystrix參數簡析:
maxQueueSize:線程池大小,默認為-1,創建的隊列是SynchronousQueue,如果設置大于0則根據其大小創建LinkedBlockingQueue。
queueSizeRejectionThreshold:動態控制線程池隊列的上限,即使maxQueueSize沒有達到,達到queueSizeRejectionThreshold該值后,請求也會被拒絕,默認值5
相關源碼:
hystrix-core-1.5.12-sources.jar!/com/netflix/hystrix/strategy/concurrency/HystrixContextScheduler.java
private class HystrixContextSchedulerWorker extends Worker { private final Worker worker; private HystrixContextSchedulerWorker(Worker actualWorker) { this.worker = actualWorker; } @Override public void unsubscribe() { worker.unsubscribe(); } @Override public boolean isUnsubscribed() { return worker.isUnsubscribed(); } @Override public Subscription schedule(Action0 action, long delayTime, TimeUnit unit) { if (threadPool != null) { if (!threadPool.isQueueSpaceAvailable()) { throw new RejectedExecutionException("Rejected command because thread-pool queueSize is at rejection threshold."); } } return worker.schedule(new HystrixContexSchedulerAction(concurrencyStrategy, action), delayTime, unit); } @Override public Subscription schedule(Action0 action) { if (threadPool != null) { if (!threadPool.isQueueSpaceAvailable()) { throw new RejectedExecutionException("Rejected command because thread-pool queueSize is at rejection threshold."); } } return worker.schedule(new HystrixContexSchedulerAction(concurrencyStrategy, action)); } }
解決辦法:
適當調大Hystrix線程隊列參數動態水平擴容服務優化下游服務,減少服務響應時間
感謝你能夠認真閱讀完這篇文章,希望小編分享的“SpringCloudHystrix線程池不足怎么辦”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。