# Disk Seeks Considered Harmful

磁盘寻道是您可能遇到的最昂贵的操作之一。从查看执行的数量，可能不能了解到，但这是真的。相应地，请避免如下次优的选择：

- 在磁盘中到处存放很多小文件。

- 在磁盘中，到处打开、查看、读取很多小文件。

- Doing the above on files that are laid out at different times, so as to ensure that they are fragmented and cause even more seeking.

- Doing the above on files that are in different directories, so as to ensure that they are in different cylinder groups and and cause even more seeking.

- Repeatedly doing the above when it only needs to be done once.

Ways in which you can optimize your code to be seek-friendly:

- Consolidate data into a single file.

- 将数据保持在同一个目录中。

- 缓存数据以避免定期重读数据。

- 共享数据以便不必每个程序需要时都从硬盘读取。

- 考虑将所有的数据缓存在单个二进制文件中，并使文件正确对齐并可以将其 mmap。

The trouble with disk seeks are compounded for reads, which is unfortunately what we are doing. Remember, reads are generally synchronous while writes are asynchronous. This only compounds the problem, serializing each read, and contributing to program latency.