How Linux tests IO performance (disk read/write speed) __linux

Source: Internet
Author: User

MySQL performance test these days, a huge company, looking for a few performance testing machines are very tangled, finally coordinated to two, IO performance how do not know.
The database is an IO-intensive application, so let's evaluate the IO performance of the server below to see if it matches the machine on the line.

I've always known that the DD (device to Device) command allows you to simply test the disk's IO read and write speed, but not delve into it.
But this performance test of the relationship, need to get a relatively accurate value (before the test to eat this aspect of the deficit, insert a digression, performance testing must first confirm good test environment. )
The common way on the Internet is to use the Hdparm and DD commands to test, but the actual use of the problem, and the test results always feel biased, the heart is not bottom.
So the peace of mind to study the next two commands, but also done some testing and analysis, simple to do the summary.

Usage:
1. Test IO Read

Hdparm-t--direct/dev/sda3

Io reads the above command test, but hdparm this tool needs to be installed on its own, and it needs to be executed by the root user.

2. Test IO Write
Sync;/usr/bin/time-p bash-c "(dd If=/dev/zero of=test.dd bs=1000k count=20000;sync)"

The DD bs=1m count=20000 if=/dev/zero of=test.dd conv=fdatasync DD command test is an IO sequential write and read mode.

3. View File system block size

Tune2fs-l/dev/sda1 | grep block

The command line above is a bit more complex, and is explained in detail:
(1) The Sync command is used to flush the buffer of the file system, and the actual function of the Sync command is to write the buffer in memory to disk.
The next sync command is executed first to reduce the impact on the subsequent test. You can also use echo 3 >/proc/sys/vm/drop_caches to clear the cache.
(2) The time command is used to test the execution times of the command, and there is also a temporal command in the shell, where we use the full path to specify the use of a non-built-in command.
The-P option sets the output format of the time to the POSIX default time format, in seconds, where the Time-p output form is visible in the subsequent test section.
(3) The Bash command-C option is used to execute the subsequent string arguments as a bash script, seemingly superfluous, as if direct execution is possible,
Actually, because the following string contains two command lines, the time command needs to count the execution times of the two command lines.
(4) The parenthesis means another subprocess to execute the script in parentheses, DD This command line is not spoken here, do not know the words Baidu Bar.
The focus is on the sync command, because when DD exits, most of the content submitted by this command line is in the memory buffer (write cache), and even if the machine's memory is much larger than the data you submit,
That might be in memory, and then sync would be able to write the data in memory to disk, or it would be the write speed of the test memory, which is obviously not the result you want.


Test Practice:
Some tests were done on a memory 64g,sas hard drive.
In the testing process, you need to pay attention to two points, disk read and write speed and IO usage, we use IOPP and iostat tools to observe respectively.

Test Write Speed:
Test writes 20G data, the larger the amount of data, the more accurate the test value should be.
# sync;/usr/bin/time-p Bash-c "(dd If=/dev/zero of=test.dd bs=1m count=20000)"
20000+0 Records in
20000+0 Records out
Real 92.87
User 0.00
SYS 18.08

The time written to 20000M is 92.87s, so the disk writes at a 215.35mb/sec (20000m/92.87) speed.
Using Iostat observations, the%util is always in the state of 100%, while the DD command write speed shown by Iopp is basically the same as the computed value (the sampling time is set to 5s).
# iostat-x 5
device:rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await SVCTM%util
SDA 0.00 0.00 0.20 864.00 1.60 449004.80 519.56 143.61 163.46 1.16 100.00

# Iopp-i-K 5
PID Rchar wchar syscr syscw rkb wkb command
32566 1033216 1033216 0 0 0 1034868 0 DD

Note: The current working directory on the command line is on the partition/dev/sda3, so test.dd This file is also created on this partition, and the following read test will use this file.

Test Read speed:
Make a comparison of DD and hdparm:

# hdparm-t--direct/dev/sda3
/dev/sda3:
Timing o_direct disk reads:2108 MB in 3.00 seconds = 702.34 mb/sec

The test result of hdparm is 3s read 2108MB, read speed is 702.34MB.

Because the Hdparm test time is too short, iostat and iopp sampling times are adjusted to 1s.

Iostat-x 1
device:rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await SVCTM%util
SDA 0.00 0.00 2752.00 1.00 1409024.00 8.00 511.82 4.64 1.69 0.35 96.10

Iopp-i-K 1
PID Rchar wchar syscr syscw rkb wkb command
32349 733184 0 0 0 733184 0 0 hdparm

Read Test using DD
# echo 3 >/proc/sys/vm/drop_caches; /USR/BIN/TIME-P DD if=test.dd of=/dev/null bs=1m
20000+0 Records in
20000+0 Records out
Real 35.69
User 0.00
SYS 9.81

Read 20G, read speed to 560.38mb/sec.

Reads are faster than writes, and the sampling time for Iostat and Iopp is adjusted to 3s.
device:rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await SVCTM%util
SDA 106.67 0.00 5851.00 0.33 1434256.00 2.67 245.12 1.62 0.28 0.16 93.60

PID Rchar wchar syscr syscw rkb wkb command
17004 1449984 1449984 1 1 1450760 0 0 DD

Conclusion:

There is a difference between the read speed and the hdparm of the DD test,
Set the block size test by the BS option (default 512 bytes, test using 1M)
It can be seen that the speed measured by DD is related to the size of the read-write block, and may also be affected by the process of having IO read and write in the system.
Hdparm's testing principle did not do in-depth research, it may be different from the DD test method, need to know this.

Overall, the actual test speed of Io is influenced by a number of factors, including the way of reading and writing (random or sequential, hdparm and DD tests are all sequential reads and writes), caching mechanisms, sampling of tests, and so on.
So it is not likely to get a certain value (the same command line multiple tests are not the same, but the difference is smaller), the above method of reading the test or recommend the use of hdparm.
Although the above data is biased, it can still roughly analyze the IO performance of the machine. It just needs to be clear what kind of environment these test values are obtained.

Friendship Link:

FIO Test iops:http://elf8848.iteye.com/blog/2168876

DD Test io:http://www.askoracle.org/linux/disk/968.html

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.