dubbo3 RPC超时

Timeout

获取超时时间

dubbo RPC 调用的超时时间在provider端或者consumer端设置都可以,consumer在调用时,会去获取超时时间,超时时间的获取顺序: consumer 引用配置的超时时间(ReferenceConfig.timeout) > provider 服务暴露的超时时间(ServiceConfig.timeout) > 默认超时时间(1000ms)
调用栈:
dubbo3 RPC超时_第1张图片
consumer/provider 优先级顺序的逻辑在InstanceAddressURL中,在该类中,即有consumer URL,也有provider的service 信息,获取逻辑的代码如下:
InstanceAddressURL#getMethodParameter()

    @Override
    public String getMethodParameter(String method, String key) {
        if (consumerParamFirst(key)) {
            URL consumerUrl = RpcContext.getServiceContext().getConsumerUrl();
            if (consumerUrl != null) {
                String v = consumerUrl.getMethodParameter(method, key);
                if (StringUtils.isNotEmpty(v)) {
                    return v;
                }
            }
        }

        String protocolServiceKey = getProtocolServiceKey();
        if (isEmpty(protocolServiceKey)) {
            return null;
        }
        return getServiceMethodParameter(protocolServiceKey, method, key);
    }

RPC调用

dubbo rpc调用底层是通过netty nio tcp实现的通信交互,在tcp的通信层是异步的,如果我们以同步的方式调用接口,就涉及到异步转同步,dubbo中关于异步转同步采用的是DefaultFuture,它继承自java.util.concurrent.CompletableFuture;
具体的步骤如下:

  1. consumer 新建一个DefaultFuture对象,将其放入一个静态的Map中,key是request.id
  2. consumer 发送request请求,并调用AsyncRpcResult.get(long, TimeUnit) (为什么没有调用DefaultFuture.get(long, TimeUnit)请看下一节)
  3. provider处理完业务逻辑后,在返回时将request.id一并返回过来
  4. consumer收回响应后,通过request.id再获取到DefaultFuture对象,再调用该对象的complete()方法

以上一次RPC的正常流程,但是超时流程在另一分支,不过代码逻辑是一样一样的。

RPC 超时处理

dubbo超时处理逻辑有三处:

  1. DefaultFuture.timeoutCheck()
    该方法是在创建DefaultFuture时,就会被执行
    public static DefaultFuture newFuture(Channel channel, Request request, int timeout, ExecutorService executor) {
        final DefaultFuture future = new DefaultFuture(channel, request, timeout);
        future.setExecutor(executor);
        // ThreadlessExecutor needs to hold the waiting future in case of circuit return.
        if (executor instanceof ThreadlessExecutor) {
            ((ThreadlessExecutor) executor).setWaitingFuture(future);
        }
        // timeout check
        timeoutCheck(future);
        long diff = System.currentTimeMillis() - future.start;
        if(diff>5){
            System.out.println("diff: " + diff);
        }
        return future;
    }

该方法会创建一个TimeoutCheckTask添加到dubbo的时间轮中处理,代码如下:

    private static void timeoutCheck(DefaultFuture future) {
        TimeoutCheckTask task = new TimeoutCheckTask(future.getId());
        future.timeoutCheckTask = TIME_OUT_TIMER.get().newTimeout(task, future.getTimeout(), TimeUnit.MILLISECONDS);
    }
  1. AsyncRpcResult.get(long, TimeUnit)
    获取响应的调用链:
    dubbo3 RPC超时_第2张图片
    调用的是AsyncRpcResult.get(long, TimeUtit)方法;
    AsyncRpcResult是dubbo对于响应结果的统一封装,获取结果的有两个方法:
    @Override
    public Result get() throws InterruptedException, ExecutionException {
        if (executor != null && executor instanceof ThreadlessExecutor) {
            ThreadlessExecutor threadlessExecutor = (ThreadlessExecutor) executor;
            threadlessExecutor.waitAndDrain();
        }
        return responseFuture.get();
    }

    @Override
    public Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        if (executor != null && executor instanceof ThreadlessExecutor) {
            ThreadlessExecutor threadlessExecutor = (ThreadlessExecutor) executor;
            threadlessExecutor.waitAndDrain();
        }
        return responseFuture.get(timeout, unit);
    }

两个方法中都有ThreadlessExecutor的判断,以及threadlessExecutor.waitAndDrain()的调用,该方法会一直等待,直到有响应结果为止。
ThreadlessExecutor是 duubo2.7版本中引入的,它在dubbo中应用于同步的RPC方法。
dubbo会在发起RPC调用之前检查是否为同步调用,如果是就创建ThreadlessExecutor用于后面的RPC流程中。
dubbo3 RPC超时_第3张图片
AbstractInvoker.getCallbackExecutor()方法代码:

    protected ExecutorService getCallbackExecutor(URL url, Invocation inv) {
        if (InvokeMode.SYNC == RpcUtils.getInvokeMode(getUrl(), inv)) {
            return new ThreadlessExecutor();
        }
        return url.getOrDefaultApplicationModel().getExtensionLoader(ExecutorRepository.class)
            .getDefaultExtension()
            .getExecutor(url);
    }
  1. TimeoutCheckTask
    TimeoutCheckTask会被添加到时间轮中,超时时间到就会被执行;TimeoutCheckTask逻辑比较简单,传递一个超时的结果;
    代码如下:
    private static class TimeoutCheckTask implements TimerTask {

        private final Long requestID;

        TimeoutCheckTask(Long requestID) {
            this.requestID = requestID;
        }

        @Override
        public void run(Timeout timeout) {
            DefaultFuture future = DefaultFuture.getFuture(requestID);
            long end = System.currentTimeMillis();
            if (future == null || future.isDone()) {
                return;
            }

            if (future.getExecutor() != null) {
                future.getExecutor().execute(() -> notifyTimeout(future));
            } else {
                notifyTimeout(future);
            }
        }

        private void notifyTimeout(DefaultFuture future) {
            // create exception response.
            Response timeoutResponse = new Response(future.getId());
            // set timeout status.
            timeoutResponse.setStatus(future.isSent() ? Response.SERVER_TIMEOUT : Response.CLIENT_TIMEOUT);
            timeoutResponse.setErrorMessage(future.getTimeoutMessage(true));
            // handle response.
            DefaultFuture.received(future.getChannel(), timeoutResponse, true);
        }
    }

