How to measure read and write speed of a disk in Linux ?
There are many monitoring tools available to measure disk read or write speed.
However suppose if we have slow disk performance and want to measure the disk read/write speed manually to confirm the disk fault, we can use below trick to identify the disk performance.
1. Identifying the disk read speed.
To identify disk read speed, we have two command available:
a. dd
b. hdparm
Using hdparm command:
[root@nglinux ~]# hdparm --direct -Tt /dev/sda1 /dev/sda1: Timing O_DIRECT cached reads: 580 MB in 2.00 seconds = 289.51 MB/sec Timing O_DIRECT disk reads: 296 MB in 3.00 seconds = 98.65 MB/sec [root@nglinux ~]#
Here hdparm command we have used below options:
–direct Use O_DIRECT to bypass page cache for exact read timings.
-t Perform device read timings
-T Perform cache read timings
And in the result we can see the disk reads are at speed 98.65MB/s and cached space read speed is 289.51MB/s.
Using dd command:
### First flush cache to get accurate read timings. [root@nglinux ~]# echo 3 > /proc/sys/vm/drop_caches ### Now run below command with some big file to identify exact read speed. [root@nglinux ~]# dd if=./test_img.img of=/dev/null bs=128K 82875+1 records in 82875+1 records out 10862710784 bytes (11 GB) copied, 57.6384 s, 188 MB/s [root@nglinux ~]#
So the actual disk read time is 188MB/s.
2. Checking disk write speed.
[root@nglinux ~]# dd if=/dev/zero of=./test_img.img bs=500M oflag=dsync dd: writing `./test_img.img': No space left on device 21+0 records in 20+0 records out 10862710784 bytes (11 GB) copied, 112.433 s, 96.6 MB/s [root@nglinux ~]#
Hence from above result, we can conclude the disk write speed is around 96MB/second and disk read speed is 188MB/s.
Most of the times low values does not confirm that we are using slow/faulted hardware. The value can be less because of the HARDWARE RAID controller’s cache.
Please do add your comments/tips here.