摘要: 原创出处 http://www.iocoder.cn/SkyWalking/collector-cache-module/ 「芋道源码」欢迎转载,保留摘要,谢谢!
本文主要基于 SkyWalking 3.2.6 正式版
🙂🙂🙂关注**微信公众号:【芋道源码】**有福利:
- RocketMQ / MyCAT / Sharding-JDBC 所有源码分析文章列表
- RocketMQ / MyCAT / Sharding-JDBC 中文注释源码 GitHub 地址
- 您对于源码的疑问每条留言都将得到认真回复。甚至不知道如何读源码也可以请教噢。
- 新的源码解析文章实时收到通知。每周更新一篇左右。
- 认真的源码交流微信群。
1. 概述
本文主要分享 SkyWalking Collector Cache Module,缓存组件。该组件用于缓存 Application 、Instance 、ServiceName 等常用且不变的数据,以提升性能。
友情提示:本文内容较为简单,胖友可快速阅读。
Cache Module 在 SkyWalking 架构图处于如下位置( 红框 ) :
FROM https://github.com/apache/incubating-skywalking
下面我们来看看整体的项目结构,如下图所示 :
collector-cache-define:定义缓存组件接口。collector-cache-guava-provider:基于 Google Guava 的缓存组件实现。
下面,我们从接口到实现的顺序进行分享。
2. collector-cache-define
collector-cache-define :定义队列组件接口。项目结构如下 :
2.1 CacheModule
org.skywalking.apm.collector.cache.CacheModule ,实现 Module 抽象类,缓存 Module 。
#name() 实现方法,返回模块名为
"cache" 。
#services() 实现方法,返回 Service 类名:ApplicationCacheService 、InstanceCacheService 、ServiceIdCacheService 、ServiceNameCacheService 。
2.2 ApplicationCacheService
org.skywalking.apm.collector.cache.service.ApplicationCacheService ,应用数据缓存服务接口。
- Table :
org.skywalking.apm.collector.storage.table.register.ApplicationTable - Data :
org.skywalking.apm.collector.storage.table.register.Application
2.3 InstanceCacheService
org.skywalking.apm.collector.cache.service.InstanceCacheService ,应用实例数据缓存服务接口。
- Table :
org.skywalking.apm.collector.storage.table.register.InstanceTable - Data :
org.skywalking.apm.collector.storage.table.register.Instance
2.4 ServiceNameCacheService
org.skywalking.apm.collector.cache.service.ServiceNameCacheService ,服务名数据缓存服务接口。org.skywalking.apm.collector.cache.service.ServiceIdCacheService ,服务编号数据缓存服务接口。
- Table :
org.skywalking.apm.collector.storage.table.register.ServiceNameTable - Data :
org.skywalking.apm.collector.storage.table.register.ServiceName
3. collector-cache-guava-provider
collector-cache-guava-provider ,基于 Google Guava 的缓存组件实现。
项目结构如下 :
默认配置,在 application-default.yml 已经配置如下:
cache:
guava:
3.1 CacheModuleGuavaProvider
org.skywalking.apm.collector.cache.guava.CacheModuleGuavaProvider ,实现 ModuleProvider 抽象类,基于 Guava 的缓存组件服务提供者。
#name() 实现方法,返回组件服务提供者名为 "guava" 。
module() 实现方法,返回组件类为 CacheModule 。
#requiredModules() 实现方法,返回依赖组件为空。
#prepare(Properties) 实现方法,执行准备阶段逻辑。
- 第 44 行 :创建 ApplicationCacheGuavaService 、InstanceCacheGuavaService 、ServiceIdCacheGuavaService 、ServiceNameCacheGuavaService 对象,并调用
#registerServiceImplementation()父类方法,注册到services。
#start() 实现方法,方法为空。
#notifyAfterCompleted() 实现方法,方法为空。
3.2 ApplicationCacheGuavaService
org.skywalking.apm.collector.cache.guava.service.ApplicationCacheGuavaService ,实现 ApplicationCacheService 接口,基于 Guava 的应用数据缓存服务实现类。
3.3 InstanceCacheGuavaService
org.skywalking.apm.collector.cache.guava.service.InstanceCacheGuavaService ,实现 InstanceCacheService 接口,基于 Guava 的应用实例数据缓存服务实现类。
3.4 ServiceNameCacheGuavaService
org.skywalking.apm.collector.cache.guava.service.ServiceNameCacheGuavaService ,实现 ServiceNameCacheService 接口,基于 Guava 的服务名数据缓存服务实现类。org.skywalking.apm.collector.cache.guava.service.ServiceIdCacheGuavaService ,实现 ServiceNameCacheService 接口,基于 Guava 的服务编号数据缓存服务实现类。
666. 彩蛋
真的是一篇水文,都写的无从下手,只好罗列了相关的类。见谅。
胖友,分享一波朋友圈可好。