ThreadlessExecutor

在duubo2.7版本中引入了ThreadlessExecutor,它能避免一次线程上下文切换,实际上也是通过队列实现的。
下面是ThreadlessExecutor的三个核心方法:

  • waitAndDrain()
    从队列中获取任务执行,如果队列为空,则等待直到有任务入队列。
  • execute(Runnable)
    将任务添加到队列中
  • notifyReturn(Throwable)
    添加任务入队列,该任务是将Throwable赋值给DefaultFuture。

代码如下:

    private final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();

    public void waitAndDrain() throws InterruptedException {
        /**
         * Usually, {@link #waitAndDrain()} will only get called once. It blocks for the response for the first time,
         * once the response (the task) reached and being executed waitAndDrain will return, the whole request process
         * then finishes. Subsequent calls on {@link #waitAndDrain()} (if there're any) should return immediately.
         *
         * There's no need to worry that {@link #finished} is not thread-safe. Checking and updating of
         * 'finished' only appear in waitAndDrain, since waitAndDrain is binding to one RPC call (one thread), the call
         * of it is totally sequential.
         */
        if (isFinished()) {
            return;
        }

        Runnable runnable;
        try {
            runnable = queue.take();
        } catch (InterruptedException e) {
            setWaiting(false);
            throw e;
        }

        synchronized (lock) {
            setWaiting(false);
            runnable.run();
        }

        runnable = queue.poll();
        while (runnable != null) {
            runnable.run();
            runnable = queue.poll();
        }
        // mark the status of ThreadlessExecutor as finished.
        setFinished(true);
    }

    /**
     * If the calling thread is still waiting for a callback task, add the task into the blocking queue to wait for schedule.
     * Otherwise, submit to shared callback executor directly.
     *
     * @param runnable
     */
    @Override
    public void execute(Runnable runnable) {
        runnable = new RunnableWrapper(runnable);
        synchronized (lock) {
            if (!isWaiting()) {
                runnable.run();
                return;
            }
            queue.add(runnable);
        }
    }
    
    public void notifyReturn(Throwable t) {
        // an empty runnable task.
        execute(() -> {
            waitingFuture.completeExceptionally(t);
        });
    }

超时调用栈:
dubbo3 RPC超时_第4张图片

正常响应调用栈:
dubbo3 RPC超时_第5张图片
AllChannelHandler又涉及到dubbo的Dispatcher,这部分内容请自行浏览其它文章。

HashedWheelTimer

本节主要介绍时间轮在dubbo超时场景中的应用,关于其实现及原理这里不过多赘述。
dubbo的时间轮采用的是轮次的方式,每一轮次都有周期/间隔时间(Duration),一个任务加入到时间轮后,时间轮并不能保证其精确的超时;
比如一个超时时间为5ms的超时任务在T1时间点加入时间轮,那么期望该任务超时T1+5ms时就被执行;但dubbo的时间轮并不是这样的,时间轮会计算当前轮次的时间点(Duration * times + startTime),如果任务的超时时间< 当前轮次时间点,就会被执行;
以T1+5ms的任务为例,T1+5ms < (Duration * times + startTime), 该任务就会被执行,startTime是时间轮创建启动的时间点。
所以时间轮中的任务被执行的最大延迟时间是 Duration - 1
dubbo3默认的时间轮Duration是30ms

验证

时间点:

时间点 说明
start dubbo service开始调用的时间
DefaultFuture.starttime 创建DefaultFuture的时间
DefaultFuture.inwheeltime 入时间轮的时间
DefaultFuture.senttime 发送request请求的时间
DefaultFuture.timeoutstart 超时;DefaultFuture.TimeoutCheckTask开始执行的时间
DefaultFuture.timeoutend DefaultFuture.TimeoutCheckTask.notifyTimeout方法执行完成的时间
AllChannelHandler.receivedtime netty接收到Result消息的时间
DefaultFuture.receivetime DefaultFuture处理接收消息的时间
end dubbo service方法调用结束的时间(正常响应/超时)

正常调用

