Why test the disk
The speed of the disk decides how quickly a database answers, how fast files load and how long backups take. A slow disk can be the reason why a server feels slow. Test when you buy a server, after a change, or when you see slow I/O.
hdparm: read speed
Install it:
sudo apt-get install hdparm
Test the read speed of a disk (replace sdX with your device, for example sda; find it with lsblk):
sudo hdparm -Tt /dev/sdX
-T tests the cache speed and -t tests the real read speed of the disk.
dd: simple read and write tests
Read test
dd if=/dev/sdX of=/dev/null bs=1M count=1000
if=/dev/sdXis the input (your disk).of=/dev/nullthrows the output away.bs=1Mis the block size.count=1000is the number of blocks (about 1 GB).
Write test. This writes a 1 GB file and measures the time. It is safe because it writes to a normal file and not to the device:
dd if=/dev/zero of=./testfile bs=1M count=1000 oflag=direct
rm ./testfile
/dev/sdX with of=. It destroys your data.fio: the flexible tester
fio can imitate real workloads (random or sequential, read or write).
Install it:
sudo apt-get install fio
Create a job file, for example test.fio:
[read_test]
rw=read
size=1G
directory=/path/to/test/directory
Run it:
fio test.fio
Change rw=read to write, randread or randwrite for other tests. The output shows bandwidth (MB/s) and IOPS.
ioping: latency
ioping measures how long a disk takes to answer.
sudo apt-get install ioping
sudo ioping -c 10 /path/to/test/directory
It sends 10 requests and shows the average latency.
How to read the results
- MB/s (bandwidth) matters for large files and backups.
- IOPS matters for databases and many small files.
- Latency matters for how quickly requests are answered.
An SSD or NVMe disk gives much better results than a hard disk. Run each test a few times, and when the server is quiet.
Quick recap
hdparm -Ttandddgive a fast check.fioandiopinggive a more detailed picture.- Never write to the raw device.