5 Linux commands for locating system slowdowns fast
It's a rare occasion that my Linux desktop slows down. That's not to say it never happens, as that would be a lie. Most often, when a system slowdown occurs, I can usually trace it back to a specific application (often VirtualBox is the culprit). I have, however, experienced problems that were caused by hard drive bottlenecks.
Also: The first 5 Linux commands every new user should learn
Let's take a look at how you can track down hardware-related bottlenecks with a few commands.
1. iostat
This command reports CPU statistics and I/O (Input/Output) statistics for both devices and partitions. With iostat, you can monitor device loading by monitoring the time a device is active in relation to average transfer rates. This command generates reports that can be used to help you configure your system for optimal performance. With iostat, there are three metrics you should consider a priority:
- %util - How much time a disk was busy handling requests. If the number is over 80%, chances are good you're dealing with a bottleneck.
- await - The average time for an I/O request to complete. If the value is high, you're dealing with a disk that is either too slow or suffering from a problem.
- svctm - The average service time for I/O requests. If the value is high, it means the disk is taking too long to respond.
One thing to keep in mind is that iostat lists all devices (including loopbacks). The devices you want to look for are most likely of the nvme, sdX, and zram type (where X is a letter).
Also: 5 best Linux commands for troubleshooting problems (and how I use them)
The iostat might not be installed on your system by default. If not, you can install the sysstat application with a command like:
- Ubuntu-based distributions - sudo apt-get install sysstat -y
- Fedora-based distribution - sudo dnf install sysstat -y
2. iotop
The iotop command is similar to iostat but instead of generating static reports, it reports in real-time. Iotop is similar to the top command; the difference is that top displays statistics about software and services, whereas iotop displays processes and disk activity. If you spot a process that is using excessive system resources, that's probably your problem.
The iotop application does have to be run with sudo privileges. When run, you'll see columns for TID, PRIO, User, Disk Read, Disk Write, SwapIn, IO Priority, and Command. The three most important bits of information to check for are Disk Read, Disk Write, and IO Priority. If you find any processes with a high Read or Write value, there's your problem. At the same time, if you spot something using a large number of I/O resources (IO Priority), you'll want to adjust the priority of that process using the ionice command (for setting or getting process I/O scheduling class and priority).
To install iotop on either Ubuntu or Fedora-based distributions, the commands would be:
sudo apt-get install iotop -y sudo dnf install iotop -y
3. dstat
The dstat command is another method of monitoring how system resources are being used, especially disk I/O. The dstat command is almost like a combination of iotop and iostat, in that it reports as much information as iostat but does it in real-time like iotop. The most important details to check for would be Disk Read/Write (if there's consistently heavy activity, that could be your problem) and Disk Await (how long individual I/O operations take to complete. A high number indicates a bottleneck).
You can install dstat on Ubuntu or Fedora-based distributions with the commands:
sudo apt-get install dstat -y sudo dnf install dstat -y
One handy little trick is to use a limit on what dstat reports are. For example, if you only care to view CPU stats, issue the command:
dstat -c
If you only want to view disk statistics, issue the command:
dstat -d
4. sar
The sar command is also installed along with sysstat and collects, reports, and saves information regarding system activity. The sar command is a bit more complicated than the above commands because you have to use options. For example, if you want to view three sets of CPU statistics with two seconds between polls, the command would be:
sar -u 2 3
The above command would print out three sets of CPU statistics and then a fourth for the average. The output includes the following:
- CPU - the number of the CPU core being tested (the default is all).
- %User - the percentage of time an application is run at the user level.
- %Nice - the percentage of time an application is run at the user level with nice priority.
- %system - the percentage of time it takes for system-level processes to execute.
- %iowait - the percentage of time a CPU is idle with a pending disk I/O request.
- %steal - the percentage of time a virtual CPU was idle due to the host servicing a different VM.
- %idle - the percentage of time a CPU is idle without a pending I/O request.
If you suspect a specific core to be a problem, you can always test them by number, like so:
sar -P 1 2 3
The -P option is followed by the core number you want to test.
5. smartctl
If you want to check the health of your hard drives, the smartctl command is what you want to use. There are two particular bits of information in a smartclt report to look out for:
- Reallocated_Sector_Ct - the number of sectors that have been reallocated because of errors. If the number is high, the drive could be failing.
- Seek_Error_Rate - if the value is high, the drive could be having trouble locating specific information, which could be a sign of damage.
And there you have it… five commands to help you find bottleneck issues on your Linux system. Make sure you read more about these commands with the help of man (i.e. man smarctl, man sar, man dstat, man iotop, and man iostat).