适用场景全新升级!扩展 Dragonfly2 作为分布式缓存系统架构 | 龙蜥技术

简介: 对于不存在的一个远端源地址,Dragonfly无法分发数据应该怎么办?

640.png

文/龙蜥社区开发者

Dragonfly2 简介

Dragonfly 作为龙蜥社区的镜像加速标准解决方案,是一款基于 P2P 的智能镜像和文件分发工具。它旨在提高大规模文件传输的效率和速率,最大限度地利用网络带宽。在应用分发、缓存分发、日志分发和镜像分发等领域被大规模使用。


现阶段 Dragonfly 基于 Dragonfly1.x 演进而来,在保持 Dragonfly1.x 原有核心能力的基础上,Dragonfly 在系统架构设计、产品能力、使用场景等几大方向上进行了全面升级。


Dragonfly 架构主要分为三部分 Manager、Scheduler、Seed Peer 以及 Peer 各司其职组成 P2P 下载网络,Dfdaemon 可以作为 Seed Peer 和 Peer。详细内容可以参考架构文档(链接见文末),下面是各模块功能:

  • Manager:维护各 P2P 集群的关联关系、动态配置管理、用户态以及权限管理等功能。也包含了前端控制台,方便用户进行可视化操作集群。
  • Scheduler:为下载节点选择最优下载父节点。异常情况控制 Dfdaemon 回源。
  • Seed Peer:Dfdaemon 开启 Seed Peer 模式可以作为 P2P 集群中回源下载节点, 也就是整个集群中下载的根节点。
  • Peer:通过 Dfdaemon 部署,基于 C/S 架构提供 dfget 命令行下载工具,以及 dfget daemon 运行守护进程,提供任务下载能力。

 

640 (49).png

更多详细信息可以参考 Dragonfly 官网(链接见文末)

问题背景

虽然 Dragonfly 的定位是一个基于 P2P 的文件分发系统,但是分发的文件必须是能够从网络上下载的文件,无论是 rpm 包还是容器镜像内容,最终都是有一个地址源的,用户可以通过 dfget 命令向 dfdaemon 发起下载请求,然后 Dragonfly P2P 系统负责下载,如果数据不在其他 Peer 上,那么 Peer 或者 SeedPeer 自己会回源,直接从源下载数据,然后返回给用户。


但是有些场景我们需要分发的数据是某个节点上生成的,不存在一个远端的源地址,这个时候 Dragonfly 就无法分发这种数据了。所以我们希望 Dragonfly 能够增加对这种场景的支持,其实相当于把 Dragonfly 当作了一个分布式的基于 P2P 的缓存和任意数据分发系统。

扩展 Dragonfly2

所以我们设想中的 Dragonfly 缓存系统架构是这样的:

640 (50).png

  • 每个计算节点上(比如神龙)部署一个 dfdaemon,作为一个 peer 加入 P2P 网络。
  • 接受来自本节点的请求
  • 为其他 peer 提供上传服务
  • 每个 peer 只负责管理自己本地的 cache 数据,不负责回源,回源由业务进程负责
  • 每个集群可以部署一个到多个基于 ECS 的 scheduler 节点。
  • 记录文件 P2P 网络的文件信息
  • 下载调度
  • 多 scheduler 节点解决单点故障问题
  • 每个 cache 系统中的文件都会通过 ringhash 映射到某个 scheduler 上
  • 一个或者多个 Manager 作为集群管理者。
  • 负责向 scheduler 和 peer 节点发送动态配置
  • 收集 metrics 等信息


接口设计

dfdaemon 接口

原来的 daemon 接口:

pkg/rpc/dfdaemon/dfdaemon.proto
// Daemon Client RPC Service
service Daemon{
  // Trigger client to download file
  rpc Download(DownRequest) returns(stream DownResult);
  // Get piece tasks from other peers
  rpc GetPieceTasks(base.PieceTaskRequest)returns(base.PiecePacket);
  // Check daemon health
  rpc CheckHealth(google.protobuf.Empty)returns(google.protobuf.Empty);
}

新增  4 个接口:

service Daemon { 
// Check if given task exists in P2P cache system
rpc StatTask(StatTaskRequest) returns(google.protobuf.Empty);
// Import the given file into P2P cache system
rpc ImportTask(ImportTaskRequest) returns(google.protobuf.Empty);
// Export or download file from P2P cache system
rpc ExportTask(ExportTaskRequest) returns(google.protobuf.Empty);
// Delete file from P2P cache system
rpc DeleteTask(DeleteTaskRequest) returns(google.protobuf.Empty);
}

scheduler 接口

原来的 scheduler 接口:

// Scheduler System RPC Service
service Scheduler{
// RegisterPeerTask registers a peer into one task.
rpc RegisterPeerTask(PeerTaskRequest)returns(RegisterResult);
// ReportPieceResult reports piece results and receives peer packets.
// when migrating to another scheduler,
// it will send the last piece result to the new scheduler.
rpc ReportPieceResult(stream PieceResult)returns(stream PeerPacket);
// ReportPeerResult reports downloading result for the peer task.
rpc ReportPeerResult(PeerResult)returns(google.protobuf.Empty);
// LeaveTask makes the peer leaving from scheduling overlay for the task.
rpc LeaveTask(PeerTarget)returns(google.protobuf.Empty);
}

 

