dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

dubbo目前的支持优雅停机吗?

Open SuperDubbo opened this issue 9 years ago • 12 comments

网上很多都说dubbo在服务端和客户端配置参数:-Ddubbo.service.shutdown.wait=30000,该参数为停机等待时间,但是结果也不生效,还是马上停机了。 <dubbo:application name="abc_dubbo"> <dubbo:parameter key="shutdown.timeout" value="60000" /> </dubbo:application>

这个支持吗? 我看了一下dubbo的dubbo.xsd的application的下面并没有dubbo:parameter标签啊

SuperDubbo avatar Jun 23 '17 02:06 SuperDubbo

1 dubbo.service.shutdown.wait需要写在配置文件中dubbo.properties

2 配置了dubbo.service.shutdown.wait的意义是首先停止接收任务,并等待现有任务执行完成,最多等待 XX时间。如果当时没有正在执行的任务,也会立刻停机。

以下是gracefulShutdown代码:

public static void gracefulShutdown(Executor executor, int timeout) {
        if (!(executor instanceof ExecutorService) || isShutdown(executor)) {
            return;
        }
        final ExecutorService es = (ExecutorService) executor;
        try {
            es.shutdown(); // Disable new tasks from being submitted
        } catch (SecurityException ex2) {
            return ;
        } catch (NullPointerException ex2) {
            return ;
        }
        try {
            if(! es.awaitTermination(timeout, TimeUnit.MILLISECONDS)) {
                es.shutdownNow();
            }
        } catch (InterruptedException ex) {
            es.shutdownNow();
            Thread.currentThread().interrupt();
        }
        if (!isShutdown(es)){
            newThreadToCloseExecutor(es);
        }
    }

你可以尝试试试

JackyWoo avatar Jun 23 '17 06:06 JackyWoo

在dubbo.xml中配置不了dubbo.service.shutdown.wait或dubbo.service.shutdown.wait.seconds吗? @JackyWoo @kimmking

SuperDubbo avatar Jun 23 '17 06:06 SuperDubbo

provider标签里有个wait, 你试试管用不

JackyWoo avatar Jun 23 '17 07:06 JackyWoo

你看看官方文档http://dubbo.io/User+Guide-zh.htm#UserGuide-zh-%3Cdubbo%3Aprovider%2F%3E Provider标签下面并没有wait呀@JackyWoo @kimmking

SuperDubbo avatar Jun 23 '17 08:06 SuperDubbo

我看代码里边有的,你可以先试试

JackyWoo avatar Jun 23 '17 08:06 JackyWoo

image 貌似是这个才对吧

SuperDubbo avatar Jun 23 '17 08:06 SuperDubbo

dubbo的原生graceful shutdown是有bug的,仅释放了一些资源但没有尝试等待服务线程结束。 可以采用这个fix:https://github.com/taige/dubbo/commit/c8c1df022cd0412ee660544028032d5c342cb219

taige avatar Aug 08 '17 07:08 taige

@taige ,can you please create a pull request?

lovepoem avatar May 17 '18 15:05 lovepoem

@lovepoem I've created a pull request: https://github.com/apache/incubator-dubbo/pull/505

taige avatar May 18 '18 02:05 taige

now it can only be configed in property file or jvm argument, we will improve it later in https://github.com/apache/incubator-dubbo/issues/1814

qinliujie avatar May 18 '18 03:05 qinliujie

xml配置dubbo:registry dubbo:registry中存在wait标签:表示在注册中心配置的优雅停机的超时时间 在provider.xml中新增: <dubbo:registry address="multicast://224.5.6.7:1234" wait="100000"/>

caneo avatar Aug 28 '18 02:08 caneo

baiji-5 The timeout for getting graceful downtime in dubbo is obtained from the method ConfigUtils.getServerShutdownTimeout, which is to get value of dubbo.service.shutdown.wait (new key) or dubbo.service.shutdown.wait.seconds (old key).

Configure the dubbo:registry configuration wait tag in xml, and the spring tag resolution will configure dubbo.service.shutdown.wait. So configure the wait tag directly in the dubbo:registry. E.g: Added in the configuration file: <dubbo:registry wait="1000"/>

chaoKing avatar Aug 28 '18 03:08 chaoKing