目录

异常信息

问题重现

解决办法


异常信息

在dubbo服务化时,有时会遇到这样的异常信息:

Caused by: com.alibaba.dubbo.remoting.RemotingException: Server side(192.168.202.56,20880) threadpool is exhausted ,detail msg:Thread pool is EXHAUSTED! Thread Name: DubboServerHandler-192.168.202.56:20880, Pool Size: 200 (active: 200, core: 200, max: 200, largest: 200), Task: 3986 (completed: 3786), Executor status:(isShutdown:false, isTerminated:false, isTerminating:false), in dubbo://192.168.202.56:20880!at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:245) ~[dubbo-2.6.8.jar:2.6.8]at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:162) ~[dubbo-2.6.8.jar:2.6.8]at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:135) ~[dubbo-2.6.8.jar:2.6.8]at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:95) ~[dubbo-2.6.8.jar:2.6.8]... 70 more

也就是dubbo服务端线程池耗尽,用jvisualVM查看线程状态:

问题重现

在服务端写测试代码如下:

 @Overridepublic HospitalDeptVO getDeptById(String id) {while(true) {System.out.println("当前线程------------------"+Thread.currentThread().getName());}}

调用端代码:

/**
* <p><b>Description:</b> </p>
* <p>Copyright: Copyright (c) </p>
* @author wangzhj
* @date 2020年8月14日
* @version 1.0
*/  package com.yky.file.controller;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;import com.yky.commons.tools.log.Logger;
import com.yky.commons.tools.log.LoggerFactory;
import com.yky.mdm.api.provider.basics.DeptProvider;/**
* <p><b>Description:</b>启动事件处理器 </p>
* @author wangzhj
* @date 2020年8月14日
*/
@Component
public class ProcessorBoot implements ApplicationListener<ContextRefreshedEvent> {@AutowiredDeptProvider deptProvider;/** * <p><b>Description:</b> </p>  * @param arg0  * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)  */@Overridepublic void onApplicationEvent(ContextRefreshedEvent event) {if(event.getApplicationContext().getParent() == null){for(int i = 0;;i++) {try {deptProvider.getDeptById("xxx");} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}System.out.println("第"+i+"次调用");}
//            while(true) {
//                deptProvider.getDeptById("xxx");
//                //Thread.sleep(1000);
//
//            }}}}

问题的原因是服务提供端的线程一直不释放(while true循环),最终导致服务端线程耗尽。

解决办法

服务端配置executes参数。

如果是以上代码的逻辑,调用端为单线程,不存在多线程并发调用时,在调用端配置actives参数是不起作用的,原因看以下代码ActiveLimitFilter:

/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements.  See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You under the Apache License, Version 2.0* (the "License"); you may not use this file except in compliance with* the License.  You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package com.alibaba.dubbo.rpc.filter;import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcStatus;/*** LimitInvokerFilter*/
@Activate(group = Constants.CONSUMER, value = Constants.ACTIVES_KEY)
public class ActiveLimitFilter implements Filter {@Overridepublic Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {URL url = invoker.getUrl();String methodName = invocation.getMethodName();int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0);RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName());if (max > 0) {long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0);long start = System.currentTimeMillis();long remain = timeout;int active = count.getActive();if (active >= max) {synchronized (count) {while ((active = count.getActive()) >= max) {try {count.wait(remain);} catch (InterruptedException e) {}long elapsed = System.currentTimeMillis() - start;remain = timeout - elapsed;if (remain <= 0) {throw new RpcException("Waiting concurrent invoke timeout in client-side for service:  "+ invoker.getInterface().getName() + ", method: "+ invocation.getMethodName() + ", elapsed: " + elapsed+ ", timeout: " + timeout + ". concurrent invokes: " + active+ ". max concurrent invoke limit: " + max);}}}}}try {long begin = System.currentTimeMillis();//调用前并发数加1,单线程时,此时加1后变为1RpcStatus.beginCount(url, methodName);try {//调用服务Result result = invoker.invoke(invocation);//调用服务后并发数减1,单线程时,此时加1后变为0RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true);return result;} catch (RuntimeException t) {//调用服务后并发数减1,单线程时,此时加1后变为0RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false);throw t;}} finally {if (max > 0) {synchronized (count) {count.notify();}}}}}

以上代码有如下的逻辑:

             //调用前并发数加1RpcStatus.beginCount(url, methodName);try {//调用服务Result result = invoker.invoke(invocation);//调用后并发数减1RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true);return result;} catch (RuntimeException t) {//调用后并发数减1RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false);throw t;}

因为是单线程,最大并发数始终是1,用于不会超过在调用端设置的actives参数,所以但线程情况下调用端配置actives是不起作用的。

dubbo服务端线程池耗尽Server side threadpool is exhausted相关推荐

  1. Dubbo学习记录(十五) - 服务调用【一】-之 服务端Netty的hander包装过程与 服务端线程模型

    Dubbo服务调用 之前写十几篇文章, 自己对Dubbo的运行有了一定的了解.而Dubbo服务调用则是重中之重, 目测将这个过程写出来起码需要5-6篇文章: 服务端Netty的hander包装 服务导 ...

  2. 没想到吧!关于Dubbo的『消费端线程池模型』官网也写错了。

    这是why的第 63 篇原创文章 荒腔走板 大家好,我是 why,欢迎来到我连续周更优质原创文章的第 63 篇.老规矩,先荒腔走板聊聊其他的. 上面这张图片是我前几天整理相册的时候看到的.拍摄于 20 ...

  3. Zookeeper服务端线程分析(单机)

    Zookeeper单机模式下启动类为ZooKeeperServerMain#runFromConfig, 调用过程可参考:http://naotu.baidu.com/file/2... ZooKee ...

  4. dubbo 服务压测_不可忽视的Dubbo线程池

    问题描述 线上突然出现Dubbo超时调用,时间刚好为Consumer端设置的超时时间. 有好几个不同的接口都报超时了 第1次调用超时,第2次(或第3次)重试调用非常快(正常水平) Dubbo调用超时的 ...

  5. Dubbo线程池耗尽问题

    场景:dubbo 线程池耗尽,报错. Caused by: java.util.concurrent.RejectedExecutionException: Thread pool is EXHAUS ...

  6. 微服务工程消费dubbo服务的配置

    1. 应用场景 微服务工程,按规范不做xml文件的配置,同时需要调用其他工程提供的dubbo服务 2. 接口引入方式 l Jar包引入方式 通过maven pom文件,引入其他工程的api jar包. ...

  7. dubbo服务接口如何mock_2019年Dubbo你掌握的如何?快看看这30道高频面试题!

    前言 Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.简单的说,dubbo就是个服务框架,如果没有分布式的需求,其实是不需要用的,只有在分布式 ...

  8. Dubbo——服务暴露过程分析

    这篇文章来叙述对dubbo的服务暴露前的准备工作: 使用Spring配置文件,通过main方法来启动spring容器,来观察dubbo服务的启动过程. dubbo配置文件 <context:co ...

  9. Dubbo:Dubbo服务发现

    文章目录 Dubbo服务发现 1. Dubbo服务架构 2. 案例环境搭建 3. service2微服务 3.1 定义service2-api 3.2 定义service2-server 4. app ...

  10. Goroutine并发调度模型深度解析之手撸一个协程池

    Goroutine & Scheduler Goroutine,Go语言基于并发(并行)编程给出的自家的解决方案.goroutine是什么?通常goroutine会被当做coroutine(协 ...

最新文章

  1. 飞思卡尔烧写工具mfgtools的使用
  2. 【2021云边协同大会】阿里云周哲畅聊边缘云基础设施创新发展及场景化实践
  3. [NOTE] 关于DNSLog平台的使用
  4. error: stray '\343' in program 问题解决
  5. JS之onsubmit事件与组织事件外延
  6. java 线程数_在虚拟机中是什么限制java线程数量?这方面涉及哪些调优?
  7. Intellij IDEA社区版集成Maven插件
  8. 十大硬盘数据恢复软件简评
  9. PowerBuilder快速入门实践
  10. jboss-5.1.0_JBoss企业SOA平台5.0和Developer Studio 3.0
  11. 2015年第六届C/C++ B组蓝桥杯省赛真题
  12. 【离散数学】单射、满射与双射
  13. oracle ora-3136,ORA-3136 错误解决 .
  14. bzoj4399 魔法少女LJJ
  15. oj趣味题:柱状图排序
  16. Win10如何彻底禁用小娜?彻底禁用小娜的方法
  17. 和印度人交往的一点感受
  18. blos禁止计算机休眠,电脑不能休眠待机
  19. java入门基础二 15-18 之三大集合
  20. 格式工厂安装流程记录

热门文章

  1. Visual Studio安装以及增加工具集C盘占用问题
  2. 51单片机 8位7段数码管静态显示
  3. 在v$lock里找Holder和Waiter
  4. Gris游戏开发-day03
  5. 关于侵权Sinesafe官方网站,仿冒、抄袭等恶劣行为的公告
  6. python中面向对象编程简称为_Python-面向对象编程
  7. 设计模式知我所见。。。
  8. See Electrical 7 R2 B11电气设计软件PLS-CADD v12.3架空电力线设计软件
  9. AddressBook、AddressBookUI、Contacts、ContactsUI 通讯录操作
  10. 比 Java 更强大的 kotlin.Deprecated