Total Pageviews

Understanding Linux

Wednesday, September 5, 2012

Disk I/O Basics

Seek Time:
Generally speaking, when the I/O request comes in for a particular piece of data, the head will not be above the correct track on the disk. The arm will need to move so that the head is directed over the correct track where it must then wait for the platter spin to present the target data beneath it. As the data could potentially be anywhere on the platter, the average seek time is time taken for the head to travel half way across the disk.

Latency (Rotational Latency):
Latency is the average time for the sector being accessed to rotate into position under a head, after a completed seek. It is easily calculated from the spindle speed, being the time for half a rotation.

Response Time = (Average Latency) + (Average Seek Time)

Disk Transfer Rates (Aka Sequential Read) :
how much data the drive could potentially deliver on a sequential read. Mainly dominated by the latency (ie rotational delay).


Let's assume the OS has directed the disk to perform a large sequential read operation. After the initial average overhead (seek + latency delay) to locate the start of the data, the actuator arm need now move only fractionally with each disk rotation to continue the read (assuming the data is contigious). The rate at which we can read data off the disk is now limited by the platter RPM and how much data the manufacturer can pack into each track.

Data per track on a 2.5 inch drive is ~1.43MB
Now a disk spinning at 7200RPM is actually spinning 120 times per second. Which means that the total amount of data which can pass under the head in 1 second is a massive 173MB (120 * 1.43MB).

Taking into account that perhaps about 87% of a track is data, this gives a maximum disk throughput of about 150MB/s.

Note that this calculation is best case -it assumes the data is being sequentially read from the outermost tracks of the disk and that there are no other delays between the head reading the data and the operating system which requested it. As we start populating the drive with data, the tracks get smaller and smaller as we work inwards (don't worry -we'll cover this in Zone Bit Recording below). This means less data per track as you work towards the centre of the platter, and therefore the less data passing under the head in any given time frame.


To see how bad the sequential read rate can get, let's perform the same calculation for the smallest track which has a 1 inch diameter. This gives a worst case sequential read rate of 60MB/s! So when your users report that their computers get progressively slower with time, they might not actually be imagining it. As the disk fills up, retrieving the data from the end of a 2.5inch drive will be 2.5 times slower than retrieving it from the start. For a 3.5 inch desktop harddisk the difference is 3.5 times.

Disk Operations per Second - IOP:

The problem with databases is that database I/O is unlikely to be sequential in nature. One query could ask for some data at the top of a table, and the next query could request data from 100,000 rows down. In fact, consecutive queries might even be for different databases.


If we were to look at the disk level whilst such queries are in action, what we'd see is the head zipping back and forth like mad -apparently moving at random as it tries ro read and write data in response to the incoming I/O requests.

In the database scenario, the time it takes for each small I/O request to be serviced is dominated by the time it takes the disk heads to travel to the target location and pick up the data. That is to say, the disk's reponse time will now dominate our performance. The response time now reflects the time our storage takes to service an I/O request when the request is random and small.

For seagate drive with RPM of 7200, seek time = 11ms. Avg latency = 4.17ms.
Response time = 11 + 4.17 = 15.17ms.
So, for the specific case of our Seagate Drive with a 15.17ms response time, it will take at least on average 15.17ms to service each I/O. Turning this on it's head to give us our IOPS yeilds (1/ 0.01517) which is 66 IOPS.


Typical IOPS values are:
Drive RPM       Avg Rotational Latency (ms)    Seek Time (ms)         IOPS                TransferRate
  5400                       5.5                                     7 - 14.4                 50 - 80                ~100MB/s
  7200                       4.2                                     5.9 - 9.1                75 - 100              ~150MB/s
10,000                       3                                       3.6 - 5                  125 - 150             ~200MB/s
15,000                       2                                       2.7 - 3.7                175 - 200            ~300MB/s

Typical disk speeds are:
5400 RPM is standard for laptops
7200 RPM is the standard for PCs. 
10000 RPM is a mid-range server. 
15000 RPM is a high-end server.

Followers