Posted inTutorial

Checking I/O Performance on Linux

I/O (Input/Output) performance is a critical aspect of system administration and optimization. In Linux, various tools can help you measure and analyze disk I/O performance, which is crucial for diagnosing system bottlenecks and ensuring optimal performance. Here, we will explore some of the most effective command-line tools for checking I/O speed on a Linux system.

1. Using dd

The dd command is a versatile utility that can be used to measure disk read and write speeds. It copies data from one location to another, making it useful for benchmarking.

Measure Write Speed

To measure the write speed, you can use the following command:

dd if=/dev/zero of=testfile bs=1G count=1 oflag=direct
  • if=/dev/zero specifies the input file, a source of null bytes.
  • of=testfile specifies the output file where the data will be written.
  • bs=1G sets the block size to 1 gigabyte.
  • count=1 specifies the number of blocks.
  • oflag=direct ensures that the data is written directly to the disk, bypassing the cache.

Measure Read Speed

To measure the read speed, you can use the following command:

dd if=testfile of=/dev/null bs=1G count=1 iflag=direct
  • if=testfile specifies the input file, the same file written in the previous test.
  • of=/dev/null discards the output data.
  • iflag=direct ensures that the data is read directly from the disk, bypassing the cache.

2. Using hdparm

The hdparm command is used primarily for configuring and displaying the properties of SATA and IDE devices. It can also measure disk read speed.

Measure Read Speed

To measure the read speed, use the following command:

sudo hdparm -t /dev/sdX
  • Replace /dev/sdX with the appropriate device identifier (e.g., /dev/sda).

 

3. Using fio

The fio (Flexible I/O Tester) tool is a powerful and flexible benchmarking tool that can simulate various I/O workloads. It can be installed via your package manager (sudo apt-get install fio on Debian-based systems).

Measure Write Speed

Create a configuration file or run fio with command-line arguments. Here’s an example:

 

fio --name=write_test --size=1G --filesize=1G --filename=testfile --bs=1M --nrfiles=1 --direct=1 --sync=0 --randrepeat=0 --iodepth=1 --rw=write
  • --name=write_test sets the job name.
  • --size=1G sets the size of the data.
  • --filesize=1G specifies the file size.
  • --filename=testfile specifies the file to be written.
  • --bs=1M sets the block size to 1 megabyte.
  • --nrfiles=1 specifies the number of files.
  • --direct=1 ensures direct I/O.
  • --sync=0 disables sync I/O.
  • --randrepeat=0 ensures randomness.
  • --iodepth=1 sets the I/O depth.
  • --rw=write sets the operation to write.

 

4. Using ioping

The ioping tool is used for monitoring I/O latency in real-time. It can be installed via your package manager (sudo apt-get install ioping on Debian-based systems).

Measure Latency

To measure I/O latency, use the following command:

ioping -c 10 .
  • -c 10 specifies the number of I/O operations.
  • . indicates the current directory.

Example Outputs

dd

$ dd if=/dev/zero of=testfile bs=1G count=1 oflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 2.87757 s, 373 MB/s

hdparm

$ sudo hdparm -t /dev/sda
/dev/sda:
Timing buffered disk reads: 160 MB in 3.00 seconds = 53.31 MB/sec

fio

$ fio --name=write_test --size=1G --filesize=1G --filename=testfile --bs=1M --nrfiles=1 --direct=1 --sync=0 --randrepeat=0 --iodepth=1 --rw=write
write_test: (g=0): rw=write, bs=(R) 1.0MiB-1.0MiB, (W) 1.0MiB-1.0MiB, (T) 1.0MiB-1.0MiB, ioengine=sync, iodepth=1
fio-3.16
Starting 1 process
Jobs: 1 (f=1): [W(1)][100.0%][w=951MiB/s][w=951 IOPS][eta 00m:00s]
write_test: (groupid=0, jobs=1): err= 0: pid=31601: Tue Jun 1 14:32:34 2021
write: IOPS=921, BW=921MiB/s (966MB/s)(1024MiB/1112msec); 0 zone resets
clat (nsec): min=860, max=39209, avg=1076.78, stdev=417.22
lat (usec): min=4, max=39, avg=10.16, stdev= 1.57
clat percentiles (nsec):
| 1.00th=[ 880], 5.00th=[ 928], 10.00th=[ 944], 20.00th=[ 976],
| 30.00th=[ 992], 40.00th=[ 1008], 50.00th=[ 1024], 60.00th=[ 1040],
| 70.00th=[ 1056], 80.00th=[ 1072], 90.00th=[ 1088], 95.00th=[ 1104],
| 99.00th=[ 1168], 99.50th=[ 1376], 99.90th=[ 8032], 99.95th=[12800],
| 99.99th=[22848]
bw ( KiB/s): min=942080, max=942080, per=100.00%, avg=942080.00, stdev= 0.00, samples=1
iops : min= 920, max= 920, avg= 920.00, stdev= 0.00, samples=1
lat (nsec) : 1000=0.03%
lat (usec) : 2=0.03%, 4=0.03%, 10=75.00%, 20=24.93%, 50=0.03%
cpu : usr=0.63%, sys=15.61%, ctx=1048, majf=0, minf=2
IO depths : 1=1.0%, 2=99.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=99.0%, 8=1.0%, 16=0.0%, 32=0.0%, >=64=0.0%
complete : 0=0.0%, 4=99.0%, 8=1.0%, 16=0.0%, 32=0.0%, >=64=0.0%
issued rwts: total=0,1024,0,0 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1

ioping

$ ioping -c 10 .
4 KiB from . (ext4 /dev/sda1): request=1 time=202 us
4 KiB from . (ext4 /dev/sda1): request=2 time=300 us
4 KiB from . (ext4 /dev/sda1): request=3 time=410 us
4 KiB from . (ext4 /dev/sda1): request=4 time=203 us
4 KiB from . (ext4 /dev/sda1): request=5 time=190 us
4 KiB from . (ext4 /dev/sda1): request=6 time=188 us
4 KiB from . (ext4 /dev/sda1): request=7 time=235 us
4 KiB from . (ext4 /dev/sda1): request=8 time=194 us
4 KiB from . (ext4 /dev/sda1): request=9 time=315 us
4 KiB from . (ext4 /dev/sda1): request=10 time=189 us

--- . (ext4 /dev/sda1) ioping statistics ---
10 requests completed in 1.0038 s, 3.91 k iops, 15.3 MiB/s
min/avg/max/mdev = 188 us / 242 us / 410 us / 72 us

Conclusion

Monitoring and analyzing I/O performance is crucial for maintaining and optimizing your Linux system. Tools like dd, hdparm, fio, and ioping provide powerful ways to measure various aspects of I/O performance, helping you identify and address potential bottlenecks. By regularly checking I/O speed, you can ensure that your system operates efficiently and effectively.

Leave a Reply

Your email address will not be published. Required fields are marked *