Easy way to load CPU / memory on Linux

Today's goal

After building a server, learn an easy way to generate a load with only standard Linux functions when performing a load test of Linux resources.

Easily apply CPU load

It's better to use standard Linux commands instead of using a commonly known tool such as "stress".

I can't easily install tools in a production environment. I picked up a method that does not modify the environment as much as possible.

use the yes command

The yes command is a built-in command included in the OS standard. It is a method to put a CPU load by repeatedly hitting this yes command.

Process with the yes command

# yes > /dev/null

Please be careful about the direction of the redirect. To stop the process, press "Ctrl + C".

It doesn't take a lot of load if it is one, so you can start multiple terminals and hit the yes command repeatedly.

# yes > /dev/null &
# yes > /dev/null &
# yes > /dev/null &
# yes > /dev/null &
# yes > /dev/null &

If you want to stop it, check "jobs" and


# jobs
[1]Running yes> /dev/null &
[2]Running yes> /dev/null &
[3]Running yes> /dev/null &
[4]Running yes> /dev/null &
[5]Running yes> /dev/null &
[6]-Running yes> /dev/null &
[7]+Running yes> /dev/null &

Stop with the following feeling

# kill %1 %2 %3
[1]Finished yes> /dev/null
[2]-Finished yes> /dev/null
[3]+Finished yes> /dev/null

Use the openssl command

Use the openssl command to load the CPU according to the number of CPU clocks.

openssl command processing execution example

[root@localhost ~]# openssl speed -multi `grep processor /proc/cpuinfo|wc -l`
Forked child 0
+DT:md2:3:16
+R:256480:md2:3.000000
+DT:md2:3:64
+R:133412:md2:3.000000
+DT:md2:3:256
+R:94141:md2:3.000000
+DT:md2:3:1024
+R:26955:md2:3.000000
+DT:md2:3:8192
+R:3545:md2:3.000000
+DT:md4:3:16
+R:16046421:md4:3.000000
+DT:md4:3:64

"Ctrl + C" to stop the processing with the openssl command

How to generate memory load

Create a dummy shell script.

# vi test-memory.sh

Describe the process that consumes 500MB of memory each time you press Enter as follows

python


#! /bin/bash
# "--bytest 5000000" is 500MB.
echo PID=$$
echo -n "[ Enter : powerup! ] , [ Ctrl+d : stop ]"
c=0
while read byte; do
   eval a$c'=$(head --bytes 5000000 /dev/zero |cat -v)'
   c=$(($c+1))
   echo -n ">"
done
echo

Execute the created script.

# chmod +x test-memory.sh
# ./test-memory.sh

Each time you press Enter, it consumes 500MB of memory. If you want to stop it, press Ctrl + d.

I think there are many ways to put a CPU load other than those listed above, but if you don't think about it to a certain extent, you may destroy the environment itself, so be careful about that!

Recommended Posts

Easy way to load CPU / memory on Linux
Easy copy to clipboard on Linux
Easy way to use Python 2.7 on Cent OS 6
Easy df command on Linux
Easy way to rename files
A relatively easy way to insert a NEologd dictionary on Windows-System Dictionary
Easy way to customize Python import
How to install VMware-Tools on Linux
How to install aws-session-manager-plugin on Manajro Linux
I want to use Linux on mac
How to update php on Amazon linux 2
Easy way to use Wikipedia in Python
Upgraded mysql on Cloud9 (Amazon Linux) (5.5 to 5,7)
How to install packages on Alpine Linux
5 reasons to install Linux on your laptop.
How to install Anisble on Amazon Linux 2
How to update security on CentOS Linux 8
How to install php7.4 on Linux (Ubuntu)
On Ubuntu Linux, set Tab to q
How to find large files on Linux
Gusto cannot connect to Wifi on Linux
Easy script migration from CentOS to Oracle Linux
Easy way to plot HR diagram using astroquery
Deliver OBS footage to Zoom on Arch Linux
Introduction to Python with Atom (on the way)
Try to create a new command on linux
How to install Camunda Modeler on Manjaro Linux
I want to log file I / O on Linux
How to build Java environment on Ubuntu (Linux)
[Small story] Easy way to convert Jupyter to PDF
An easy way to call Java from Python
An easy way to measure the processing speed of a disk recognized by Linux
An easy way to pad the number with zeros depending on the number of digits [Python]
[Linux] Introduction to Linux
Command to check the total number of CPU physical cores / logical cores / physical memory on Mac
Linux (command memory)
Easy way to check the source of Python modules
How to "cache enabled" access to FPGA memory from Linux
Install Grub on USB memory (UEFI) ~ Boot Linux from grub on USB memory ~
Take your own peak memory usage on Linux & Python
Very easy to install SciPy on Mac OS X
Yum command to access MySQL with Python 3 on Linux
How to install Linux on a 32bit UEFI PC
Easy way to scrape with python using Google Colab
An easy way to create an import module with jupyter
How to allow nologin users to log in on Linux
How to run Self bot on Discord.py [Easy vandalism! ]
Preparing to use Ansible on an existing Linux server
I want to use OpenJDK 11 on Ubuntu Linux 18.04 LTS / 18.10
[AWS EC2] How to install Maven on Amazon Linux 2
How to install git on Linux such as EC2
[Tips] How to use iPhone as webcam on Linux
How to build a Python environment on amazon linux 2
[AWS] How to expand disk space on Amazon linux
Even beginners can do it! An easy way to write a Sankey Diagram on Plotly