How to Use ‘iotop’ to Measure the Speed of Data Reads/Writes on Storage Devices in Linux

How to Use IOTOP Utility for Storage I_O Performance Tests

In the world of Linux administration, monitoring system performance is crucial. One of the key aspects of system performance is Input/Output (I/O) operations, especially when it comes to storage devices. Whether you’re running a web server, a database, or any other application, the speed at which your system reads and writes data can significantly impact its overall performance.

There are several tools available for Linux to monitor I/O operations, but one of the most popular and comprehensive tools is iotop. This tool allows administrators to get a real-time view of disk I/O activity on a system. Whether you’re on a dedicated server, a VPS server, or even cloud hosting, monitoring storage I/O is essential.

In this tutorial, we will show how to use iotop to measure the speed of data reads/writes on storage devices.

Let’s get started.

Prerequisites

  • A Linux machine or server.
  • Root or sudo access to the machine.
  • `iotop` installed on the system. If not, we will cover the installation process.

Installing iotop

Before we can use iotop, we need to ensure it’s installed on our system.

For Debian/Ubuntu:

sudo apt update
sudo apt install iotop

For CentOS/Red Hat:

sudo yum install iotop

Using iotop

Once installed, you can start iotop by simply typing:

sudo iotop

This command will display a real-time view of I/O operations happening on your system. You’ll see columns for the process ID, user, disk read, disk write, swap, and command.

For example:

Total DISK READ: 0.00 B/s | Total DISK WRITE: 15.67 K/s
TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND
1234 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/u8:2]
5678 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/u8:0]
9012 be/4 root        0.00 B/s    3.91 K/s  0.00 %  0.00 % [jbd2/sda1-8]
3456 be/4 www-data    0.00 B/s   11.76 K/s  0.00 %  0.00 % apache2 -k start
7890 be/4 mysql       0.00 B/s    0.00 B/s  0.00 %  0.00 % mysqld

Here’s a breakdown of the output:

  • Total DISK READ: This shows the total read speed from all processes.
  • Total DISK WRITE: This shows the total write speed from all processes.
  • TID: This is the thread ID.
  • PRIO: This is the I/O priority of the process.
  • USER: This is the user running the process.
  • DISK READ: This shows the current read speed of the process.
  • DISK WRITE: This shows the current write speed of the process.
  • SWAPIN: This shows the percentage of time the thread spent while swapped out.
  • IO>: This shows the percentage of time the thread spent while waiting on I/O to complete.
  • COMMAND: This is the name of the command or process.
See also  How to Test a Web Server's Page Load Times in Linux

Interpreting the Output

The main columns to focus on are:

  • DISK READ – Shows the current read speed of a process.
  • DISK WRITE – Displays the current write speed of a process.
Total DISK READ: 0.00 B/s | Total DISK WRITE: 15.67 K/s
TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND
1234 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/u8:2]
5678 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/u8:0]
9012 be/4 root        0.00 B/s    3.91 K/s  0.00 %  0.00 % [jbd2/sda1-8]
3456 be/4 www-data    0.00 B/s   11.76 K/s  0.00 %  0.00 % apache2 -k start
7890 be/4 mysql       0.00 B/s    0.00 B/s  0.00 %  0.00 % mysqld

