简体   繁体   English

使用 mmap 从文件中随机读取,但读取吞吐量不符合预期

[英]Use mmap for random read from file but the read throuput is not as expected

I write kv data into file with value size of 100KB and key size of 10Bytes.我将 kv 数据写入值大小为 100KB 且密钥大小为 10Bytes 的文件中。 Only value data is written into file and indices of keys are stored in ram.只有值数据写入文件,键的索引存储在 ram 中。 I write 10M keys and I get a 1TB value file.我写了 10M 个密钥,得到了一个 1TB 的值文件。 I use nvme ssd and 100G memory. Then I use mmap to read data from the file.我用的是nvme ssd和100G memory。然后我用mmap从文件中读取数据。 I get a read throughput of 1.8GB/s which is calculated by my metrics code.我得到 1.8GB/s 的读取吞吐量,这是根据我的指标代码计算得出的。 But my disk read throughput is 3.2GB/s, which is observed by iostat .但是我的磁盘读取吞吐量是 3.2GB/s,这是通过iostat观察到的。 I think this is caused by prefetch .我认为这是由prefetch引起的。 So I use madvise to close prefetch as follows.所以我使用madvise关闭prefetch如下。

  const void* p_val_buffer_ = mmap(NULL, val_buffer_size_, PROT_READ,
                       MAP_PRIVATE | MAP_POPULATE | MAP_NONBLOCK, fd, 0);
  if (nullptr == p_val_buffer_) return -2;

  int ret =
      madvise(const_cast<void*>(p_val_buffer_), val_buffer_size_, MADV_RANDOM);
  if (0 != ret) {
    return ret;
  }

I get the same read throuput but the throughput is only 600MB/s.我得到相同的读取吞吐量,但吞吐量仅为 600MB/s。 This is far below the limit performance of NMVE SSD.这远低于NMVE SSD的极限性能。 Anyone help me?有人帮帮我吗?

I found the problem.我发现了问题。 It is because I keep using 10 threads to read data when I use MADV_RANDOM .这是因为我在使用MADV_RANDOM时一直使用 10 个线程来读取数据。 That is not enough to make a deep io depth.这还不足以达到 io 的深度。 I use 100 threads and I can get read throughput of 3.2GB/s我使用 100 个线程,可以获得 3.2GB/s 的读取吞吐量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM