dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

dubbo+tomcat容器,无法优雅停机

Open wonderlq opened this issue 9 years ago • 8 comments

在服务端和消费端 启动配置中增加了-Ddubbo.service.shutdown.wait=10000 ,也参考了网上优雅停机的源码修改,但是依旧无法实现。kill -pid 服务端,tomcat就马上停了,没有等待请求完成。求助如何实现优雅停机。

wonderlq avatar Aug 02 '17 15:08 wonderlq

停机的具体脚本或命令;以及停机阶段的log能贴一下吗?

chickenlj avatar Aug 03 '17 08:08 chickenlj

在消费端的tomcat增加了一个请求计数器的filter,增加一个实现ServletContextListener的实现,在contextDestroyed做了一个循环,等待请求计数器为0 才跳出循环,否则继续。这样可以实现当消费端tomcat 被kill -pid时,继续等待服务端的返回,直到超时。但是感觉很别扭,想问下,有没有更好的方法。 另外还有,为什么kill -pid tomcat时 ,容器不会受到优雅停机的影响(?)

wonderlq avatar Aug 03 '17 09:08 wonderlq

脚本: `#!/bin/bash source /etc/profile

export CATALINA_HOME=/home/xx/tomcat

if echo $1 | grep -q "/home/xx/webServer" then export CATALINA_BASE=${1%/} else export CATALINA_BASE=/home/xx/webServer/${1%/} fi

instance=ls /home/xx/webServer | head -1; if ! [ -e $CATALINA_BASE/conf/server.xml ] then echo -e " usage: $0 /home/xx/webServer/$instance\n" exit 1; fi

for i in {1..60}; do

TOMCAT_ID=`ps aux |grep "java"|grep "Dcatalina.base=$CATALINA_BASE "|grep -v "grep"|awk '{ print $2}'`

if [ -n "$TOMCAT_ID" ]; then

    if [ "$i" = "1" ]; then
         echo -n "trying stop ($TOMCAT_ID): $i"
         kill "$TOMCAT_ID"
else
         echo -n -e "\b$i"
        
fi

    sleep 1

else
    if [ $i -gt 5 ]; then
        echo -e "\n$TOMCAT_BASE was killed($i)"
    else
        echo -e "\n$TOMCAT_BASE was stoped"
    fi

    exit;
fi

done;

kill -9 "$TOMCAT_ID"`

项目的log日志: 2017-08-03 17:26:17.202 iZ94i8aust9Z - [INFO] http-bio-8020-exec-10 InterFlightB2BServiceImpl test createOrder,createOrderRq: {xxxxxxxxxxxxxxxxx} 2017-08-03 17:26:22.429 iZ94i8aust9Z - [INFO] DubboShutdownHook AbstractConfig [DUBBO] Run shutdown hook now., dubbo version: 2.5.6-SNAPSHOT, current host: xxx.xxx.xx.xxx 2017-08-03 17:26:22.430 iZ94i8aust9Z - [INFO] DubboShutdownHook AbstractRegistryFactory [DUBBO] Close all registries [zookeeper://120.25.xx.xxx:2181/com.alibaba.dubbo.registry.RegistryService?application=b2b&dubbo=2.5.6-SNAPSHOT&file=...... dubbo version: 2.5.6-SNAPSHOT, current host: 10.251.227.249 2017-08-03 17:26:22.431 iZ94i8aust9Z - [INFO] DubboShutdownHook ZookeeperRegistry [DUBBO] Destroy registry:zookeeper://120.25.xx.xxx:2181/com.alibaba.dubbo.registry.RegistryService?application=b2b&dubbo=2.5.6-SNAPSHOT&file=/home/xxx/webServer/b2b/cache/dubbo-registry.properties&group=log.deva&interface=com.alibaba.dubbo.registry.RegistryService&organization=XXdubbo&owner=xxx&pid=29966&timestamp=1501752301353, dubbo version: 2.5.6-SNAPSHOT, current host: 10.251.227.xxx 2017-08-03 17:26:22.431 iZ94i8aust9Z - [INFO] DubboShutdownHook ZookeeperRegistry [DUBBO] Unregister: consumer://10.251.xx.xxx/com.bill.service.BillService?application=fr_intl_b2b&category=consumers&check=false&dubbo=2.5.6-SNAPSHOT&interface=com.bill.service.BillService&methods=update,search,refund,&organization=xxdubbo&owner=xxxx&pid=29966&revision=2.1.5&side=consumer&timeout=50000&timestamp=1501752302787&version=1.0.0, dubbo version: 2.5.6-SNAPSHOT, current host: 10.251.227.249

sorry,一些项目信息去除了,消费端tomcat kill -pid,输出完这些日志后就没了。

wonderlq avatar Aug 03 '17 09:08 wonderlq

请参考我的修改: https://github.com/taige/dubbo/commit/c8c1df022cd0412ee660544028032d5c342cb219

taige avatar Aug 08 '17 06:08 taige

@taige @chickenlj 谢谢你们的帮助。最终采用修改源码+采用平滑发布的方式解决了这个问题。

wonderlq avatar Aug 11 '17 14:08 wonderlq

怎么修改详细说明一下

zhaojianping avatar Aug 12 '17 07:08 zhaojianping

参考了https://my.oschina.net/u/1398931/blog/790709 和 taige的 taige/dubbo@c8c1df0

wonderlq avatar Aug 14 '17 09:08 wonderlq

@chickenlj 看了修复的代码,NettyChannel 中的 lastChannelFuture 定义,怎么保证异步调用的情况一定是最后一个执行完成?这个方案针对同步调用的场景是可行的,但对异步调用的场景好像存在缺陷?

lihuagang03 avatar Sep 08 '17 01:09 lihuagang03