0. Relationship between disk read/write and database

Source: Internet
Author: User
One disk physical structure (1) disk Disk: the disk body consists of multiple disk fragments stacked together. When the hard disk is released, the hard disk manufacturer completes low-level formatting (physical formatting). The function is to divide the blank platters into tracks with the same center and different radius ), the track is also divided into several sectors (Sector), each of which can store 1282

One disk physical structure (1) disk Disk: the disk body consists of multiple disk fragments stacked together. When the hard disk is released, the hard disk manufacturer completes low-level formatting (physical formatting). The function is to divide the blank platters into tracks with the same center and different radius ), the track is also divided into several sectors (Sector), each of which can store 1282

One Disk Physical Structure
(1) disk: the disk body of a hard disk is composed of multiple disks stacked together.

When the hard disk is released, the hard disk manufacturer completes low-level formatting (physical formatting). The function is to divide the blank platters into tracks with the same center and different radius ), the track is also divided into several sectors. Each Sector can store 128x2 n (N = 0.1.2.3) bytes. By default, the size of each Sector is 512 bytes. Generally, you do not need to perform low-level formatting.

(2) Head: Each disk has a head on both sides.

(3) spindle: all disks are rotated by the spindle motor.

(4) control the integrated circuit board: complicated! There are also ROM (including software systems) and Cache.

How to complete a single I/O operation on a two-disk
(1) Seek
When the controller sends an I/O operation command to the disk, the drive Arm (Actuator Arm) of the disk drives the Head out of the Landing Zone, in the inner ring without data), move to the top of the Track where the initial data block to be operated. This process is called Seeking ), the Time consumed is called the track Time (Seek Time );

(2) Rotating Delay
Data cannot be read immediately after the corresponding track is found. At this time, the head must wait until the disk (Platter) rotates to the Sector where the initial data block is located (Sector) and falls right below the read/write head to start reading data, the time consumed in this process of waiting for the disk to rotate to an operable sector is called the Rotational Latency );

(3) Data Transmission
Next, as the disk is rotated, the head constantly reads/writes the corresponding Data blocks until all the Data required for this IO operation is completed. This process is called Data Transfer ), the corresponding Time is called the Transfer Time (Transfer Time ). After completing these three steps, a single IO operation is completed.

Based on the process of a single disk IO operation, you can find that:
Single IO time = seek time + rotation delay + Transfer Time

The formula for calculating IOPS (IO per second) is:
IOPS = 1000 ms/single IO time

Three-disk IOPS computing
What is the time required for different disks, such as track time, rotation latency, and data transmission?

1. Seek time
Considering that the read/write data may be stored in any track on the disk, it may be in either the inner ring of the disk (the shortest track time) or the outermost ring of the disk (the longest track time ), therefore, in calculation, we only consider the average seek time.

When purchasing a disk, this parameter indicates that the current SATA/SAS disk is at different speed and the seek time is different, but generally it is below 10 MS:

Speed

Average seek time

15000 rpm

2 ~ 3 ms

10000 rpm

3 ~ 5 ms

7200 rpm

8 ~ 9 ms

2. Rotation Delay
Like pathfinding, when the head of a Hong Kong server is located on the track, it may be located on top of the read/write sector. At this time, data can be read and written immediately without additional latency, however, in the worst case, the disk must be rotated for a full circle before the head can read data. Therefore, we also consider the average rotation latency. For 15000rpm of disks, the average rotation latency is (60 s/15000) * (1/2) = 2 ms.

3. Transfer Time
(1) disk transmission rate
The disk transmission Rate can be divided into two types: Internal transmission Rate (Internal Transfer Rate) and External transmission Rate (External Transfer Rate ).

The Internal transmission Rate refers to the data transmission Rate between the head and the hard disk cache. Simply put, the hard disk head reads data from the disk, then the speed stored in the cache.

The ideal internal transmission rate does not involve seek, and the rotation delay keeps reading data on the same track and passing it to the cache. Obviously, this is impossible because the storage space of a single track is limited;

The actual internal transmission rate includes seek and rotation latency. Currently, the stable internal transmission rate of a home disk is generally between 30 Mb/s and 45 Mb/s (the server disk should be higher ).

The External transmission Rate refers to the data transmission Rate between the hard disk cache and the system bus, that is, the speed at which the computer reads data from the cache to the corresponding hard disk controller through the hard disk interface.

Hard Disk manufacturers usually provide a maximum transmission rate in hard disk parameters. For example, if SATA3.0's 6 Gbit/s is used, the conversion is 6*1024/8, MB/s, it usually refers to the maximum external transmission rate of the hard disk interface. Of course, this value cannot be reached in actual use.

Here, IOPS is calculated, and the actual internal transmission rate is selected conservatively. Take 40 MB/s as an example.

(2) Size of a single IO operation
With the transfer rate, you must know the Size of a single IO operation (IO Chunk Size) to calculate the transfer time of a single IO. What is the size of a single disk IO? The answer is: Not sure.

The operating System introduces the File System Cache to improve IO performance. The System first caches multiple IO requests based on the request data, and then submit it to the disk at a time. That is to say, the read operations on multiple 8 K data blocks sent by the database may be processed in one disk read IO.

In addition, some storage systems also provide Cache. After receiving the IO requests from the operating system, they also combine the IO requests from multiple operating systems into one for processing.

There is only one purpose, either at the operating system level or at the disk controller level, to improve data read/write efficiency. Therefore, the size of each independent IO operation varies depending on the system's judgment on the data read/write efficiency. Take the data page size of the SQL Server database as an example: 8 K.

(3) Transfer Time
Transfer Time = IO Chunk Size/Internal Transfer Rate = 8 k/40 M/s = 0.2 ms

We can find that:
(3.1) if the Size of the IO Chunk is large, the transfer time will be longer, and the IO time will be longer at a time, resulting in reduced IOPS;
(3.2) The main read/write costs of mechanical disks are all spent on addressing time, that is, track time + rotation delay, that is, the swing of the disk arm and the rotation delay of the disk.
(3.3) If you roughly calculate IOPS, you can ignore the transfer time, 1000 ms/(seek time + rotation delay.

4. IOPS computing example
Take 15000rpm as an example:

(1) single IO time
Single IO time = seek time + rotation delay + transfer time = 3 ms + 2 ms + 0.2 ms = 5.2 ms

(2) IOPS
IOPS = 1000 ms/single IO time = 1000 ms/5.2 ms = 192 (times)
The Random Access IOPS of a single disk is calculated here.

In an extreme case, if all the disks are accessed sequentially, you can ignore the following: Seek time + rotation delay duration, and the IOPS formula is changed: IOPS = 1000 ms/Transfer Time
IOPS = 1000 ms/transfer time = 1000 ms/0.2 ms = 5000 (times)

Obviously, this extreme situation is too ideal. After all, the space of each track is limited, and the seek time + rotation delay duration can indeed be reduced, but it cannot be completely avoided.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.