Interpretation:

  1. Total DISK READ: 0.00 B/s
    • The system is currently not reading any data from the storage devices. This means there’s no active data retrieval happening at this moment.
  2. Total DISK WRITE: 15.67 K/s
    • The system is writing data to the storage devices at a rate of 15.67 Kilobytes per second. This indicates there are active write operations occurring.
  3. TID 1234 & 5678 ([kworker/u8:2] & [kworker/u8:0])
    • These are kernel worker threads. They’re not reading or writing any data to the disk at this moment. Kernel worker threads handle background tasks within the Linux kernel.
  4. TID 9012 ([jbd2/sda1-8])
    • This is a journaling block device thread for the sda1 partition. It’s writing data at 3.91 Kilobytes per second. This process is responsible for journaling in the ext4 filesystem, ensuring data integrity.
  5. TID 3456 (apache2 -k start)
    • This is an Apache web server process. It’s writing data at a rate of 11.76 Kilobytes per second. This could be due to logging, caching, or other write operations related to web server activities.
  6. TID 7890 (mysqld)
    • This is a MySQL database server process. It’s currently not performing any read or write operations. This suggests that the database is either idle or processing tasks that don’t involve disk I/O at this exact moment.
  7. SWAPIN & IO> Columns
    • All processes have a 0.00% in the SWAPIN column, indicating that none of them are being swapped in from the swap space. This is a good sign as it means the system has enough RAM to handle the current tasks.
    • Similarly, all processes have a 0.00% in the IO> column, meaning they’re not waiting on I/O operations to complete. This suggests that the storage devices are responding promptly to requests.
See also  How to Setup Grafana to Monitor Server Uptime and Record Downtimes on Linux

Overall Impression: The system is in a relatively idle state regarding disk reads, but there are some write operations, primarily from the Apache web server and the ext4 filesystem’s journaling process. The system’s RAM is sufficient for the current workload, as no processes are being swapped in or out. The storage devices are also performing efficiently, with no processes waiting on I/O operations.

Commands Mentioned

  • sudo apt update – Updates the package list on Debian/Ubuntu systems.
  • sudo apt install iotop – Installs iotop on Debian/Ubuntu systems.
  • sudo yum install iotop – Installs iotop on CentOS/Red Hat systems.
  • sudo iotop – Starts the iotop tool to monitor I/O operations.

FAQ

  1. What is the main purpose of iotop?

    The primary purpose of `iotop` is to provide a real-time view of disk I/O activity on a Linux system. It allows administrators to monitor and identify processes that are reading or writing to the disk extensively, which can be useful for performance tuning and troubleshooting.

  2. How is iotop different from top?

    While both `iotop` and `top` are monitoring tools, `iotop` focuses specifically on disk I/O operations, displaying processes that are reading or writing to the disk. In contrast, `top` provides a general overview of system performance, including CPU and memory usage.

  3. Do I need root access to run iotop?

    Yes, to get a comprehensive view of all processes and their I/O operations, you need root or sudo privileges to run `iotop`.

  4. Can I filter the output of iotop?

    Yes, `iotop` comes with several command-line options that allow you to filter the output. For instance, using the `-o` or `–only` option will display only processes that are currently doing I/O operations.

  5. Is iotop available for all Linux distributions?

    `iotop` is widely available for most major Linux distributions. However, it’s always a good idea to check your distribution’s package manager or repository to ensure its availability.

See also  How to Setup Nmap to Perform a Security Vulnerability Test on a Linux Machine

Conclusion

Monitoring storage I/O performance is crucial for ensuring optimal system performance, especially for applications that heavily rely on disk operations. iotop is an invaluable tool for Linux administrators and webmasters, offering a real-time view of disk I/O activity. By understanding which processes are consuming the most I/O resources, you can make informed decisions about system tuning, application optimization, and infrastructure upgrades.

For those managing web servers, whether it’s Apache, Nginx, or LiteSpeed, iotop becomes an essential tool in the toolkit. It helps ensure that your server, whether it’s on a dedicated server, a VPS server, cloud hosting, or shared hosting, operates at peak performance.

Furthermore, as data-driven applications continue to grow in complexity and size, the importance of monitoring tools like iotop cannot be overstated. From databases to content management systems, the speed and efficiency of data reads/writes play a pivotal role in the overall user experience.

In conclusion, iotop is more than just a monitoring tool; it’s a window into the intricate operations of your Linux system. By leveraging its capabilities, you can ensure that your applications run smoothly, your servers respond quickly, and your storage devices maintain their longevity. As with any tool, the key is to use it regularly, understand its output, and take proactive measures based on the insights it provides. Whether you’re a seasoned Linux administrator or just starting out, make iotop a part of your regular system checks, and you’ll be well-equipped to handle the challenges of modern web hosting and server management.

Comments

Leave a Reply

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