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

你可能感兴趣的文章
NPOI初级教程
查看>>
NPOI利用多任务模式分批写入多个Excel
查看>>
NPOI在Excel中插入图片
查看>>
NPOI将某个程序段耗时插入Excel
查看>>
NPOI格式设置
查看>>
NPOI设置单元格格式
查看>>
Npp删除选中行的Macro录制方式
查看>>
NR,NF,FNR
查看>>
nrf24l01+arduino
查看>>
nrf开发笔记一开发软件
查看>>
nrm —— 快速切换 NPM 源 (附带测速功能)
查看>>
nrm报错 [ERR_INVALID_ARG_TYPE]
查看>>
NS3 IP首部校验和
查看>>
NSDateFormatter的替代方法
查看>>
NSError 的使用方法
查看>>
NSGA-Ⅲ源代码
查看>>
nsis 安装脚本示例(转)
查看>>
NSJSON的用法(oc系统自带的解析方法)
查看>>
nslookup 的基本知识与命令详解
查看>>
NSOperation基本操作
查看>>