首页
学习
活动
专区
圈层
工具
发布

链路追踪 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 已经配置如下:

代码语言:javascript
复制
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
下一篇
举报
领券