dubbo间歇性的超时问题

使用dubbo开发项目的时候,经常会发生超时问题,信息如下

Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2017-07-14 13:27:34.831, end time: 2017-07-14 13:27:39.832, client elapsed: 0 ms, server elapsed: 5001 ms, timeout: 5000 ms, request: Request [id=576670, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=findBJQByCode, parameterTypes=[class java.lang.String, class java.lang.String], arguments=[99123], attachments={input=356, path=com.anne.bqj.service.BqjService, interface=com.anne.bqj.service.BqjService, timeout=5000, version=1.0.0}]], channel: /192.168.1.110:34443 -> /192.168.1.110:20880



经过测试,greys跟踪得知,是dubbo的monitor的问题。主要超时的方法是dubbo的getIP方法,monitor每隔一段时间收集数据的时候都要根据域名获取zk的IP,这一步耗时很长。

public String getIp() {
if (ip == null) {
ip = NetUtils.getIpByHost(host);
}
return ip;
}


现在改了dubbo的源码,monitor每次收集数据的时候不获取zk的ip,直接用域名。增加如下方法,


public String toServiceString(boolean useIP){
return buildString(true, false, useIP, true);
}


修改AbstractMonitorFactory的方法


public Monitor getMonitor(URL url) {
url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
String key = url.toServiceString(false);
LOCK.lock();
try {
Monitor monitor = MONITORS.get(key);
if (monitor != null) {
return monitor;
}
monitor = createMonitor(url);
if (monitor == null) {
throw new IllegalStateException("Can not create monitor " + url);
}
MONITORS.put(key, monitor);
return monitor;
} finally {
// 释放锁
LOCK.unlock();
}
}

你可能感兴趣的:(微服务)