現(xiàn)象:
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),黔西南州企業(yè)網(wǎng)站建設(shè),黔西南州品牌網(wǎng)站建設(shè),網(wǎng)站定制,黔西南州網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,黔西南州網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
昨天突然線上很多接口獲取失敗,通過 kibana發(fā)現(xiàn)大量異常,具體異常信息:
...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 @Component public class LoadBalancingFallbackFactory implements FallbackFactory{ @Override public LoadBalancingFeignClient create(Throwable throwable) { final String msg = throwable.getMessage(); return () -> { log.error("loadBalancingFeignClient currentServer into fallback. {}", msg); return Result.error(); };**** } }
原因:
看到這里已經(jīng)很明顯了,是由于hystrix線程池不夠用,直接熔斷導(dǎo)致的。
項(xiàng)目apollo配置:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds = 3500 hystrix.threadpool.default.maxQueueSize = 60 hystrix.threadpool.default.queueSizeRejectionThreshold = 40
hystrix參數(shù)簡析:
maxQueueSize:線程池大小,默認(rèn)為-1,創(chuàng)建的隊(duì)列是SynchronousQueue,如果設(shè)置大于0則根據(jù)其大小創(chuàng)建LinkedBlockingQueue。
queueSizeRejectionThreshold:動(dòng)態(tài)控制線程池隊(duì)列的上限,即使maxQueueSize沒有達(dá)到,達(dá)到queueSizeRejectionThreshold該值后,請(qǐng)求也會(huì)被拒絕,默認(rèn)值5
相關(guān)源碼:
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)); } }
解決辦法:
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。