Each process running on the server does some work or, as we'll call it in the topic further, produces some load on the CPU. In other words, a system load is a number of such processes running or waiting in a queue for execution. If the server's resources become insufficient, problems can occur.
In order to make sure that your programs are not waiting in the queue for the execution, running slower, or even freezing, you need to keep an eye on the processor load. Also, you'll need to review such important info as user number, current time, system uptime since startup, the number of tasks, and so on.
There are several utilities in Linux for this kind of monitoring. Below we will analyze three of them: uptime, htop, and top. Also, we will describe what the load average is in more detail.
Load average
System load average is the average number of processes that are either in a runnable or uninterruptible state.
Load average shows up as the three averages for 1, 5, and 15 minutes. They look like three positive fractional numbers, for example, 1.4, 1.7, and 1.9. Generally, the lower the numbers are, the better the state of the system is.
However, in order to more accurately understand what the three numbers mean, you need to know the number of cores, since the average load depends on it.
Each core is a kind of queue in which processes are located. If there are too many processes or they overload the CPU, the waiting time for them will start to increase, as well as the load average. If, for example, you have only one core, then you have only one queue and its maximum will be 1 for the whole system. Then values like 1.4, 1.7, and 1.9 will mean that it's overloaded since there is no more space in the queue. And a value less than 1, for example, 0.5, will mean that the queue is half full and you do not have any reason to be worried.
In the case of two cores, the full load for the whole system will be 2, and the overload will start when the numbers become larger than two. For 4 cores the maximum will be 4, for eight cores 8, and so on. If the load average is 0, it means there are no processes at all.
If your disk is running slowly, the load average might also be high, although the CPU load will be low.
Okay, now you know about the load average so let's move to commands.
Uptime
Uptime command can help you to find out the operating time of the system, the number of currently logged-in users, and the load average of the system for the last 1, 5, and 15 minutes.
The command syntax is as follows: type uptime in your terminal. The result will be like the one below:
$ uptime
18:28:05 up 3:53, 1 user, load average: 1.87, 1.54, 1.12
Here you see the current time, system uptime since startup, the number of users, and the load average, 1, 5, and 15 minutes correspondingly.
There are also additional uptime options. If you want to know more about them, you may use the -h help option.
So, with this command, you can quickly check the load average and the time and the number of users. However, this information is not always sufficient. You can learn more about the operation of the system using the top and htop commands, which we will analyze below.
Top
The top command allows you to display information about the system, as well as a list of processes, i.e. tasks, dynamically updating information about the resources they consume.
To run the command, type top in your terminal and the result will be like the one below:
In addition to the parameters that we've studied above, you can also see the information about:
- Tasks — the total number of running processes in different statuses (running, sleeping — waiting, stopped, and "zombies", which are child processes waiting for the parent process to collect their exit statuses);
- Cpu (s) — the percentage of CPU (central processing unit) time spent executing processes;
- Mem, Swap — information about the use of RAM (total, free memory, used memory).
You can also find on the screenshot a list of processes. The processes with the highest CPU load will be at the top of the list.
The top command also has many additional options. If you'd like to explore them, use the -h to display the utility's help.
Htop
Htop utility is one of the top analogues that you may choose. The main difference is that it shows the percentage of loading for each processor core separately. The rest of the output is almost identical to the output of the top command. This utility may not be preinstalled on your system. In this case do not forget to install it with your package manager.
To run the command, write htop in the terminal and the result will look something like this:
In this example, the processor has 4 cores and right to each core you can see the percentage of workload. On the right there are the number of tasks and threads, average load, and uptime.
Thread is a part of the process, a single sequence stream within the process. Processes can have one or multiple threads.
Also, you can see a list of processes sorted by processor load, from highest to lowest as in the top output above.
In order to get thorough help with the command and its additional settings, use the F1 key.
Conclusion
So, we've figured out that in order to find out if your system has enough processor power you can use one of these utilities: uptime, htop, and top. In addition, you will find information about user number, current time, and system uptime since startup. Also, the last two commands provide more detailed and real-time information about the processes.