Linux Distros

How to Stress Test CPU in Manjaro

System administrators test the CPU to check its performance under a high level of stress and temperature. Other types of stress tests include memory, clock speed, workload, memory usage, and many others. CPU stress test utilizes all cores at their maximum capacity to thoroughly measure the processor’s performance.

This article explains the CPU stress test and discusses various reasons to stress test the CPU. Lastly, we demonstrate how to stress test the CPU using different tools in Manjaro Linux.

CPU Stress Test

A stress test is running an overclocked system to its maximum capacity to measure system stability. The components are deliberately checked under high levels of stress for a sustained period to verify reliability.

All central processing unit components are burdened by running them at maximum capacity and temperature for the CPU stress test. There are various reasons to stress test CPU in Manjaro; some of them are as follows:

  • To check how the CPU works under abnormal conditions.
  • To verify the reliability and stability of the newly bought system.
  • To check how Manjaro Linux works with the hardware platform at maximum CPU consumption to identify bugs and hardware failures.
  • To troubleshoot heat-related issues.

The main objective of CPU stress testing is to analyze system behavior after failure and if the systems display an error message under extreme conditions.

Stress Test Techniques

There are various ways and tools to stress test the CPU. We can utilize command-line tools as well as a text-based interface. In this article, we stress test CPU with the help of command-line utilities: stress and s-tui, and GUI.

Stress

stress is a command-line utility to generate workload by estimating the square root of any number in loops. It simultaneously loads all CPU cores that impose significant stress on the system. Besides, it also performs workload, disk, and memory stress on the system.

Use Manjaro Package manager Pacman to download stress:

[manjaro@manjaro ~]$ sudo pacman -S stress

After installation, use the getconf _NPROCESSORS_ONLN in the command-line terminal to identify the appropriate number of threads.

[manjaro@manjaro ~]$ getconf _NPROCESSORS_ONLN
4

To stress-test the CPU at the best of its capacity, the number must be the total number of cores and double if it supports hyperthreading. In this article, the stress test is performed on core i3 that supports hyper-threading, which implies number 6.

To begin, use the stress command with a –cpu flag and the number of threads to start.

[manjaro@manjaro ~]$ sudo stress --cpu 4
stress: info: [5183] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

In the meantime, run the top command to ensure 100% CPU utilization.

S-tui

S-tui is a front-end stress terminal user interface for the stress utility. It stress test cpu in real-time and exports the data in .csv format. It has a clean interface with smooth graph outlines.

The interface allows an in-depth view of the CPU performance. For instance, it displays all the sensors it can detect, i.e., CPU frequency, temperature, power, and utilization, as graphs relevant to each sensor value. It also displays the performance dips.

Use the pacman command to install s-tui, as follows:

[manjaro@manjaro ~]$ sudo pacman -S s-tui

The tool undoubtedly have the best monitoring functionality, but it also allows to add more options, for instance, to perform a stress test, install stress as follows:

[manjaro@manjaro ~]$ sudo pacman -S stress

Enter s-tui in the command-line terminal to launch the program. A text-based interface will appear. Use the arrow keys to change the mode of operation from monitor to stress.

The tool further allows to include additional options from the tool interface. For instance, it enables configuring “tension options” as a load level to stress test the CPU. Similarly, we can choose CPU cores; however, it is set to a maximum number of cores relevant to maximum load by default.

To save the data in CSV format, initiate the program with the following command.

[manjaro@manjaro ~]$ s-tui --csv

Use the ls command to list the content of the current working directory and cat the content of the .csv file.

[manjaro@manjaro ~]$ cat s-tui_log_2021-06-20_01_51_28.csv | less

Note: FIRESTARTER is another tool to stress test systems to their maximum capacity. s-tui allows integration of that utility as a submodule. However, it requires building s-tui from the source, and Firestarter isn’t compatible with all systems.

Yes Stress Test

Yes, the stress test is a way to troubleshoot intermittent problems under heavy load. All it requires is a yes command to utilize the CPU and its one core to 100%. The command repeatedly prints ‘y’ to the terminal until it’s terminated by pressing the Ctrl + C keys combination.

If the machine supports hyper-threading, it will create twice as many processes. For instance, use the following command for a single core machine and direct the output to /dev/null.

[manjaro@manjaro ~]$ yes > /dev/null

If you have two cores, use the above command in between & operator as follows:

[manjaro@manjaro ~]$ yes > /dev/null & yes > /dev/null

Similarly, keep on adding as per your requirement.

Or use the following one-line command to automate the process.

[manjaro@manjaro ~]$ for i in $(seq $(getconf _NPROCESSORS_ONLN)); do yes > /dev/null & done

The above command works as a for loop that takes a sequence of numbers from 1 to $(seq $(getconf _NPROCESSORS_ONLN)), where seq takes $(getconf _NPROCESSORS_ONLN) output as a sequence in the form of the total number of virtual cores.

We recommend monitoring the CPU using the top or htop command to verify its utilization up to 100%. Use the killall yes command to terminate yes processes.

Conclusion

The article demonstrated the use of various tools to test the CPU at its maximum capacity. The goal of CPU stress tests is to determine system resilience. Hence, it’s an appropriate skill for any beginner system administrator to learn and know system capacity.

About the author

Usama Azad

A security enthusiast who loves Terminal and Open Source. My area of expertise is Python, Linux (Debian), Bash, Penetration testing, and Firewalls. I’m born and raised in Wazirabad, Pakistan and currently doing Undergraduation from National University of Science and Technology (NUST). On Twitter i go by @UsamaAzad14