温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SpringCloudHystrix线程池不足怎么办

发布时间:2021-09-26 10:54:26 来源:亿速云 阅读:181 作者:小新 栏目:编程语言

这篇文章主要介绍了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线程池不足怎么办”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI