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.
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.
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 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
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