博客
关于我
源码分析Dubbo监控中心实现原理
阅读量:93 次
发布时间:2019-02-25

本文共 3925 字,大约阅读时间需要 13 分钟。

Dubbo??????????????????????????Dubbo????????????????????????????????????MonitorFilter???????????????????????????????????????????????????????????????????

MonitorFilter?????

MonitorFilter?Dubbo???????????????????????????????????????????????????????????????????????????

MonitorFilter???

MonitorFilter???SPI??????Singleton?ThreadSafe??????????????????????????????????????@Activate?????Constants.PROVIDER?Constants.CONSUMER????????

/** * MonitorFilter. (SPI, Singleton, ThreadSafe) */@Activate(group = {Constants.PROVIDER, Constants.CONSUMER})public class MonitorFilter implements Filter {     // ??????}

getConcurrent????

getConcurrent???????????????????????ConcurrentMap?????????????????????????????

private AtomicInteger getConcurrent(Invoker invoker, Invocation invocation) {    String key = invoker.getInterface().getName() + "." + invocation.getMethodName();    AtomicInteger concurrent = concurrents.get(key);    if (concurrent == null) {        concurrents.putIfAbsent(key, new AtomicInteger());        concurrent = concurrents.get(key);    }    return concurrent;}

invoker????

invoker???MonitorFilter??????????????????????????????????????????????????????collect?????????

public Result invoke(Invoker invoker, Invocation invocation) throws RpcException {    if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) {        RpcContext context = RpcContext.getContext();        String remoteHost = context.getRemoteHost();        long start = System.currentTimeMillis();        getConcurrent(invoker, invocation).incrementAndGet();        try {            Result result = invoker.invoke(invocation);            collect(invoker, invocation, result, remoteHost, start, false);            return result;        } catch (RpcException e) {            collect(invoker, invocation, null, remoteHost, start, true);            throw e;        } finally {            getConcurrent(invoker, invocation).decrementAndGet();        }    } else {        return invoker.invoke(invocation);    }}

DubboMonitor????

Dubbo????????DubboMonitor???????????????????????DubboMonitor????????????????????????

DubboMonitor????

  • ScheduledExecutorService??????????????????3????
  • MonitorService??????????????Dubbo???????
  • statisticsMap??????????ConcurrentMap???????

DubboMonitor????

DubboMonitor????????????????????????

public DubboMonitor(Invoker monitorInvoker, MonitorService monitorService) {    this.monitorInvoker = monitorInvoker;    this.monitorService = monitorService;    this.monitorInterval = monitorInvoker.getUrl().getPositiveParameter("interval", 60000);    sendFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {        @Override        public void run() {            try {                send();            } catch (Throwable t) {                logger.error("Unexpected error occur at send statistic, cause: " + t.getMessage(), t);            }        }    }, monitorInterval, monitorInterval, TimeUnit.MILLISECONDS);}

send??

send???????????????MonitorService????????

public void send() {    try {        for (URL url = queue.take(); !queue.isEmpty(); url = queue.take()) {            if (POISON_PROTOCOL.equals(url.getProtocol())) {                continue;            }            // ?????????            // ...        }    } catch (Throwable t) {        logger.error("Unexpected error occur at send statistic, cause: " + t.getMessage(), t);    }}

Dubbo??????

Dubbo??????SimpleMonitorService????????????????????????????????????

SimpleMonitorService????

  • ScheduledExecutorService??????????
  • writeThread?????????????
  • queue??????????????

write??

write???????????????????????????????? + ??? + ???

private void write() throws Exception {    URL statistics = queue.take();    if (POISON_PROTOCOL.equals(statistics.getProtocol())) {        return;    }    // ???????????    // ...}

????

???Dubbo?????????????????????????????????????????????

???????Dubbo????????????????????????????????????????????????????????

转载地址:http://nwz.baihongyu.com/

你可能感兴趣的文章
nginx添加模块与https支持
查看>>
Nginx用户认证
查看>>
Nginx的location匹配规则的关键问题详解
查看>>
Nginx的Rewrite正则表达式,匹配非某单词
查看>>
Nginx的使用总结(一)
查看>>
Nginx的使用总结(三)
查看>>
Nginx的使用总结(二)
查看>>
Nginx的可视化神器nginx-gui的下载配置和使用
查看>>
Nginx的是什么?干什么用的?
查看>>
Nginx访问控制_登陆权限的控制(http_auth_basic_module)
查看>>
nginx负载均衡和反相代理的配置
查看>>
nginx负载均衡器处理session共享的几种方法(转)
查看>>
nginx负载均衡的5种策略(转载)
查看>>
nginx负载均衡的五种算法
查看>>
nginx转发端口时与导致websocket不生效
查看>>
Nginx运维与实战(二)-Https配置
查看>>
Nginx配置Https证书
查看>>
Nginx配置ssl实现https
查看>>
Nginx配置TCP代理指南
查看>>
Nginx配置——不记录指定文件类型日志
查看>>