随机磁盘写入

发布于 2024-11-27 22:02:26 字数 156 浏览 1 评论 0原文

我需要对文件进行就地随机更新。我需要更新偏移量 k1、k2、....、kn 处的文件。从性能角度来看,如果我以任何顺序写入是否重要,或者如果我以偏移量递增的顺序写入,性能是否会提高?更具体地说,我将在 RAM 中缓冲一堆更新,然后进行更新。因此,当我准备将更新刷新到磁盘时,我知道需要写入的偏移量。

I need to perform random updates in-place to a file. Let's I need to update a file at offset k1, k2, ...., kn. From a performance perspective does it matter if I write in any order or does the performance improve if I write in increasing order of offsets? More specifically I am going to buffer of bunch of updates in RAM and then update. So when I ready to flush the updates to disk I know the offset I need to write to.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謸气贵蔟 2024-12-04 22:02:26

在处理旋转磁盘上的大文件时,将硬盘驱动器的磁头从一个柱面移至另一个柱面是最大的性能杀手。头部移动得越远,影响就越大。

按顺序进行写入。这将导致(至少从统计上来说)一个柱面上的所有扇区被一起写入(没有磁头移动),然后磁头移动到相邻的柱面(尽可能短的磁头移动)。

请注意,如果您正在处理具有多个后备物理磁盘(例如 RAID、NAS)的逻辑磁盘,则通过拥有更多磁盘可以在一定程度上缓解磁头寻道问题,但除非您具有从逻辑扇区到物理存储的映射的具体知识,按扇区顺序进行更新仍然最有可能最大限度地减少头部移动。

Moving the head of a hard drive from one cylinder to another is the largest performance killer when dealing with large files on rotating disks. The further the head has to move, the larger the impact.

Do the writes in order. That will cause (statistically speaking at least) all sectors on a cylinder to be written together (no head move), then the head to move to an adjacent cylinder (shortest possible head move).

Note that if you are dealing with a logical disk that has multiple backing physical disks (e.g. RAID, NAS) the head seek issue is somewhat mitigated by having more disks, but unless you have specific knowledge of the mapping from logical sector to physical storage, doing the updates in sector order is still most likely to minimize head moves.

笙痞 2024-12-04 22:02:26

除非您知道偏移量如何转化为特定的柱面/磁头/扇区,否则我不会担心它。您的磁盘控制器可能会自行重新排序请求以提高效率,并且如果您的磁盘出现碎片,您无论如何都不知道文件的逻辑块是否是连续的。

Unless you know how your offsets translate into specific cylinders/heads/sectors, I wouldn't worry about it. Your disk controller may re-order requests for efficiency on its own, and if your disk gets fragmented you don't know whether the file's logical blocks are sequential or not anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文