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

你可能感兴趣的文章
Navicat for MySQL 查看BLOB字段内容
查看>>
Neo4j的安装与使用
查看>>
Neo4j(2):环境搭建
查看>>
nessus快速安装使用指南(非常详细)零基础入门到精通,收藏这一篇就够了
查看>>
Nessus漏洞扫描教程之配置Nessus
查看>>
Nest.js 6.0.0 正式版发布,基于 TypeScript 的 Node.js 框架
查看>>
Netpas:不一样的SD-WAN+ 保障网络通讯品质
查看>>
netsh advfirewall
查看>>
Netty WebSocket客户端
查看>>
Netty 异步任务调度与异步线程池
查看>>
Netty中集成Protobuf实现Java对象数据传递
查看>>
Netty工作笔记0006---NIO的Buffer说明
查看>>
Netty工作笔记0011---Channel应用案例2
查看>>
Netty工作笔记0013---Channel应用案例4Copy图片
查看>>
Netty工作笔记0014---Buffer类型化和只读
查看>>
Netty工作笔记0020---Selectionkey在NIO体系
查看>>
Vue踩坑笔记 - 关于vue静态资源引入的问题
查看>>
Netty工作笔记0025---SocketChannel API
查看>>
Netty工作笔记0027---NIO 网络编程应用--群聊系统2--服务器编写2
查看>>
Netty工作笔记0050---Netty核心模块1
查看>>