I/O Time: Doing the Math

Let's do mathematical analysis to analyze the performance of a disk.

We'll cover the following

Now that we have an abstract model of the disk, we can use a little analysis to better understand disk performance. In particular, we can now represent I/O time as the sum of three major components:

TI/O=Tseek+Trotation+TtransferT_{I/O}=T_{seek}+T_{rotation}+T_{transfer}

Note that the rate of I/O (RI/OR_{I/O}), which is often more easily used for comparison between drives (as we will do below), is easily computed from the time. Simply divide the size of the transfer by the time it took:

RI/O=SizeTransferTI/OR_{I/O}=\frac{Size_{Transfer}}{T_{I/O}}

To get a better feel for I/O time, let us perform the following calculation. Assume there are two workloads we are interested in. The first, known as the random workload, issues small (e.g., 4KB) reads to random locations on the disk. Random workloads are common in many important applications, including database management systems. The second, known as the sequential workload, simply reads a large number of sectors consecutively from the disk, without jumping around. Sequential access patterns are quite common and thus important as well.

To understand the difference in performance between random and sequential workloads, we need to make a few assumptions about the disk drive first. Let’s look at a couple of modern disks from Seagate. The first, known as the Cheetah 15K.5“Cheetah 15K.5” by Seagate, Inc… Available at this website, we’re pretty sure it is: http://www.seagate.com/docs/pdf/datasheet/disc/ds-cheetah-15k-5-us.pdf. See above commentary on data sheets., is a high-performance SCSI drive. The second, the Barracuda“Barracuda ES.2 data sheet” by Seagate, Inc… Available at this website, at least, it was: http://www.seagate.com/docs/pdf/datasheet/disc/ds_barracuda_es.pdf. A data sheet; read at your own risk. Risk of what? Boredom., is a drive built for capacity. Details on both are found in the table below.

As you can see, the drives have quite different characteristics, and in many ways nicely summarize two important components of the disk drive market. The first is the “high performance” drive market, where drives are engineered to spin as fast as possible, deliver low seek times, and transfer data quickly. The second is the “capacity” market, where cost per byte is the most important aspect. Thus, the drives are slower but pack as many bits as possible into the space available.

From these numbers, we can start to calculate how well the drives would do under our two workloads outlined above. Let’s start by looking at the random workload.

Random workload

Assuming each 4 KB read occurs at a random location on disk, we can calculate how long each such read would take. On the Cheetah:

Tseek=4ms,Trotation=2ms,Ttransfer=30microsecsT_{seek}=4\:ms,\: T_{rotation}=2\:ms,\:T_{transfer}=30\:microsecs

The average seek time (4 milliseconds) is just taken as the average time reported by the manufacturer; note that a full seek (from one end of the surface to the other) would likely take two or three times longer. The average rotational delay is calculated from the RPM directly. 15000 RPM is equal to 250 RPS (rotations per second); thus, each rotation takes 4 ms. On average, the disk will encounter a half rotation and thus 2 ms is the average time. Finally, the transfer time is just the size of the transfer over the peak transfer rate; here it is vanishingly small (30 microseconds; note that we need 1000 microseconds just to get 1 millisecond!).

Thus, from our equation above, TI/OT_{I/O} for the Cheetah roughly equals 6 ms. To compute the rate of I/O, we just divide the size of the transfer by the average time, and thus arrive at RI/OR_{I/O} for the Cheetah under the random workload of about 0.66 MB/s. The same calculation for the Barracuda yields a TI/O of about 13.2 ms, more than twice as slow, and thus a rate of about 0.31 MB/s.

Sequential workload

Now let’s look at the sequential workload. Here we can assume there is a single seek and rotation before a very long transfer. For simplicity, assume the size of the transfer is 100 MB. Thus, TI/OT_{I/O} for the Cheetah and Barracuda is about 800 ms and 950 ms, respectively. The rates of I/O are thus very nearly the peak transfer rates of 125 MB/s and 105 MB/s, respectively. The following table summarizes these numbers.

The table shows us a number of important things. First, and most importantly, there is a huge gap in drive performance between random and sequential workloads, almost a factor of 200 or so for the Cheetah and more than a factor 300 difference for the Barracuda. And thus we arrive at the most obvious design tip in the history of computing.

A second, more subtle point: there is a large difference in performance between high-end “performance” drives and low-end “capacity” drives. For this reason (and others), people are often willing to pay top dollar for the former while trying to get the latter as cheaply as possible.

TIP: USE DISKS SEQUENTIALLY

When at all possible, transfer data to and from disks in a sequential manner. If sequential is not possible, at least think about transferring data in large chunks: the bigger, the better. If I/O is done in little random pieces, I/O performance will suffer dramatically. Also, users will suffer. In addition, you will also suffer, knowing what suffering you have wrought with your careless random I/Os.

ASIDE: COMPUTING THE “AVERAGE” SEEK

In many books and papers, you will see average disk-seek time cited as being roughly one-third of the full seek time. Where does this come from?

Turns out it arises from a simple calculation based on average seek distance, not time. Imagine the disk as a set of tracks, from 00 to NN. The seek distance between any two tracks xx and yy is thus computed as the absolute value of the difference between them: xy|x-y|.

To compute the average seek distance, all you need to do is to first add up all possible seek distances:

x=0Ny=0Nxy.\sum_{x=0}^{N}\sum_{y=0}^{N}|x-y|.

Then, divide this by the number of different possible seeks: N2N^2. To compute the sum, we’ll just use the integral form:

x=0Ny=0Nxydxdy.\int_{x=0}^N\int_{y=0}^N|x-y|dxdy.

To compute the inner integral, let’s break out the absolute value:

y=0x(xy)dy+y=xN(yx)dy.\int_{y=0}^x(x-y)dy+\int_{y=x}^N(y-x)dy.

Solving this leads to (xy12y2)0x+(12y2xy)xN(xy-\frac{1}{2}y^2)|_0^x+(\frac{1}{2}y^2-xy)|_x^N which can be simplified to (x2Nx+12N2)(x^2-Nx-+\frac{1}{2}N^2). Now we have to compute the outer integral:

x=0N(x2Nx+12N2),\int_{x=0}^N(x^2-Nx-+\frac{1}{2}N^2),

which results in:

(13x3N2x2+N22x)0N=N33.(\frac{1}{3}x^3-\frac{N}{2}x^2+\frac{N^2}{2}x)|_0^N=\frac{N^3}{3}.

Remember that we still have to divide by the total number of seeks (N2N^2) to compute the average seek distance: (N33)/N2=13N(\frac{N^3}{3})/N^2 = \frac{1}{3}N. Thus the average seek distance on a disk, over all possible seeks, is one-third the full distance. And now when you hear that an average seek is one-third of a full seek, you’ll know where it came from.

Get hands-on with 1400+ tech skills courses.