Part 6 of 7 · 3 min read
Check and generalise
Check the result and think about other disks
Think of a surveyor who measures a plot twice with different tools before signing the report. A second measurement that agrees makes the result trustworthy. The analogy stops in one place: a surveyor's plot does not change, and a disk's behaviour may differ on another day or machine.
In plain words: After a change, the numbers are measured again with the same tool. Here the second run of the program gave 6,792, 48,652, 95,218 and 150,070 records per second, within about 10% of the first run. The result is stable. The device writes were again 15,002, 1,502, 152 and 28. The fix, a group of 10 or more, works on this machine. On another machine the numbers will differ, so measure there as well.
A worked example (made up to show the idea). On a 7,200 RPM spinning disk (page 1), suppose each fsync must wait at least one turn of the platter, 8.33 ms, for its write to pass under the head. The best rate would then be 1,000 / 8.33 = 120 syncs per second. With one sync for each record, the 5,000 records need 5,000 / 120 = 41.7 s, a rate of 120 records per second, which is 60 times lower than the 7,262 on the test machine. With a group of 100 the rate would be 12,000 records per second, if the data rate allows. The same program gains far more from grouping on a slower device. This is an estimate from the model and was not measured.
The key lines. The method has five steps: report, measure, find the fixed cost, change one thing, measure again. It works for databases, file servers and logs alike.
Durability
Durability is the guarantee that data that was acknowledged as written will survive a crash or a power loss. A program obtains it by forcing the data to a persistent device, for example with fsync, before it acknowledges the write.
Example: a program that calls fsync and then replies "saved" to a client has made the saved record durable.
Check yourself: 1. Why is the second run of the program important? 2. At 120 syncs per second, how long do 5,000 single-record syncs take? 3. Why does grouping help more on a slower disk?
Words you will meet
| Word | Meaning |
|---|---|
| fsync | Forces a file's data to the device. |
| Durability | Acknowledged data survives a crash. |
| Group commit | One sync for many records. |
| Bottleneck | The limit that decides the rate of the whole. |
| Device writes | Write requests that reach the disk, from /proc/diskstats. |
Quick notes
- Start with the symptom in numbers, then find the bottleneck. Change one thing and measure again.
fsyncforces data to the device and waits. Each call has a fixed cost.- In the test, each fsync caused about three device writes on ext4.
- Time follows the number of
fsynccalls, not the number of records. - Group commit syncs once for many records. It trades speed against the records a crash can lose.
- Slower devices gain more from grouping.