新增 2 个接口,下载复用之前的 RegisterPeerTask()接口,删除复用之前的LeaveTask() 接口:

// Scheduler System RPC Service
service Scheduler{
// Checks if any peer has the given task
rpc StatTask(StatTaskRequest)returns(Task);
// A peer announces that it has the announced task to other peers
rpc AnnounceTask(AnnounceTaskRequest) returns(google.protobuf.Empty);
}

接口请求时序图

StatTask

640 (51).png

ImportTask

640 (52).png

ExportTask

640 (53).png

DeleteTask

640 (54).png

代码实现

目前代码已经合并,可以在 Dragonfly v2.0.3 版本中使用。

upstream PR:

https://github.com/dragonflyoss/Dragonfly2/pull/1227


使用方法

除了增加新的接口之外,我们还增加了一个叫 dfcache 的命令,用于测试,使用方法如下:

- add a file into cache system
dfcache import --cid sha256:xxxxxx --tag testtag /path/to/file
- check if a file exists in cache system
dfcache stat --cid testid --local # only check local cache
dfcache stat --cid testid # check other peers as well
- export/download a file from cache system
dfcache export --cid testid -O /path/to/output
- delete a file from cache system, both local cache and P2P network
dfcache delete -i testid -t testtag

测试及效果

测试方法

通过新增的 dfcache 命令,在一个节点上向 P2P cache 系统中添加不同大小的文件,然后在另外一个节点上针对这个文件做查询、下载、删除等操作。例如:

# dd if=/dev/urandom of=testfile bs=1M count =1024
# dfcache stat -i testid # 检查一个不存在的文件
# dfcache import -i testid testfile
# on another node
# dfcache stat -i testid
# dfcache export -i testid testfile.export

测试效果

两台 ecs,网络走 vpc,带宽 3.45 Gbits/s (约 440MiB/s):

640 (55).png

下载的 ecs 磁盘带宽 180MiB/s 左右:

640 (56).png

640 (57).png

相关阅读链接:

1、Dragonfly1.x 链接地址:

https://github.com/dragonflyoss/Dragonfly

2、Dragonfly 架构文档:

https://d7y.io/zh/docs/concepts/terminology/architecture/

3、Dragonfly 官网链接:

https://d7y.io/

4、龙蜥云原生SIG地址链接:

https://openanolis.cn/sig/cloud-native

—— 完 ——


加入龙蜥社群


加入微信群:添加社区助理-龙蜥社区小龙(微信:openanolis_assis),备注【龙蜥】与你同在;加入钉钉群:扫描下方钉钉群二维码。

640 (5).png

相关文章
|
27天前
|
设计模式 安全 Java
【分布式技术专题】「Tomcat技术专题」 探索Tomcat技术架构设计模式的奥秘(Server和Service组件原理分析)
【分布式技术专题】「Tomcat技术专题」 探索Tomcat技术架构设计模式的奥秘(Server和Service组件原理分析)
32 0
|
25天前
|
存储 缓存 监控
构建高效可扩展的后端服务架构
在当今互联网时代,构建高效可扩展的后端服务架构对于企业的业务发展至关重要。本文将探讨如何通过合理设计和优化后端服务架构,实现系统的高性能、高可用性和易扩展性,从而满足不断增长的业务需求和用户规模。
18 0
|
2天前
|
存储 缓存 运维
软件体系结构 - 缓存技术(5)Redis Cluster
【4月更文挑战第20天】软件体系结构 - 缓存技术(5)Redis Cluster
136 10
|
2天前
|
存储 缓存 NoSQL
软件体系结构 - 缓存技术
【4月更文挑战第20天】软件体系结构 - 缓存技术
36 7
|
8天前
|
弹性计算 安全 Serverless
图像处理场景下的Serverless架构
【4月更文挑战第15天】图像处理场景下的Serverless架构
|
13天前
|
运维 监控 自动驾驶
构建可扩展的应用程序:Apollo与微服务架构的完美结合
构建可扩展的应用程序:Apollo与微服务架构的完美结合
32 10
|
24天前
|
负载均衡 网络协议 Java
构建高效可扩展的微服务架构:利用Spring Cloud实现服务发现与负载均衡
本文将探讨如何利用Spring Cloud技术实现微服务架构中的服务发现与负载均衡,通过注册中心来管理服务的注册与发现,并通过负载均衡策略实现请求的分发,从而构建高效可扩展的微服务系统。
|
27天前
|
存储 监控 安全
金石推荐 | 【分布式技术专题】「单点登录技术架构」一文带领你好好认识以下Saml协议的运作机制和流程模式
金石推荐 | 【分布式技术专题】「单点登录技术架构」一文带领你好好认识以下Saml协议的运作机制和流程模式
62 1
|
27天前
|
存储 Java 应用服务中间件
【分布式技术专题】「架构实践于案例分析」盘点互联网应用服务中常用分布式事务(刚性事务和柔性事务)的原理和方案
【分布式技术专题】「架构实践于案例分析」盘点互联网应用服务中常用分布式事务(刚性事务和柔性事务)的原理和方案
51 0