Measuring disk cache impact on system performance

Measuring disk cache impact on system performance

When you access data or load applications on your computer, the data blocks containing the data or applications are typically fetched from your local hard drive. These data blocks are loaded into memory, and are then ready for your computer to process. Since fetching data blocks from the hard drive or other external sources are very expensive in terms of time, your operating system typically implements a disk cache – data blocks that are loaded into memory remain there for some period of time just in case it needs to be accessed again. If the data block is access again while already being resident in the disk cache, your computer saves time by not having to load the data block from disk.

Let’s run a couple of tests to sees how much time your computer can save by utilizing this type of disk cache. What I will do is to issue a command that causes my computer to read a great number of data blocks from my computer’s hard drive, which causes the disk blocks to be added to the disk cache. Then I’ll run the same command again, to measure what effect having the disk blocks already loaded into disk cache have on the command completion time. Lastly, I’ll clear the disk cache, and measure the command completion time again.

The command I’ll use in the examples below is simply “time ls -R / >/dev/null 2>&1”, which lists all files on my computer, and tells me how long the time took to complete. Before I start I’ll clear my disk cache (must be run as root):

Now let’s run the file listing command:

As you can see, the command took 1 minute and 33 seconds to complete. Now, let’s run the same command again. Now the relevant disk blocks should already be cached in memory, so I expect the command to take a lot less time to complete.

The command finished in less than 1.5 seconds! Wow! Let’s run the same command a third time, but clear the cache before doing so:

….and then:

Now we’re back to a minute and half for the command to complete.

To sum up, what we’ve seen here is that disk cache can significantly increase the system performance, since fetching data blocks externally (for example hard drive) takes a lot more time than having the data already available in memory. Of course, this applies best to situations where your computer reads more data blocks than it writes.

Leave a Reply

%d bloggers like this: