纯Python中的fastcd(内容定义的分块)。
fastcdc的Python项目详细描述
快速疾病控制中心
此包在中实现了“fastcd”内容定义的分块算法 提供可选cython支持的Python。了解更多内容 定义分块及其应用,请参阅下面链接的参考资料。在
要求
- ^{a4.6以后的版本。在Linux、Mac和 窗口
安装
$ pip install fastcdc
启用对哈希算法的附加支持 (xxhash和 blake3)使用
^{pr2}$示例用法
可以在源存储库的examples
目录中找到一个示例,
它演示将任意大小的文件读入内存映射缓冲区
并通过chunker传递它们(并计算
每个块)。在
使用默认设置计算块:
$ fastcdc tests/SekienAkashita.jpg hash=103159aa68bb1ea98f64248c647b8fe9a303365d80cb63974a73bba8bc3167d7 offset=0size=22366hash=3f2b58dc77982e763e75db76c4205aaab4e18ff8929e298ca5c58500fee5530d offset=22366size=10491hash=fcfb2f49ccb2640887a74fad1fb8a32368b5461a9dccc28f29ddb896b489b913 offset=32857size=14094hash=bd1198535cdb87c5571378db08b6e886daf810873f5d77000a54795409464138 offset=46951size=18696hash=d6347a2e5bf586d42f2d80559d4f4a2bf160dce8f77eede023ad2314856f3086 offset=65647size=43819
自定义最小大小、平均大小、最大大小和哈希函数
$ fastcdc -mi 16384 -s 32768 -ma 65536 -hf sha256 tests/SekienAkashita.jpg hash=5a80871bad4588c7278d39707fe68b8b174b1aa54c59169d3c2c72f1e16ef46d offset=0size=32857hash=13f6a4c6d42df2b76c138c13e86e1379c203445055c2b5f043a5f6c291fa520d offset=32857size=16408hash=0fe7305ba21a5a5ca9f89962c5a6f3e29cd3e2b36f00e565858e0012e5f8df36 offset=49265size=60201
扫描目录中的文件并报告重复。
$ fastcdc scan ~/Downloads [####################################] 100% Files: 1,332 Chunk Sizes: min 4096 - avg 16384 - max 131072 Unique Chunks: 506,077 Total Data: 9.3 GB Dupe Data: 873.8 MB DeDupe Ratio: 9.36 % Throughput: 135.2 MB/s
显示帮助
$ fastcdc Usage: fastcdc [OPTIONS] COMMAND [ARGS]... Options: --version Show the version and exit. --help Show this message and exit. Commands: chunkify* Find variable sized chunks for FILE and compute hashes. benchmark Benchmark chunking performance. scan Scan files in directory and report duplication.
从python代码中使用
测试还提供了一些使用chunker的简短示例,其中 代码片段就是一个例子:
fromfastcdcimportfastcdcresults=list(fastcdc("tests/SekienAkashita.jpg",16384,32768,65536))assertlen(results)==3assertresults[0].offset==0assertresults[0].length==32857assertresults[1].offset==32857assertresults[1].length==16408assertresults[2].offset==49265assertresults[2].length==60201
参考资料
该算法如“FastCDC:a Fast and Efficient Content Defined”中所述 用于重复数据消除的分块方法”请参阅 paper, 和 presentation 了解详情。有一些细微的区别,如下所述。在
与FastCDC论文的差异
以下解释抄袭自 ronomon/deduplication从这以后 codebase只不过是该实现的翻译:
The following optimizations and variations on FastCDC are involved in the chunking algorithm:
- 31 bit integers to avoid 64 bit integers for the sake of the Javascript reference implementation.
- A right shift instead of a left shift to remove the need for an additional modulus operator, which would otherwise have been necessary to prevent overflow.
- Masks are no longer zero-padded since a right shift is used instead of a left shift.
- A more adaptive threshold based on a combination of average and minimum chunk size (rather than just average chunk size) to decide the pivot point at which to switch masks. A larger minimum chunk size now switches from the strict mask to the eager mask earlier.
- Masks use 1 bit of chunk size normalization instead of 2 bits of chunk size normalization.
这个代码库的主要目标是使用 许可证,可用于新项目,无需担心 与现有实现的数据奇偶性。在
现有技术
这个包最初是由nathanfiedler实现的Python端口(参见 nlfiedler链接如下)。在
- nlfiedler/fastcdc-rs
- 此代码所基于的Rust实现。在
- ronomon/deduplication
C++和JavaScript实现,其中RID实现是基于。在
- FastCDC的另一种实现方式。在
- 类似但稍早的算法由一些相同的研究人员。在
更改日志
[1.4.2]-2020年11月25日
- 向PyPI添加二进制版本(谢彦波)
- 更新依赖项
[1.4.1]-2020年9月30日
- 修正cython版本中fat选项的问题
- 更新的依赖项
[1.4.0]-2020年8月8日
- 使用scan命令添加对多路径的支持
- 修复建筑cython扩展的问题
- 用fat选项修复问题
- 修正零点分离误差
[1.3.0]-2020-06-26
- 添加新的
scan
命令来计算目录的重复数据消除率
[1.2.0]-2020-05-23
添加
- 更快的可选cython实现
- 基准命令
[1.1.0]-2020-05-09
添加
- 高级API
- 对流的支持
- 支持自定义哈希函数
[1.0.0]-2020-05-07
添加
- 初始释放(端口nlfiedler/fastcdc-rs)。在
- 项目
标签: