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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With