Introduction
Load average in Linux measures the usage of system resources. Understanding this metric helps sysadmins identify and troubleshoot performance issues.
In this tutorial, you will learn what the Linux average load is, how to check it, and how to manage it to improve system performance.
What Is Linux Load Average?
Linux load average is a metric that shows the number of tasks currently executed by the CPU and tasks waiting in the queue.
Unlike CPU usage, which measures system performance at a specific point in time, the load average shows performance over a particular period. The number of processes running on the system changes constantly, and the load average displays that change.
The metric is expressed as the average number of processes in a runnable state over the last 1, 5, or 15 minutes. A higher load average indicates higher resource usage.
What Is a Normal Load Average for Linux?
A normal load average for Linux depends on the number of CPUs and cores the system has. Dual-CPU systems can handle more concurrent processes, resulting in a lower load average. However, if a system runs more processes than it has CPUs, the average load increases.
The number of cores also affects the load average. A high load average with a low number of cores indicates an overwhelmed system. On the other hand, a low load average with a high number of cores means that the system has spare capacity and is able to manage more processes. Generally, a load average of less than the number of CPU cores is normal, as it means there are enough resources for all processes to run smoothly.
For example, in a quad-core CPU system, a load average of less than 4 is normal. However, if the load average is consistently above the number of CPU cores, it indicates that the system is under a heavy load.
On the other hand, a load average of 0 doesn't mean the system is idle. It is possible the system runs background processes or tasks.
How to Check the Load Average in Linux?
Checking the load average in Linux helps users monitor performance and optimize the use of system resources. There are several ways to check the load average in Linux.
Note: Certain methods require sudo privileges.
Checking with the uptime Command
Use the uptime command to check the load average for the past 1, 5, and 15 minutes.
uptime
The output shows that the system has been running for 21 minutes since the last boot and that the number of active users is 1.
The load average for one user is:
- 0.79 for the past 1 minute.
- 0.32 for the past 5 minutes.
- 0.11 for the past 15 minutes.
The results are calculated by dividing the number of running and waiting processes by the number of available CPU cores.
Using the top Command
To get a real-time view of running processes, use the top (table of processes) command. This command provides information about the load average and the usage of other resources in the first line of output.
Check load average with:
top
Checking Load Average with cat
Another way to view the load average on a Linux system is by using the cat command. To print the load average in the first three columns, run the following:
cat /proc/loadavg
While the first three numbers show the load average, the last three represent:
- The number of currently running processes: 3.
- The total number of processes: 472.
- The ID of the most recently created process: 26767.
Check Load Average with w
The w command also prints the load average in the first line of output:
w
The first line shows info about currently logged-in users, including system time, uptime, number of users, and the average Linux load.
Using the glances Utility
glances
is a system monitoring tool for Linux that provides a detailed overview of resources. The utility works similarly to the top
command, displaying extensive system info.
Since glances does not come preinstalled on Linux, follow these steps to install and run it:
1. Update the repository with the following:
sudo apt update
2. Install the package with apt:
sudo apt install glances
3. Once the installation completes, execute:
glances
The command opens the glances
interface and prints various system information. The load average is in the top right corner.
How to Increase Load Average in Linux?
Increasing the load average on a Linux system can be detrimental as it makes the system work harder. However, in specific situations raising the load average is the desired result, such as when conducting system stress tests..
If you want to increase the load average in Linux, try one of the following methods:
- Increase the number of processes by running more applications or starting processes that use more resources.
- Optimize code or run processes in parallel to decrease the time each process takes to complete.
- Increase the number of concurrent users.
- Schedule more tasks to run automatically using a scheduler like cron.
- Run more CPU-intensive tasks, such as programs that perform mathematical calculations, encryption, or compression.
- Increase the number of threads a process uses to work.
How to Decrease Load Average in Linux?
Most Linux servers are designed to handle a load average lower than the number of CPU cores. However, the system may be under heavy stress if the load is higher.
To reduce the load average on a Linux system, first identify the source of the high load using tools like top
, htop
, and ps
.
Once the cause is identified, there are several ways to decrease the load average:
- Upgrade the system with a more capable CPU.
- Increase RAM to reduce swapping (moving data from the RAM to the hard drive) and improve system performance.
- Optimize running processes' performance by fine-tuning the configuration, reducing memory usage, or running tasks at a lower priority.
- Use a scheduler like cron,
anacron
, orat
to schedule background tasks to run at specific times, reducing the number of processes running simultaneously. - Use containerization technology, like Docker or Kubernetes, to isolate and manage processes.
- Kill unnecessary processes. Use the
top
orps
command to print a list of running processes and thekill
command to terminate them. - Limit the number of concurrent users or encourage them to use the system at different times.
Conclusion
After reading this article, you know what the average Linux load is and how it works. Next, learn how to check memory usage in Linux with these commands.