1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:22:35:074 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:35.05, DefaultFuture.startTime: 2022-04-06T21:22:35.051, diff: 1 ms
[06/04/22 21:22:35:075 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:35.051, DefaultFuture.inwheeltime:2022-04-06T21:22:35.051 diff: 0 ms
[06/04/22 21:22:35:075 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:35.051, DefaultFuture.senttime:2022-04-06T21:22:35.055 diff: 4 ms
[06/04/22 21:22:35:075 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:22:35.071, DefaultFuture.senttime: 2022-04-06T21:22:35.055, diff: 16 ms
[06/04/22 21:22:35:076 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:22:35.071, end:2022-04-06T21:22:35.073 diff: 2 ms
[06/04/22 21:22:35:076 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:35.05, end: 2022-04-06T21:22:35.073, diff: 23 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:22:36:089 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:36.081, DefaultFuture.startTime: 2022-04-06T21:22:36.082, diff: 1 ms
[06/04/22 21:22:36:089 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:36.082, DefaultFuture.inwheeltime:2022-04-06T21:22:36.082 diff: 0 ms
[06/04/22 21:22:36:090 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:36.082, DefaultFuture.senttime:2022-04-06T21:22:36.086 diff: 4 ms
[06/04/22 21:22:36:090 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:22:36.088, DefaultFuture.senttime: 2022-04-06T21:22:36.086, diff: 2 ms
[06/04/22 21:22:36:090 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:22:36.088, end:2022-04-06T21:22:36.088 diff: 0 ms
[06/04/22 21:22:36:091 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:36.081, end: 2022-04-06T21:22:36.088, diff: 7 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:22:37:103 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:37.095, DefaultFuture.startTime: 2022-04-06T21:22:37.096, diff: 1 ms
[06/04/22 21:22:37:103 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:37.096, DefaultFuture.inwheeltime:2022-04-06T21:22:37.096 diff: 0 ms
[06/04/22 21:22:37:103 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:37.096, DefaultFuture.senttime:2022-04-06T21:22:37.097 diff: 1 ms
[06/04/22 21:22:37:103 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:22:37.102, DefaultFuture.senttime: 2022-04-06T21:22:37.097, diff: 5 ms
[06/04/22 21:22:37:103 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:22:37.102, end:2022-04-06T21:22:37.102 diff: 0 ms
[06/04/22 21:22:37:103 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:37.095, end: 2022-04-06T21:22:37.102, diff: 7 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:22:38:116 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:38.108, DefaultFuture.startTime: 2022-04-06T21:22:38.109, diff: 1 ms
[06/04/22 21:22:38:116 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:38.109, DefaultFuture.inwheeltime:2022-04-06T21:22:38.109 diff: 0 ms
[06/04/22 21:22:38:116 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:38.109, DefaultFuture.senttime:2022-04-06T21:22:38.11 diff: 1 ms
[06/04/22 21:22:38:117 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:22:38.114, DefaultFuture.senttime: 2022-04-06T21:22:38.11, diff: 4 ms
[06/04/22 21:22:38:117 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:22:38.114, end:2022-04-06T21:22:38.115 diff: 1 ms
[06/04/22 21:22:38:117 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:38.108, end: 2022-04-06T21:22:38.115, diff: 7 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:22:39:127 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:39.122, DefaultFuture.startTime: 2022-04-06T21:22:39.123, diff: 1 ms
[06/04/22 21:22:39:127 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:39.123, DefaultFuture.inwheeltime:2022-04-06T21:22:39.123 diff: 0 ms
[06/04/22 21:22:39:127 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:22:39.123, DefaultFuture.senttime:2022-04-06T21:22:39.124 diff: 1 ms
[06/04/22 21:22:39:128 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:22:39.126, DefaultFuture.senttime: 2022-04-06T21:22:39.124, diff: 2 ms
[06/04/22 21:22:39:128 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:22:39.126, end:2022-04-06T21:22:39.127 diff: 1 ms
[06/04/22 21:22:39:128 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:22:39.122, end: 2022-04-06T21:22:39.127, diff: 5 ms

正常调用 provider sleep 10ms

1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:24:23:193 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:23.168, DefaultFuture.startTime: 2022-04-06T21:24:23.168, diff: 0 ms
[06/04/22 21:24:23:193 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:23.168, DefaultFuture.inwheeltime:2022-04-06T21:24:23.168 diff: 0 ms
[06/04/22 21:24:23:193 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:23.168, DefaultFuture.senttime:2022-04-06T21:24:23.17 diff: 2 ms
[06/04/22 21:24:23:194 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:24:23.192, DefaultFuture.senttime: 2022-04-06T21:24:23.17, diff: 22 ms
[06/04/22 21:24:23:194 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:24:23.192, end:2022-04-06T21:24:23.193 diff: 1 ms
[06/04/22 21:24:23:194 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:23.168, end: 2022-04-06T21:24:23.193, diff: 25 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:24:24:214 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:24.198, DefaultFuture.startTime: 2022-04-06T21:24:24.199, diff: 1 ms
[06/04/22 21:24:24:214 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:24.199, DefaultFuture.inwheeltime:2022-04-06T21:24:24.199 diff: 0 ms
[06/04/22 21:24:24:214 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:24.199, DefaultFuture.senttime:2022-04-06T21:24:24.2 diff: 1 ms
[06/04/22 21:24:24:214 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:24:24.213, DefaultFuture.senttime: 2022-04-06T21:24:24.2, diff: 13 ms
[06/04/22 21:24:24:215 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:24:24.213, end:2022-04-06T21:24:24.214 diff: 1 ms
[06/04/22 21:24:24:215 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:24.198, end: 2022-04-06T21:24:24.214, diff: 16 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:24:25:236 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:25.219, DefaultFuture.startTime: 2022-04-06T21:24:25.22, diff: 1 ms
[06/04/22 21:24:25:236 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:25.22, DefaultFuture.inwheeltime:2022-04-06T21:24:25.22 diff: 0 ms
[06/04/22 21:24:25:236 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:25.22, DefaultFuture.senttime:2022-04-06T21:24:25.221 diff: 1 ms
[06/04/22 21:24:25:237 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:24:25.235, DefaultFuture.senttime: 2022-04-06T21:24:25.221, diff: 14 ms
[06/04/22 21:24:25:237 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:24:25.235, end:2022-04-06T21:24:25.236 diff: 1 ms
[06/04/22 21:24:25:237 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:25.219, end: 2022-04-06T21:24:25.236, diff: 17 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:24:26:259 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:26.242, DefaultFuture.startTime: 2022-04-06T21:24:26.243, diff: 1 ms
[06/04/22 21:24:26:259 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:26.243, DefaultFuture.inwheeltime:2022-04-06T21:24:26.243 diff: 0 ms
[06/04/22 21:24:26:259 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:26.243, DefaultFuture.senttime:2022-04-06T21:24:26.243 diff: 0 ms
[06/04/22 21:24:26:259 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:24:26.258, DefaultFuture.senttime: 2022-04-06T21:24:26.243, diff: 15 ms
[06/04/22 21:24:26:259 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:24:26.258, end:2022-04-06T21:24:26.258 diff: 0 ms
[06/04/22 21:24:26:259 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:26.242, end: 2022-04-06T21:24:26.258, diff: 16 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:24:27:279 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:27.26, DefaultFuture.startTime: 2022-04-06T21:24:27.261, diff: 1 ms
[06/04/22 21:24:27:279 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:27.261, DefaultFuture.inwheeltime:2022-04-06T21:24:27.261 diff: 0 ms
[06/04/22 21:24:27:279 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:27.261, DefaultFuture.senttime:2022-04-06T21:24:27.262 diff: 1 ms
[06/04/22 21:24:27:280 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:24:27.277, DefaultFuture.senttime: 2022-04-06T21:24:27.262, diff: 15 ms
[06/04/22 21:24:27:280 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:24:27.277, end:2022-04-06T21:24:27.278 diff: 1 ms
[06/04/22 21:24:27:280 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:27.26, end: 2022-04-06T21:24:27.278, diff: 18 ms
1
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:24:28:304 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:28.284, DefaultFuture.startTime: 2022-04-06T21:24:28.286, diff: 2 ms
[06/04/22 21:24:28:305 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:28.286, DefaultFuture.inwheeltime:2022-04-06T21:24:28.286 diff: 0 ms
[06/04/22 21:24:28:305 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:24:28.286, DefaultFuture.senttime:2022-04-06T21:24:28.287 diff: 1 ms
[06/04/22 21:24:28:305 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:24:28.304, DefaultFuture.senttime: 2022-04-06T21:24:28.287, diff: 17 ms
[06/04/22 21:24:28:305 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:24:28.304, end:2022-04-06T21:24:28.304 diff: 0 ms
[06/04/22 21:24:28:305 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:24:28.284, end: 2022-04-06T21:24:28.304, diff: 20 ms

超时 provider sleep 10ms, timeout 5ms 超时

1
[06/04/22 21:26:38:713 CST] Dubbo-global-shared-handler-thread-1  WARN support.DefaultFuture:  [DUBBO] The timeout response finally returned at 2022-04-06 21:26:38.713, response status is 20, channel: /192.168.1.4:53692 -> /192.168.1.4:20880, please check provider side for detailed result., dubbo version: , current host: 192.168.1.4
[06/04/22 21:26:38:725 CST] main  WARN support.FailoverClusterInvoker:  [DUBBO] Although retry the method sayHello in the service org.apache.dubbo.rpc.service.GenericService was successful by the provider 192.168.1.4:20880, but there have been failed providers [192.168.1.4:20880] (1/1) from the registry 127.0.0.1:2181 on the consumer 192.168.1.4 using the dubbo version . Last error is: Invoke remote method timeout. method: $invoke, provider: DefaultServiceInstance{serviceName='dubbo-springboot-demo-provider', host='192.168.1.4', port=20880, enabled=true, healthy=true, metadata={dubbo.endpoints=[{"port":20880,"protocol":"dubbo"}], dubbo.metadata-service.url-params={"connections":"1","version":"1.0.0","dubbo":"2.0.2","release":"3.0.8-SNAPSHOT","side":"provider","port":"20880","protocol":"dubbo"}, dubbo.metadata.revision=f33cf55bb420d0545ec1217fad84da87, dubbo.metadata.storage-type=local}}, service{name='org.apache.dubbo.springboot.demo.DemoService',group='null',version='null',protocol='dubbo',params={side=provider, release=3.0.8-SNAPSHOT, methods=sayHello,sayHelloAsync, deprecated=false, dubbo=2.0.2, interface=org.apache.dubbo.springboot.demo.DemoService, service-name-mapping=true, timeout=5, generic=false, application=dubbo-springboot-demo-provider, background=false, dynamic=true, REGISTRY_CLUSTER=zk-registry, anyhost=true},}, cause: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2022-04-06 21:26:38.686, end time: 2022-04-06 21:26:38.698, client elapsed: 4 ms, server elapsed: 8 ms, timeout: 5 ms, request: Request [id=27, version=2.0.2, twoway=true, event=false, broken=false, data=null], channel: /192.168.1.4:53692 -> /192.168.1.4:20880, dubbo version: , current host: 192.168.1.4
org.apache.dubbo.rpc.RpcException: Invoke remote method timeout. method: $invoke, provider: DefaultServiceInstance{serviceName='dubbo-springboot-demo-provider', host='192.168.1.4', port=20880, enabled=true, healthy=true, metadata={dubbo.endpoints=[{"port":20880,"protocol":"dubbo"}], dubbo.metadata-service.url-params={"connections":"1","version":"1.0.0","dubbo":"2.0.2","release":"3.0.8-SNAPSHOT","side":"provider","port":"20880","protocol":"dubbo"}, dubbo.metadata.revision=f33cf55bb420d0545ec1217fad84da87, dubbo.metadata.storage-type=local}}, service{name='org.apache.dubbo.springboot.demo.DemoService',group='null',version='null',protocol='dubbo',params={side=provider, release=3.0.8-SNAPSHOT, methods=sayHello,sayHelloAsync, deprecated=false, dubbo=2.0.2, interface=org.apache.dubbo.springboot.demo.DemoService, service-name-mapping=true, timeout=5, generic=false, application=dubbo-springboot-demo-provider, background=false, dynamic=true, REGISTRY_CLUSTER=zk-registry, anyhost=true},}, cause: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2022-04-06 21:26:38.686, end time: 2022-04-06 21:26:38.698, client elapsed: 4 ms, server elapsed: 8 ms, timeout: 5 ms, request: Request [id=27, version=2.0.2, twoway=true, event=false, broken=false, data=null], channel: /192.168.1.4:53692 -> /192.168.1.4:20880
	at org.apache.dubbo.rpc.protocol.AbstractInvoker.waitForResultIfSync(AbstractInvoker.java:275)
	at org.apache.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:185)
	at org.apache.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:78)
	at org.apache.dubbo.rpc.filter.GenericImplFilter.invoke(GenericImplFilter.java:125)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:193)
	at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invokeWithContext(AbstractClusterInvoker.java:378)
	at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:80)
	at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:340)
	at org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter.invoke(RouterSnapshotFilter.java:46)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:99)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:51)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter.invoke(ConsumerContextFilter.java:109)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:193)
	at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$ClusterFilterInvoker.invoke(AbstractCluster.java:92)
	at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:97)
	at org.apache.dubbo.registry.client.migration.MigrationInvoker.invoke(MigrationInvoker.java:280)
	at org.apache.dubbo.rpc.proxy.InvocationUtil.invoke(InvocationUtil.java:57)
	at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:73)
	at com.alibaba.dubbo.rpc.service.GenericServiceDubboProxy1.$invoke(GenericServiceDubboProxy1.java)
	at org.apache.dubbo.demo.consumer.GenericApplication.runWithBootstrap(GenericApplication.java:86)
	at org.apache.dubbo.demo.consumer.GenericApplication.main(GenericApplication.java:46)
Caused by: java.util.concurrent.ExecutionException: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2022-04-06 21:26:38.686, end time: 2022-04-06 21:26:38.698, client elapsed: 4 ms, server elapsed: 8 ms, timeout: 5 ms, request: Request [id=27, version=2.0.2, twoway=true, event=false, broken=false, data=null], channel: /192.168.1.4:53692 -> /192.168.1.4:20880
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2022)
	at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:195)
	at org.apache.dubbo.rpc.protocol.AbstractInvoker.waitForResultIfSync(AbstractInvoker.java:264)
	... 25 more
Caused by: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2022-04-06 21:26:38.686, end time: 2022-04-06 21:26:38.698, client elapsed: 4 ms, server elapsed: 8 ms, timeout: 5 ms, request: Request [id=27, version=2.0.2, twoway=true, event=false, broken=false, data=null], channel: /192.168.1.4:53692 -> /192.168.1.4:20880
	at org.apache.dubbo.remoting.exchange.support.DefaultFuture.doReceived(DefaultFuture.java:229)
	at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:192)
	at org.apache.dubbo.remoting.exchange.support.DefaultFuture$TimeoutCheckTask.notifyTimeout(DefaultFuture.java:314)
	at org.apache.dubbo.remoting.exchange.support.DefaultFuture$TimeoutCheckTask.lambda$run$0(DefaultFuture.java:301)
	at org.apache.dubbo.common.threadpool.ThreadlessExecutor$RunnableWrapper.run(ThreadlessExecutor.java:184)
	at org.apache.dubbo.common.threadpool.ThreadlessExecutor.waitAndDrain(ThreadlessExecutor.java:103)
	at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:193)
	... 26 more
[06/04/22 21:26:38:727 CST] main  WARN proxy.InvokerInvocationHandler:  [DUBBO] [Dubbo-Consumer] execute service org.apache.dubbo.springboot.demo.DemoService#$invoke cost 41.329177 ms, this invocation almost (maybe already) timeout. Timeout: 5ms
invocation context:
path=org.apache.dubbo.springboot.demo.DemoService;
remote.application=demo-consumer;
interface=org.apache.dubbo.springboot.demo.DemoService;
version=0.0.0;
generic=true;
timeout=5;
thread info: 
Start time: 1125789532871242
+-[ Offset: 0.000000ms; Usage: 41.329177ms, 100% ] Receive request. Client invoke begin. ServiceKey: org.apache.dubbo.springboot.demo.DemoService MethodName:$invoke
  +-[ Offset: 0.520902ms; Usage: 14.979145ms, 36% ] Invoker invoke. Target Address: 192.168.1.4:20880
  +-[ Offset: 17.960444ms; Usage: 21.790695ms, 52% ] Invoker invoke. Target Address: 192.168.1.4:20880, dubbo version: , current host: 192.168.1.4
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:26:38:727 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:38.685, DefaultFuture.startTime: 2022-04-06T21:26:38.704, diff: 19 ms
[06/04/22 21:26:38:727 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:38.704, DefaultFuture.inwheeltime:2022-04-06T21:26:38.705 diff: 1 ms
[06/04/22 21:26:38:727 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:38.704, DefaultFuture.senttime:2022-04-06T21:26:38.708 diff: 4 ms
[06/04/22 21:26:38:728 CST] main  INFO consumer.GenericApplication: DefaultFuture.senttime:2022-04-06T21:26:38.708, DefaultFuture.timeoutstart: 2022-04-06T21:26:38.698, diff: 10 ms
[06/04/22 21:26:38:728 CST] main  INFO consumer.GenericApplication: DefaultFuture.timeoutstart: 2022-04-06T21:26:38.698, DefaultFuture.timeoutend: 2022-04-06T21:26:38.7, diff: 2 ms
[06/04/22 21:26:38:728 CST] main  INFO consumer.GenericApplication: DefaultFuture.timeoutend: 2022-04-06T21:26:38.7, DefaultFuture.receivetime: 2022-04-06T21:26:38.725, diff: 25 ms
[06/04/22 21:26:38:728 CST] main  INFO consumer.GenericApplication: DefaultFuture.receivetime: 2022-04-06T21:26:38.725, end:2022-04-06T21:26:38.727 diff: 2 ms
[06/04/22 21:26:38:728 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:38.685, end: 2022-04-06T21:26:38.727, diff: 42 ms
1
[06/04/22 21:26:39:754 CST] Dubbo-global-shared-handler-thread-1  WARN support.DefaultFuture:  [DUBBO] The timeout response finally returned at 2022-04-06 21:26:39.754, response status is 20, channel: /192.168.1.4:53692 -> /192.168.1.4:20880, please check provider side for detailed result., dubbo version: , current host: 192.168.1.4
[06/04/22 21:26:39:769 CST] main  WARN support.FailoverClusterInvoker:  [DUBBO] Although retry the method sayHello in the service org.apache.dubbo.rpc.service.GenericService was successful by the provider 192.168.1.4:20880, but there have been failed providers [192.168.1.4:20880] (1/1) from the registry 127.0.0.1:2181 on the consumer 192.168.1.4 using the dubbo version . Last error is: Invoke remote method timeout. method: $invoke, provider: DefaultServiceInstance{serviceName='dubbo-springboot-demo-provider', host='192.168.1.4', port=20880, enabled=true, healthy=true, metadata={dubbo.endpoints=[{"port":20880,"protocol":"dubbo"}], dubbo.metadata-service.url-params={"connections":"1","version":"1.0.0","dubbo":"2.0.2","release":"3.0.8-SNAPSHOT","side":"provider","port":"20880","protocol":"dubbo"}, dubbo.metadata.revision=f33cf55bb420d0545ec1217fad84da87, dubbo.metadata.storage-type=local}}, service{name='org.apache.dubbo.springboot.demo.DemoService',group='null',version='null',protocol='dubbo',params={side=provider, release=3.0.8-SNAPSHOT, methods=sayHello,sayHelloAsync, deprecated=false, dubbo=2.0.2, interface=org.apache.dubbo.springboot.demo.DemoService, service-name-mapping=true, timeout=5, generic=false, application=dubbo-springboot-demo-provider, background=false, dynamic=true, REGISTRY_CLUSTER=zk-registry, anyhost=true},}, cause: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2022-04-06 21:26:39.733, end time: 2022-04-06 21:26:39.751, client elapsed: 1 ms, server elapsed: 17 ms, timeout: 5 ms, request: Request [id=29, version=2.0.2, twoway=true, event=false, broken=false, data=null], channel: /192.168.1.4:53692 -> /192.168.1.4:20880, dubbo version: , current host: 192.168.1.4
org.apache.dubbo.rpc.RpcException: Invoke remote method timeout. method: $invoke, provider: DefaultServiceInstance{serviceName='dubbo-springboot-demo-provider', host='192.168.1.4', port=20880, enabled=true, healthy=true, metadata={dubbo.endpoints=[{"port":20880,"protocol":"dubbo"}], dubbo.metadata-service.url-params={"connections":"1","version":"1.0.0","dubbo":"2.0.2","release":"3.0.8-SNAPSHOT","side":"provider","port":"20880","protocol":"dubbo"}, dubbo.metadata.revision=f33cf55bb420d0545ec1217fad84da87, dubbo.metadata.storage-type=local}}, service{name='org.apache.dubbo.springboot.demo.DemoService',group='null',version='null',protocol='dubbo',params={side=provider, release=3.0.8-SNAPSHOT, methods=sayHello,sayHelloAsync, deprecated=false, dubbo=2.0.2, interface=org.apache.dubbo.springboot.demo.DemoService, service-name-mapping=true, timeout=5, generic=false, application=dubbo-springboot-demo-provider, background=false, dynamic=true, REGISTRY_CLUSTER=zk-registry, anyhost=true},}, cause: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2022-04-06 21:26:39.733, end time: 2022-04-06 21:26:39.751, client elapsed: 1 ms, server elapsed: 17 ms, timeout: 5 ms, request: Request [id=29, version=2.0.2, twoway=true, event=false, broken=false, data=null], channel: /192.168.1.4:53692 -> /192.168.1.4:20880
	at org.apache.dubbo.rpc.protocol.AbstractInvoker.waitForResultIfSync(AbstractInvoker.java:275)
	at org.apache.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:185)
	at org.apache.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:78)
	at org.apache.dubbo.rpc.filter.GenericImplFilter.invoke(GenericImplFilter.java:125)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:193)
	at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invokeWithContext(AbstractClusterInvoker.java:378)
	at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:80)
	at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:340)
	at org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter.invoke(RouterSnapshotFilter.java:46)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:99)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:51)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter.invoke(ConsumerContextFilter.java:109)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
	at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:193)
	at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$ClusterFilterInvoker.invoke(AbstractCluster.java:92)
	at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:97)
	at org.apache.dubbo.registry.client.migration.MigrationInvoker.invoke(MigrationInvoker.java:280)
	at org.apache.dubbo.rpc.proxy.InvocationUtil.invoke(InvocationUtil.java:57)
	at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:73)
	at com.alibaba.dubbo.rpc.service.GenericServiceDubboProxy1.$invoke(GenericServiceDubboProxy1.java)
	at org.apache.dubbo.demo.consumer.GenericApplication.runWithBootstrap(GenericApplication.java:86)
	at org.apache.dubbo.demo.consumer.GenericApplication.main(GenericApplication.java:46)
Caused by: java.util.concurrent.ExecutionException: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2022-04-06 21:26:39.733, end time: 2022-04-06 21:26:39.751, client elapsed: 1 ms, server elapsed: 17 ms, timeout: 5 ms, request: Request [id=29, version=2.0.2, twoway=true, event=false, broken=false, data=null], channel: /192.168.1.4:53692 -> /192.168.1.4:20880
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2022)
	at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:195)
	at org.apache.dubbo.rpc.protocol.AbstractInvoker.waitForResultIfSync(AbstractInvoker.java:264)
	... 25 more
Caused by: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2022-04-06 21:26:39.733, end time: 2022-04-06 21:26:39.751, client elapsed: 1 ms, server elapsed: 17 ms, timeout: 5 ms, request: Request [id=29, version=2.0.2, twoway=true, event=false, broken=false, data=null], channel: /192.168.1.4:53692 -> /192.168.1.4:20880
	at org.apache.dubbo.remoting.exchange.support.DefaultFuture.doReceived(DefaultFuture.java:229)
	at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:192)
	at org.apache.dubbo.remoting.exchange.support.DefaultFuture$TimeoutCheckTask.notifyTimeout(DefaultFuture.java:314)
	at org.apache.dubbo.remoting.exchange.support.DefaultFuture$TimeoutCheckTask.lambda$run$0(DefaultFuture.java:301)
	at org.apache.dubbo.common.threadpool.ThreadlessExecutor$RunnableWrapper.run(ThreadlessExecutor.java:184)
	at org.apache.dubbo.common.threadpool.ThreadlessExecutor.waitAndDrain(ThreadlessExecutor.java:103)
	at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:193)
	... 26 more
[06/04/22 21:26:39:770 CST] main  WARN proxy.InvokerInvocationHandler:  [DUBBO] [Dubbo-Consumer] execute service org.apache.dubbo.springboot.demo.DemoService#$invoke cost 37.212631 ms, this invocation almost (maybe already) timeout. Timeout: 5ms
invocation context:
path=org.apache.dubbo.springboot.demo.DemoService;
remote.application=demo-consumer;
interface=org.apache.dubbo.springboot.demo.DemoService;
version=0.0.0;
generic=true;
timeout=5;
thread info: 
Start time: 1125790580464414
+-[ Offset: 0.000000ms; Usage: 37.212631ms, 100% ] Receive request. Client invoke begin. ServiceKey: org.apache.dubbo.springboot.demo.DemoService MethodName:$invoke
  +-[ Offset: 0.249678ms; Usage: 18.652652ms, 50% ] Invoker invoke. Target Address: 192.168.1.4:20880
  +-[ Offset: 19.153993ms; Usage: 17.481482ms, 46% ] Invoker invoke. Target Address: 192.168.1.4:20880, dubbo version: , current host: 192.168.1.4
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:26:39:770 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:39.733, DefaultFuture.startTime: 2022-04-06T21:26:39.752, diff: 19 ms
[06/04/22 21:26:39:771 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:39.752, DefaultFuture.inwheeltime:2022-04-06T21:26:39.752 diff: 0 ms
[06/04/22 21:26:39:771 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:39.752, DefaultFuture.senttime:2022-04-06T21:26:39.753 diff: 1 ms
[06/04/22 21:26:39:771 CST] main  INFO consumer.GenericApplication: DefaultFuture.senttime:2022-04-06T21:26:39.753, DefaultFuture.timeoutstart: 2022-04-06T21:26:39.751, diff: 2 ms
[06/04/22 21:26:39:771 CST] main  INFO consumer.GenericApplication: DefaultFuture.timeoutstart: 2022-04-06T21:26:39.751, DefaultFuture.timeoutend: 2022-04-06T21:26:39.751, diff: 0 ms
[06/04/22 21:26:39:771 CST] main  INFO consumer.GenericApplication: DefaultFuture.timeoutend: 2022-04-06T21:26:39.751, DefaultFuture.receivetime: 2022-04-06T21:26:39.769, diff: 18 ms
[06/04/22 21:26:39:771 CST] main  INFO consumer.GenericApplication: DefaultFuture.receivetime: 2022-04-06T21:26:39.769, end:2022-04-06T21:26:39.77 diff: 1 ms
[06/04/22 21:26:39:771 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:39.733, end: 2022-04-06T21:26:39.77, diff: 37 ms
1
[06/04/22 21:26:40:789 CST] main  WARN proxy.InvokerInvocationHandler:  [DUBBO] [Dubbo-Consumer] execute service org.apache.dubbo.springboot.demo.DemoService#$invoke cost 16.183850 ms, this invocation almost (maybe already) timeout. Timeout: 5ms
invocation context:
path=org.apache.dubbo.springboot.demo.DemoService;
remote.application=demo-consumer;
interface=org.apache.dubbo.springboot.demo.DemoService;
version=0.0.0;
generic=true;
timeout=5;
thread info: 
Start time: 1125791620404444
+-[ Offset: 0.000000ms; Usage: 16.183850ms, 100% ] Receive request. Client invoke begin. ServiceKey: org.apache.dubbo.springboot.demo.DemoService MethodName:$invoke
  +-[ Offset: 0.536625ms; Usage: 15.576262ms, 96% ] Invoker invoke. Target Address: 192.168.1.4:20880, dubbo version: , current host: 192.168.1.4
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:26:40:790 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:40.773, DefaultFuture.startTime: 2022-04-06T21:26:40.773, diff: 0 ms
[06/04/22 21:26:40:790 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:40.773, DefaultFuture.inwheeltime:2022-04-06T21:26:40.773 diff: 0 ms
[06/04/22 21:26:40:790 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:40.773, DefaultFuture.senttime:2022-04-06T21:26:40.774 diff: 1 ms
[06/04/22 21:26:40:790 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:26:40.788, DefaultFuture.senttime: 2022-04-06T21:26:40.774, diff: 14 ms
[06/04/22 21:26:40:790 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:26:40.788, end:2022-04-06T21:26:40.789 diff: 1 ms
[06/04/22 21:26:40:791 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:40.773, end: 2022-04-06T21:26:40.789, diff: 16 ms
1
[06/04/22 21:26:41:810 CST] main  WARN proxy.InvokerInvocationHandler:  [DUBBO] [Dubbo-Consumer] execute service org.apache.dubbo.springboot.demo.DemoService#$invoke cost 15.095078 ms, this invocation almost (maybe already) timeout. Timeout: 5ms
invocation context:
path=org.apache.dubbo.springboot.demo.DemoService;
remote.application=demo-consumer;
interface=org.apache.dubbo.springboot.demo.DemoService;
version=0.0.0;
generic=true;
timeout=5;
thread info: 
Start time: 1125792642017715
+-[ Offset: 0.000000ms; Usage: 15.095078ms, 100% ] Receive request. Client invoke begin. ServiceKey: org.apache.dubbo.springboot.demo.DemoService MethodName:$invoke
  +-[ Offset: 0.193376ms; Usage: 14.856755ms, 98% ] Invoker invoke. Target Address: 192.168.1.4:20880, dubbo version: , current host: 192.168.1.4
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:26:41:810 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:41.794, DefaultFuture.startTime: 2022-04-06T21:26:41.794, diff: 0 ms
[06/04/22 21:26:41:810 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:41.794, DefaultFuture.inwheeltime:2022-04-06T21:26:41.794 diff: 0 ms
[06/04/22 21:26:41:810 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:41.794, DefaultFuture.senttime:2022-04-06T21:26:41.795 diff: 1 ms
[06/04/22 21:26:41:810 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:26:41.809, DefaultFuture.senttime: 2022-04-06T21:26:41.795, diff: 14 ms
[06/04/22 21:26:41:811 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:26:41.809, end:2022-04-06T21:26:41.81 diff: 1 ms
[06/04/22 21:26:41:811 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:41.794, end: 2022-04-06T21:26:41.81, diff: 16 ms
1
[06/04/22 21:26:42:829 CST] main  WARN proxy.InvokerInvocationHandler:  [DUBBO] [Dubbo-Consumer] execute service org.apache.dubbo.springboot.demo.DemoService#$invoke cost 17.188159 ms, this invocation almost (maybe already) timeout. Timeout: 5ms
invocation context:
path=org.apache.dubbo.springboot.demo.DemoService;
remote.application=demo-consumer;
interface=org.apache.dubbo.springboot.demo.DemoService;
version=0.0.0;
generic=true;
timeout=5;
thread info: 
Start time: 1125793659747795
+-[ Offset: 0.000000ms; Usage: 17.188159ms, 100% ] Receive request. Client invoke begin. ServiceKey: org.apache.dubbo.springboot.demo.DemoService MethodName:$invoke
  +-[ Offset: 0.304199ms; Usage: 16.808201ms, 97% ] Invoker invoke. Target Address: 192.168.1.4:20880, dubbo version: , current host: 192.168.1.4
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:26:42:830 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:42.812, DefaultFuture.startTime: 2022-04-06T21:26:42.812, diff: 0 ms
[06/04/22 21:26:42:830 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:42.812, DefaultFuture.inwheeltime:2022-04-06T21:26:42.812 diff: 0 ms
[06/04/22 21:26:42:830 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:42.812, DefaultFuture.senttime:2022-04-06T21:26:42.813 diff: 1 ms
[06/04/22 21:26:42:830 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:26:42.829, DefaultFuture.senttime: 2022-04-06T21:26:42.813, diff: 16 ms
[06/04/22 21:26:42:830 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:26:42.829, end:2022-04-06T21:26:42.829 diff: 0 ms
[06/04/22 21:26:42:830 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:42.812, end: 2022-04-06T21:26:42.829, diff: 17 ms
1
[06/04/22 21:26:43:846 CST] main  WARN proxy.InvokerInvocationHandler:  [DUBBO] [Dubbo-Consumer] execute service org.apache.dubbo.springboot.demo.DemoService#$invoke cost 14.162471 ms, this invocation almost (maybe already) timeout. Timeout: 5ms
invocation context:
path=org.apache.dubbo.springboot.demo.DemoService;
remote.application=demo-consumer;
interface=org.apache.dubbo.springboot.demo.DemoService;
version=0.0.0;
generic=true;
timeout=5;
thread info: 
Start time: 1125794679162714
+-[ Offset: 0.000000ms; Usage: 14.162471ms, 100% ] Receive request. Client invoke begin. ServiceKey: org.apache.dubbo.springboot.demo.DemoService MethodName:$invoke
  +-[ Offset: 0.202243ms; Usage: 13.917734ms, 98% ] Invoker invoke. Target Address: 192.168.1.4:20880, dubbo version: , current host: 192.168.1.4
used millis: 0
Hello dubbo generic invoke
[06/04/22 21:26:43:846 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:43.831, DefaultFuture.startTime: 2022-04-06T21:26:43.832, diff: 1 ms
[06/04/22 21:26:43:846 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:43.832, DefaultFuture.inwheeltime:2022-04-06T21:26:43.832 diff: 0 ms
[06/04/22 21:26:43:846 CST] main  INFO consumer.GenericApplication: DefaultFuture.startTime: 2022-04-06T21:26:43.832, DefaultFuture.senttime:2022-04-06T21:26:43.832 diff: 0 ms
[06/04/22 21:26:43:846 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime:2022-04-06T21:26:43.845, DefaultFuture.senttime: 2022-04-06T21:26:43.832, diff: 13 ms
[06/04/22 21:26:43:846 CST] main  INFO consumer.GenericApplication: AllChannelHandler.receivedtime: 2022-04-06T21:26:43.845, end:2022-04-06T21:26:43.846 diff: 1 ms
[06/04/22 21:26:43:846 CST] main  INFO consumer.GenericApplication: start: 2022-04-06T21:26:43.831, end: 2022-04-06T21:26:43.846, diff: 15 ms

可以看到虽然设置了超时时间5ms,provider 在10ms后返回, 可是consumer仍然在15ms的时候正常接收到响应信息,原因就是consumer在收到provider响应时,时间轮中的超时任务还没有被执行,这跟时间轮的tickDuration有关;
以超时时间为5ms的RPC场景为例,时间轮的tickDuration为30ms时间线如下:
T0: 创建时间轮,T0 + (30ms * n) 的时间点执行时间轮中过期的超时任务,n每隔30ms递增+1;
T1: 调用service 方法;
T2: 超时任务 OverTimeTask1 添加到时间轮, 期望在T2 + 5ms时执行OverTimeTask1;
T3: = T0 + (30ms * 1) 执行超时任务列表;此时OverTimeTask1并不一定会执行,因为可能存在 (T2 + 5ms) > (T0 + 30ms * 1) 的情况,如果是这种情况,将会在T0 + (30ms * 2) 时执行;

不管如何OverTimeTask1的执行肯定是会延迟的,延迟时间计算公式: delayTime = T0 + (30ms * n) - (T2 + 5ms)

Dubbo2请求超时

Dubbo2请求超时等待采用JUC中的Condition的超时等待,超时时间几乎不存在误差

你可能感兴趣的:(Dubbo,dubbo,超时,时间轮)