This topic explains how to use the iostat and iotop tools to check I/O load.
Check disk I/O load
Use iostat to check disk I/O load
The iostat command is used for monitoring I/O performance in the Linux operating system. It generates reports to check disk I/O load from the system perspective.
Run the following command to install iostat:
yum install sysstat
Run the following command to check I/O load:
iostat -d -k 3 5
Note-d: displays the utilization report of the device (disk).
-k: displays statistics in KB as the unit.
3: The data display is refreshed every 3 seconds.
5: displays 5 reports.
The output displays as below.
The displaying parameters are explained as follows. For more information, see iostat(1) - Linux man page.
Device: The disk name.
tps: The number of I/O requests sent per second.
Blk_read/s: The number of blocks read per second.
Blk_wrtn/s: The number of blocks written per second.
Blk_read: The total number of blocks read.
Blk_wrtn: The total number of blocks written.
Use iotop to check disk I/O load
The iotop is a Linux command. It is a top-like utility for monitoring disk I/O usage. We can use it to check disk I/O load from the process perspective.
Run the following command to install iotop:
yum install iotop
Run the following command to check I/O load:
iotop -k -n 5 -d 3
Note-b: records to log.
-k: displays in KB as the unit.
-n: indicates the number of iterations before ending.
-d: indicates the delay between iterations.
The output displays as below.
The displaying parameters are explained as follows. For more information, run
iotop -h
query.DISK READ: displays the current read speed of the process.
DISK WRITE: displays the current write speed of the process.
SWAPIN: displays the swap utilization of the disk.
IO: displays the utilization of the process, including disk and swap.
The kjournald process occupies lots of I/O resources.
Problem description
Use iotop to troubleshoot and analyze the issue that the kjournald process occupies a large amount of I /O resources.
Cause
This issue is usually caused by the Journal size of the .ext3
file system that is set too small.
The kjournald process is the core process of the ext3 file system, which is responsible for handling I/O data operations. It consumes CPU and memory resources during disks read and write activities. When it writes data to the ext3 file system repeatedly, the Journal size is continuously increasing. This issue occurs when the journal reaches its maximum size.
Solution
Connect to a Linux Elastic Compute Service (ECS) instance.
For more information, see Connection method overview.
Run the following command to check the Journal size of the corresponding partition:
dumpe2fs /dev/xvda1 | grep Journal
NoteReplace /dev/xvda1 with your actual partition.
The system displays similar to the following, indicating that the Journal size of the
/dev/xvda1
partition is 128M.dumpe2fs 1.42.9 (28-Dec-2013) Journal inode: 8 Journal backup: inode blocks Journal features: journal_incompat_revoke Journal size: 128M Journal length: 32768 Journal sequence: 0x00010ffb Journal start: 10953
Run the following command to change the Journal size:
mke2fs -J size=400 /dev/xvda1
NoteModify the size as needed, and replace /dev/xvda1 with your actual partition.
I/O performance optimization: Improve I/O performance with 4K alignment
4K alignment refers to formatting a hard disk that conforms to the 4K sector definition and writing data according to the 4K sector rule. 4K alignment can make clusters correspond to sectors, ensuring disk read and write efficiency to improve I/O performance.
This section describes how to format a disk and automatically configure 4K alignment through the following script.
Running this script automatically formats all data disks. If it is not a newly purchased data disk, make sure that the data on the disk has been backed up. For more information, see Create a snapshot for a disk.
Use the root user to connect to the Linux ECS instance.
For more information, see Connection method overview.
Download the auto_fdisk.zip package, extract it, and upload the extracted script to the target server.
Run the following commands in sequence to add the execute permissions on the script and run the script:
chmod +x ./auto_fdisk.sh ./auto_fdisk.sh