Dubbo intermittent timeout issue

When using dubbo to develop projects, timeout problems often occur, the information is as follows
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



After testing, greys tracked that it was a problem with dubbo's monitor. The main timeout method is dubbo's getIP method. When the monitor collects data at regular intervals, it must obtain the IP of zk according to the domain name. This step takes a long time.
public String getIp() {
        if (ip == null) {
            ip = NetUtils.getIpByHost(host);
        }
        return ip;
    }


Now that the source code of dubbo has been changed, the monitor does not obtain the IP of zk every time it collects data, but uses the domain name directly. Add the following method,

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


Modify the method of 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 {
            // release the lock
            LOCK.unlock();
        }
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326373780&siteId=291194637