博客
关于我
源码分析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/

你可能感兴趣的文章
npm的安装和更新---npm工作笔记002
查看>>
npm的常用配置项---npm工作笔记004
查看>>
npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
查看>>
npm编译报错You may need an additional loader to handle the result of these loaders
查看>>
npm设置淘宝镜像、升级等
查看>>
npm设置源地址,npm官方地址
查看>>
npm设置镜像如淘宝:http://npm.taobao.org/
查看>>
npm配置安装最新淘宝镜像,旧镜像会errror
查看>>
NPM酷库052:sax,按流解析XML
查看>>
npm错误 gyp错误 vs版本不对 msvs_version不兼容
查看>>
npm错误Error: Cannot find module ‘postcss-loader‘
查看>>
npm,yarn,cnpm 的区别
查看>>
NPOI
查看>>
NPOI之Excel——合并单元格、设置样式、输入公式
查看>>
NPOI初级教程
查看>>
NPOI利用多任务模式分批写入多个Excel
查看>>
NPOI在Excel中插入图片
查看>>
NPOI将某个程序段耗时插入Excel
查看>>
NPOI格式设置
查看>>
NPOI设置单元格格式
查看>>