c++ - 创建 boost::file_mapping 对象的成本?

标签 c++ performance boost ipc filemap

我有一个文件解析器,它将文件加载为文件映射对象,然后根据调用者的需求映射区域。 可以在本地或通过网络访问这些文件。

这个文件读取是顺序的。

我有两种方法 -

Approach 1

Create a file_mapping object, say f.

Create mapped regions using 'f', where at a time, only one mapped_region is active.

Approach 2

Create new file_mapping object(for the same file), every time a mapped_region is to be created.

方法 2 假设 file_mapping 是为进程间通信而设计的,因此为同一个文件创建多个 file_mapping 对象不是问题。

When the file was accessed locally, the performance benchmarks, shown, similar timings in both the approaches(for a 3GB File)

However, when the files were being accessed from over the network, Approach 2, performed ~5 times slower as compared to Approach 1.

在这两种方法中,mapped_region 在创建新区域之前都会被破坏。

方法 2 的唯一区别是为每个 mapped_region 创建和销毁 file_mapping 对象。

Bench marking Procedure for sequential file read operation:
-File Size : 3GB
-Number of Mapped Regions Created : 8600
-Mapped Region Size : Variable, varies in the range of 9KB - 900KB
-Mapped Region Access : All the regions are accessed immediately after their creation.
-Mapped Region Creation Frequency : One after the other in loop, with some processing of the data extracted from mapped region. The processing involves recursive structure population, though depth is max 10. It is not very intensive.

我想了解:

Why is there such a huge difference in timings?

What exactly happens when a file_mapping object is created?

What exactly happens when a mapped_region objected is created?

Does the OS searches for a big chunk of memory during file_mapping creation or during mapped_region creation?

When is the file data actually loaded in main memory?

非常感谢。

最佳答案

如果不了解您的基准程序,即您创建 mapped_region 对象的频率、映射部分有多大以及实际访问了其中的哪些部分,就不可能回答这个问题。

还不清楚在您的实现中文件映射对象 (boost::file_mapping) 是否也显式打开文件句柄,或者文件由您打开。

我只能猜测在网络文件系统中创建文件和映射对象可能需要更多的 PC 间通信(用于同步)。

关于c++ - 创建 boost::file_mapping 对象的成本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55254767/

相关文章:

c++ - 这是 Visual C++ 2010 中的错误,还是我遗漏了什么?

c++ - 无法通过 SQLApi++ 连接到 MemSQL

c++ - 不能用boost编译?

c++ - Qt中如何从txt文件中加载大数据

c++ - Boost Multi-Index 自定义复合键比较器

c++ - 如何在 CMake 文件中添加定义 QT_NO_DEBUG_OUTPUT?

java - 如何监控java应用程序的堆栈使用情况

c++ - 动态分配的数组或 std::vector

delphi - 有没有办法保存对象的状态以便以后更快地重新加载?

c++ - 使用一个参数初始化 boost::hana::tuple