dubbo超时原因以及解决方案:

1、超时日志:

服务端:

Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout. start time: 2017-08-05 18:14:52.751, end time: 2017-08-05 18:14:53.764, client elapsed: 6 ms, server elapsed: 1006 ms, timeout: 1000 ms, request: Request [id=0, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=getCommentsByProductId, parameterTypes=[class java.lang.Long], arguments=[1], attachments={traceId=6299543007105572864, spanId=6299543007105572864, input=259, path=com.jim.framework.dubbo.core.service.CommentService, interface=com.jim.framework.dubbo.core.service.CommentService, version=0.0.0}]], channel: /192.168.10.222:53204 -> /192.168.10.222:7777

at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:107) ~[dubbo-2.5.3.jar:2.5.3]

at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:84) ~[dubbo-2.5.3.jar:2.5.3]

at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:96) ~[dubbo-2.5.3.jar:2.5.3]

... 42 common frames omitted

客户端类似:

com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method in the service com.... Tried 3 times of the providers [172..., 172.... , 172...:03] (3/3) from the registry 172....:2181 on the consumer 172.... using the dubbo version 2.5.3. Last error is: Invoke remote method timeout. method: , provider: dubbo://172....:03/com.?anyhost=true&application=admin-dubbo&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=com. ice&methods=getBalanceInfo,getBalance,recharge,unfreeze,statisticAccountInfo,withdraw,transfer2User,register&pid=1&release=2.7.7&revision=1.0.0.0-SNAPSHOT&side=consumer×tamp=1648652988240, cause: Waiting server-side response timeout by scan timer. start time: 2022-03-30 23:12:22.772, end time: 2022-03-30 23:12:23.796, client elapsed: 0 ms, server elapsed: 1024 ms, timeout: 1000 ms, request:

2、原因:

消费者:当消费者发起一次请求后,如果在规定时间内未得到服务端的响应则直接返回超时异常,但服务端的代码依然在执行。

生产者:消费端发起一次请求后,一直等待服务端的响应,服务端在方法执行到指定时间后如果未执行完,此时返回一个超时异常给到消费端。

dubbo的超时主要是针对客户端的,由于Dubbo是采用一种NIO模式,消费者发起请求后得到一个ResponseFuture,然后消费者一直轮询这个ResponseFuture直至超时或者收到生产者的返回结果。虽然超时了,但仅仅是消费者不再等待生产者的反馈并不代表此时服务端也停止了执行。

3、解决方案:

springboot配置超时时间:

dubbo:

consumer:

timeout: 10000

provider:

timeout: 30000

springMVC配置:

4、举例 生产者 4秒  ,消费者设置3秒,这个service在调用时的超时时间就是3秒。

1)consumer会在超过3秒时得到一个调用超时的异常。

2)provider中代码的执行不会因为超时而中断,在执行完毕后,会得到一个dubbo的警告。

即 在dubbo的provider和consumer的配置文件中,如果都配置了timeout的超时时间,dubbo默认以consumer中配置的时间为准。

好文阅读

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: