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

你可能感兴趣的文章
Numpy如何使用np.umprod重写range函数中i的python
查看>>
numpy学习笔记3-array切片
查看>>
numpy数组替换其中的值(如1替换为255)
查看>>
numpy数组索引-ChatGPT4o作答
查看>>
NUMPY矢量化np.prod不能构造具有超过32个操作数的ufunc
查看>>
Numpy矩阵与通用函数
查看>>
numpy绘制热力图
查看>>
numpy转PIL 报错TypeError: Cannot handle this data type
查看>>
Numpy闯关100题,我闯了95关,你呢?
查看>>
Nutch + solr 这个配合不错哦
查看>>
NuttX 构建系统
查看>>
NutUI:京东风格的轻量级 Vue 组件库
查看>>
NutzCodeInsight 2.0.7 发布,为 nutz-sqltpl 提供友好的 ide 支持
查看>>
NutzWk 5.1.5 发布,Java 微服务分布式开发框架
查看>>
NUUO网络视频录像机 css_parser.php 任意文件读取漏洞复现
查看>>
Nuxt Time 使用指南
查看>>
NuxtJS 接口转发详解:Nitro 的用法与注意事项
查看>>
NVelocity标签使用详解
查看>>
NVelocity标签设置缓存的解决方案
查看>>
Nvidia Cudatoolkit 与 Conda Cudatoolkit
查看>>