小编Fan*_*Fan的帖子

随机磁盘寻道和读取成本约为 16 毫秒是否合理?

我对从非 ssd 磁盘随机读取的延迟感到沮丧。根据以下测试程序的结果,在没有操作系统缓存帮助的情况下,随机读取仅 512 字节的速度约为 16 毫秒。

我尝试将 512 更改为更大的值,例如 25k,但延迟并没有增加太多。我猜是因为磁盘寻道主宰了时间。

我知道随机读取本质上很慢,但只是想确保 ~16ms 是合理的,即使对于非 ssd 磁盘也是如此。

#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char** argv) {
  int fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Failed open %s\n", argv[1]);
    return -1;
  }
  const size_t count = 512;
  const off_t offset = 25990611 / 2;
  char buffer[count] = { '\0' };
  struct timeval start_time;
  gettimeofday(&start_time, NULL);
  off_t …
Run Code Online (Sandbox Code Playgroud)

linux performance hard-drive

2
推荐指数
1
解决办法
228
查看次数

标签 统计

hard-drive ×1

linux ×1

performance ×1