相关疑难解决方法(0)

随机访问gzip文件?

我有一个非常大的文件压缩与gzip坐在磁盘上.生产环境基于"云",因此存储性能很差,但CPU很好.以前,我们的数据处理流程始于gzip -dc从磁盘上传输数据.

现在,为了并行工作,我想运行多个管道,每个管道都需要一对字节偏移 - 开始和结束 - 并获取该文件的块.使用普通文件,这可以通过head和实现tail,但我不知道如何使用压缩文件有效地完成它; 如果我gzip -dc和管道进入head,文件末尾的偏移对将涉及浪费地搜索整个文件,因为它慢慢解压缩.

所以我的问题实际上是关于gzip算法 - 理论上是否有可能在底层文件中寻找一个字节偏移量或得到它的任意一块,而没有解压缩整个文件到那一点的全部含义?如果没有,我可以如何有效地将文件分区为多个进程的"随机"访问,同时最小化I/O吞吐量开销?

unix concurrency streaming gzip

23
推荐指数
4
解决办法
5466
查看次数

Seek 对使用 boost filtering_istreambuf 初始化的 std::istream 不起作用

我试图读取一个文件。它应该是内存映射的性能。我想使用 iostream 的 boost 过滤器链来轻松包含 zip、bzip2 和 gzip 解压缩。

我尝试采用Using boost::iostreams mapping_file_source and filtering_streambuf to decompress file 中提出的解决方案。

我的问题:当我尝试seek()直播时,出现异常:“无随机访问”。这很奇怪,因为从文档中我了解到我可以std::istream用作接口。

我想出了以下代码(也在 coliru 上):

#include <iostream>
#include <stdio.h>
#include <boost/iostreams/device/mapped_file.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>

// and later also include ...
//#include <boost/iostreams/filter/gzip.hpp>
//#include <boost/iostreams/filter/bzip2.hpp>

int main()
{
    namespace io = boost::iostreams;
    io::mapped_file_source inputDevice;                           // the device to read from (file)
    io::stream<io::mapped_file_source> mappedFileStream; // the memory mapped file stream    
    io::filtering_istreambuf filteredInputStream;                 // the source file …
Run Code Online (Sandbox Code Playgroud)

c++ boost

4
推荐指数
1
解决办法
993
查看次数

标签 统计

boost ×1

c++ ×1

concurrency ×1

gzip ×1

streaming ×1

unix ×1