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

本文共 3985 字,大约阅读时间需要 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/

你可能感兴趣的文章
Node.js卸载超详细步骤(附图文讲解)
查看>>
Node.js基于Express框架搭建一个简单的注册登录Web功能
查看>>
node.js学习之npm 入门 —8.《怎样创建,发布,升级你的npm,node模块》
查看>>
Node.js安装与配置指南:轻松启航您的JavaScript服务器之旅
查看>>
Node.js安装及环境配置之Windows篇
查看>>
Node.js安装和入门 - 2行代码让你能够启动一个Server
查看>>
node.js安装方法
查看>>
Node.js官网无法正常访问时安装NodeJS的方法
查看>>
node.js模块、包
查看>>
node.js的express框架用法(一)
查看>>
Node.js的交互式解释器(REPL)
查看>>
Node.js的循环与异步问题
查看>>
Node.js高级编程:用Javascript构建可伸缩应用(1)1.1 介绍和安装-安装Node
查看>>
nodejs + socket.io 同时使用http 和 https
查看>>
NodeJS @kubernetes/client-node连接到kubernetes集群的方法
查看>>
NodeJS API简介
查看>>
Nodejs express 获取url参数,post参数的三种方式
查看>>
nodejs http小爬虫
查看>>
nodejs libararies
查看>>
nodejs npm常用命令
查看>>