链路追踪 SkyWalking 源码分析 —— Collector Cache 缓存组件

点击上方“芋道源码”,选择“设为星标

做积极的人,而不是积极废人!

源码精品专栏

 

摘要: 原创出处 http://www.iocoder.cn/SkyWalking/collector-cache-module/ 「芋道源码」欢迎转载,保留摘要,谢谢!

本文主要基于 SkyWalking 3.2.6 正式版

  • 1. 概述

  • 2. collector-cache-define

    • 2.1 CacheModule

    • 2.2 ApplicationCacheService

    • 2.3 InstanceCacheService

    • 2.4 ServiceNameCacheService

  • 3. collector-cache-guava-provider

    • 3.1 CacheModuleGuavaProvider

    • 3.2 ApplicationCacheGuavaService

    • 3.3 InstanceCacheGuavaService

    • 3.4 ServiceNameCacheGuavaService


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 的应用数据缓存服务实现类

  • EsDAO :org.skywalking.apm.collector.storage.es.dao.ApplicationEsCacheDAO

3.3 InstanceCacheGuavaService

org.skywalking.apm.collector.cache.guava.service.InstanceCacheGuavaService ,实现 InstanceCacheService 接口,基于 Guava 的应用实例数据缓存服务实现类

  • EsDAO :org.skywalking.apm.collector.storage.es.dao.InstanceEsCacheDAO

3.4 ServiceNameCacheGuavaService

org.skywalking.apm.collector.cache.guava.service.ServiceNameCacheGuavaService ,实现 ServiceNameCacheService 接口,基于 Guava 的服务名数据缓存服务实现类
org.skywalking.apm.collector.cache.guava.service.ServiceIdCacheGuavaService ,实现 ServiceNameCacheService 接口,基于 Guava 的服务编号数据缓存服务实现类

  • EsDAO :org.skywalking.apm.collector.storage.es.dao.ServiceNameEsCacheDAO



欢迎加入我的知识星球,一起探讨架构,交流源码。加入方式,长按下方二维码噢

已在知识星球更新源码解析如下:


如果你喜欢这篇文章,喜欢,转发。

生活很美好,明天见(。・ω・。)ノ♡

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值