Linux hard disk Performance Detection and linux hard disk Detection
For today's computers, the performance of the entire computer is mainly affected by the disk I/O speed, and the speed of memory, CPU, and motherboard bus has become very fast.
Basic detection method 1. dd command
The dd command function is very simple. It reads data from a source and writes it to a destination address in bit-level form. In this way, we can detect the read/write performance of our actual disk in linux, data is read without any detection software. In general, dd is used to detect the disk performance, which is considered to be the closest to the actual situation.
Usage: dd if [Where to read data, generally from the zero device under dev, this device continuously returns 0 as the data source] of [file to which the Read File is written] bs [block size, size of each read/write speed] count [total number of bs read/write operations] conv = fdatasync [There is a strong memory cache mechanism in linux. to improve system performance, linux uses a large amount of memory as the hard disk read/write cache, so this parameter is used to ensure that data is directly written to the hard disk]
Example:
dd if=/dev/zero of=testfile bs=1M count=512 conv=fdatasync
The result on my VM is as follows:
[root@localhost ~]# dd if=/dev/zero of=testfile bs=1M count=512 conv=fdatasync512+0 records in512+0 records out536870912 bytes (537 MB) copied, 19.6677 s, 27.3 MB/s
We recommend that you run this command multiple times to get the average value. Before executing the preceding command, we recommend that you use the following command to clear the cache:
echo 3 > /proc/sys/vm/drop_caches
Dd command testing is often not rigorous or scientific, because it may be affected by cpu usage and background services.
2. hdparm command
The hdparm command is used to obtain and modify the test disk information. Hdparm must be run as an administrator.
Usage: hdparm-t disk to be tested
Example:
# hdparm -t /dev/sda
Result:
[root@localhost ~]# hdparm -t /dev/sda/dev/sda: Timing buffered disk reads: 444 MB in 3.01 seconds = 147.35 MB/sec[root@localhost ~]# hdparm -t /dev/sda/dev/sda: Timing buffered disk reads: 808 MB in 3.00 seconds = 269.21 MB/sec
We can see that there is a large gap between the two running results. Therefore, we recommend that you take the average value for multiple running times.
The results of these two tests are very simple. When you test disk performance professionally, you not only need to know the read/write performance, the size of read/write data (4 k/16 k/32 k) should also be distinguished, and sequential read/write or random read/write should also be tested. If it is a mechanical hard disk, the speed gap between the inner and external magnetic channels should also be tested.
Advanced detection method 1, bonnie ++
You can install it using yum (not included in the default yum source of linux. We recommend that you install the repoforge source ):
yum install -y bonnie++
Usage: bonnie ++-u username-s to test the size of the read/write File
Example:
bonnie++ -u root -s 2g
By default, a 4G file is written, which is divided into four parts. The system IO is fully tested by random read/write operations. because the size of the file to be written is large, it takes a long time.
Result:
[root@localhost ~]# bonnie++ -u root -s 2gUsing uid:0, gid:0.Writing a byte at a time...doneWriting intelligently...doneRewriting...doneReading a byte at a time...doneReading intelligently...donestart 'em...done...done...done...done...done...Create files in sequential order...done.Stat files in sequential order...done.Delete files in sequential order...done.Create files in random order...done.Stat files in random order...done.Delete files in random order...done.Version 1.96 ------Sequential Output------ --Sequential Input- --Random-Concurrency 1 -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CPlocalhost.locald 2G 287 99 31885 20 59035 15 2795 99 514292 64 9491 421Latency 42230us 2804ms 284ms 8198us 5820us 4819usVersion 1.96 ------Sequential Create------ --------Random Create--------localhost.localdoma -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete-- files /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP 16 20946 92 +++++ +++ +++++ +++ 23169 94 +++++ +++ +++++ +++Latency 2539us 853us 993us 1675us 284us 1234us1.96,1.96,localhost.localdomain,1,1414376948,2G,,287,99,31885,20,59035,15,2795,99,514292,64,9491,421,16,,,,,20946,92,+++++,+++,+++++,+++,23169,94,+++++,+++,+++++,+++,42230us,2804ms,284ms,8198us,5820us,4819us,2539us,853us,993us,1675us,284us,1234us
This format is a bit messy, but fortunately this software also provides a tool to convert the result into an html table (using the last line for conversion ):
echo 1.96,1.96,localhost.localdomain,1,1414376948,2G,,287,99,31885,20,59035,15,2795,99,514292,64,9491,421,16,,,,,20946,92,+++++,+++,+++++,+++,23169,94,+++++,+++,+++++,+++,42230us,2804ms,284ms,8198us,5820us,4819us,2539us,853us,993us,1675us,284us,1234us | bon_csv2html >> bon_result.html
Bon_result.html is displayed as follows:
This is much more interesting. A brief explanation is as follows:
The Per Char in Sequential Output (Sequential Output is actually a write operation) is written in putc mode, because the cache line is always greater than 1 byte, therefore, we constantly harass the CPU and execute putc. We can see that the cpu usage is 99%. the write speed is 0.3 MB/s, which is very slow.
The block in Sequential Output is written according to the block. Obviously, the CPU usage is reduced and the speed is up, which is 31 MB/s, which is similar to the previous dd test.
In Sequential Input (Sequential Input, actually a read operation), Per Char refers to reading files using getc. The speed is 2.5 MB/s and the CPU usage is 99%.
The block in Sequential Input refers to reading files by block. The speed is 50 MB/s, And the CPU usage is 64%.
Random Seeks are Random addressing, and addressing more than 9000 times per second is acceptable.
Sequential Create (Sequential file creation)
Random Create (Random file creation)
Some results are many + numbers, which means bonner ++ considers the value unreliable, so it does not output. Generally, this is because the execution is fast and is generally not a system bottleneck, so don't worry.
2. iozone
Iozone provides more comprehensive and accurate information, so iozone is one of the most useful tools in system performance testing.
Iozone usage is slightly complicated. Here we only use the most common parameters:
-L: the minimum number of processes for concurrent testing. If you do not want to test multiple processes, you can set it to 1.
-U: the maximum number of processes used for concurrent testing. If you do not want to test multiple processes, you can set it to 1.
-R: The default basic read/write unit, such as 16 k. This value is generally related to the test application. To test the database, this value is consistent with the block size of the database.
-S: the default read/write size. It is recommended that this value be larger (usually twice the memory size), because iozone does not circumvent the lower-layer cache, so if the value is small, it may be completed directly in the memory.
-F: Specifies the cached file.
Example:
iozone -l 1 -u 1 -r 16k -s 2g -F tempfile
Result:
Children see throughput for 1 initial writers = 31884.46 kB/secParent sees throughput for 1 initial writers = 30305.05 kB/secMin throughput per process = 31884.46 kB/sec Max throughput per process = 31884.46 kB/secAvg throughput per process = 31884.46 kB/secMin xfer = 2097152.00 kBChildren see throughput for 1 rewriters = 102810.49 kB/secParent sees throughput for 1 rewriters = 95660.98 kB/secMin throughput per process = 102810.49 kB/sec Max throughput per process = 102810.49 kB/secAvg throughput per process = 102810.49 kB/secMin xfer = 2097152.00 kBChildren see throughput for 1 readers = 450193.59 kB/secParent sees throughput for 1 readers = 450076.28 kB/secMin throughput per process = 450193.59 kB/sec Max throughput per process = 450193.59 kB/secAvg throughput per process = 450193.59 kB/secMin xfer = 2097152.00 kBChildren see throughput for 1 re-readers = 451833.53 kB/secParent sees throughput for 1 re-readers = 451756.47 kB/secMin throughput per process = 451833.53 kB/sec Max throughput per process = 451833.53 kB/secAvg throughput per process = 451833.53 kB/secMin xfer = 2097152.00 kBChildren see throughput for 1 reverse readers = 61854.02 kB/secParent sees throughput for 1 reverse readers = 61851.88 kB/secMin throughput per process = 61854.02 kB/sec Max throughput per process = 61854.02 kB/secAvg throughput per process = 61854.02 kB/secMin xfer = 2097152.00 kBChildren see throughput for 1 stride readers = 43441.66 kB/secParent sees throughput for 1 stride readers = 43439.83 kB/secMin throughput per process = 43441.66 kB/sec Max throughput per process = 43441.66 kB/secAvg throughput per process = 43441.66 kB/secMin xfer = 2097152.00 kBChildren see throughput for 1 random readers = 47707.72 kB/secParent sees throughput for 1 random readers = 47705.00 kB/secMin throughput per process = 47707.72 kB/sec Max throughput per process = 47707.72 kB/secAvg throughput per process = 47707.72 kB/secMin xfer = 2097152.00 kBChildren see throughput for 1 mixed workload = 50807.69 kB/secParent sees throughput for 1 mixed workload = 50806.24 kB/secMin throughput per process = 50807.69 kB/sec Max throughput per process = 50807.69 kB/secAvg throughput per process = 50807.69 kB/secMin xfer = 2097152.00 kBChildren see throughput for 1 random writers = 45131.93 kB/secParent sees throughput for 1 random writers = 43955.32 kB/secMin throughput per process = 45131.93 kB/sec Max throughput per process = 45131.93 kB/secAvg throughput per process = 45131.93 kB/secMin xfer = 2097152.00 kB
From the above results, we can see the read/write performance of the system disk in various ways.
PS: Actually, there are still results, but my VM disk is full and crashes.
References
1. Linux Hard Drive Performance Detection
2. Learn about how to use bonnie ++ to test disk performance.
How can I check the Linux system?
When using the network, we need to monitor the Linux system: CPU load, memory consumption, disk space in several specified directories, disk I/O, and swap are also the network traffic. Today, Shanghai Express network introduces how to obtain Linux system performance monitoring parameters.
There are actually many performance testing tools in Linux.
Mrtg is a good choice. However, mrtg is required to install sysstat, apache, snmp, perl, and other things. It may take several steps to install the SDK. I also wanted to directly call the commands such as sar and vmstat, And the parse would just calculate the result. Which knows that the results of linux commands of different versions are also different. Since the results of version parse are required, it is better to calculate them directly in the system. So I studied the source code of sysstat and gkrellm and found the data for monitoring performance.
1. CPU
The file "/proc/stat" contains CPU information. Every CPU tick is used in this file. The following numbers indicate user, nice, sys, idle, and iowait. Some versions of kernel do not include iowait. These values indicate where each tick of the CPU is used from the boot to the present.
That is, 256279030 tick is used for user consumption since CPU 0 is started, and 11832528 is used for sys consumption. So if you want to calculate the CPU load per unit time (for example, 1 s), you only need to calculate the difference between the values before and after 1 second by the number of tick per second.
2. memory consumption
The file "/proc/meminfo" contains the memory information and swap information.
3. Disk Space
From the source code of gkrellm, this is a very complex data.
4. Disk I/O
Disk I/O data is also complex. For some versions, see/proc/diskstats, for some versions, see/proc/partitions, and for some versions, I still don't know where to view them ...... However, we can see that the data version is also the same as the CPU, which requires a value every other time. The difference between the two values is the traffic.
5. Network Traffic
Network traffic is also varied, but it can basically be obtained in/proc/net/dev. It also requires two values to take the difference as the traffic value.
Reference: Shanghai Express Network
What is the command for testing the read/write speed of a single hard disk on a linux server?
C cainiao assistant member tonytvb answers your questions (if you have any questions, please hi or ask my team ):
Function Description: displays and sets hard disk parameters.
Syntax: hdparm [-partition hiiqttvyyz] [-a <cache partition>] [-A <0 or 1>] [-c] [-d <0 or 1>] [-k <0 or 1>] [-K <0 or 1>] [-m <Number of partitions>] [-n <0 or 1>] [-p] [-P <Number of partitions >] [-r <0 or 1>] [-S <time>] [-u <0 or 1>] [-W <0 or 1>] [-X <transmission Mode>] [device]
Note: hdparm can be detected to display and set the parameters of the IDE or SCSI hard disk.
Test the reading speed of each hard disk to determine whether the hard disk is faulty
Run the following command in the server command window:
Hdparm-t/dev/hda (IDE Hard Drive)
Hdparm-t/dev/sda (SATA, SCSI, hard RAID card array)
Hdparm-t/dev/md0 (soft RAID device)
The test results should be greater than 40 M/s under no-load conditions, and the test results should be equal to> 20 M/s under load conditions. If the test results are extremely low, you need to use a dedicated hard disk detection tool to test whether the disk is faulty.
Parameters:
-A <cache partition> sets the number of partitions that are pre-stored in the block area when the file is read. If the <cache partition> option is not added, the current setting is displayed.
-A <0 or 1> enables or disables the cache function when reading files.
-C: sets the IDE32-bit I/O mode.
-C: detects the power management mode of the IDE hard disk.
-D <0 or 1> sets the DMA mode of the disk.
-F writes the data in the memory buffer to the hard disk and clarifies the buffer.
-G: displays the disk's magnetic track, Head, magnetic area, and other parameters.
-H: displays help.
-I displays the hardware specification information of the hard disk, which is provided by the hard disk itself at startup.
-I directly reads the hardware specification information provided by the hard disk.
-K <0 or 1> to reset the hard disk, retain the-dmu parameter settings.
-K <0 or 1> to reset the hard disk, retain the-APSWXZ parameter settings.
-M <number of magnetic partitions> sets the number of partitions accessed by multiple hard disk partitions.
-N <0 or 1> indicates an error that occurs when the hard disk is written.
-P: Set the PIO mode of the hard disk.
-P <number of magnetic partitions> sets the number of partitions in the cache of the hard disk.
-When executing subsequent parameters, q does not display any information on the screen.
-R <0 or 1> sets the read/write mode of the hard disk.
-S <time> sets the waiting time before the hard disk enters power-saving mode.
-T to evaluate the Read efficiency of the hard disk.
-T the reading efficiency of the flat hard disk cache.
-U <0 or 1> allows other interruption requests to be executed simultaneously during hard disk access.
-V displays the hard disk settings.
-W <0 or 1> sets the hard disk write cache.
-X <transmission mode> sets the transmission mode of the hard disk.
-Y enables the IDE hard drive to power-saving mode.
-Y: Enable the IDE hard drive to sleep.
-Z: Disable Automatic power saving for some Seagate hard disks .... Remaining full text>