A script that can perform stress tests according to the number of CPU cores

Introduction

When trying to stress test a CPU in a Linux environment, I think the easiest way is yes> / dev / null.

However, this command has a weakness, and when the number of CPU cores is 2 or more, after executing multiple processes at the same time, the kill command will forcibly stop the process. [Linux] How to easily apply CPU load without using stress command

Therefore, the ʻopenssl` command introduced in I tried to summarize how to easily apply CPU load on Linux Using it, I made a script that can execute the stress test of the CPU considering the number of logical cores (number of threads) of the CPU.

Created script

#!/bin/bash

function usage {
    cat <<EOS
$(basename ${0}) is a cpu stress test tool for multi-core processor.
Usage:
    $(basename ${0}) [<options>]
Options:
    -n    using n cores in stress test. default is `grep processor /proc/cpuinfo | wc -l`.
EOS
}

CPU_THREADS=`grep processor /proc/cpuinfo | wc -l`

while getopts n:h OPT
do
  case $OPT in
    "n" ) CPU_THREADS="$OPTARG"
          ;;
    "h" ) usage;
          exit 0
          ;;
  esac
done

echo "using "$CPU_THREADS" cores in stress test."
openssl speed -multi $CPU_THREADS > /dev/null 2>&1

How to use

Command options


[root@akagi ~]# ./cpu_stress_test.sh -h
cpu_stress_test.sh is a cpu stress test tool for multi-core processor.

Usage:
    cpu_stress_test.sh [<options>]

Options:
    -n    using n cores in stress test. default is 8.

Run CPU stress test


[root@akagi ~]# ./cpu_stress_test.sh -n 2
using 2 cores in stress test.

Reference URL

Recommended Posts

A script that can perform stress tests according to the number of CPU cores
[Python] A program to find the number of apples and oranges that can be harvested
A script that returns 0, 1 attached to the first Python prime number
[Python] A program that calculates the number of socks to be paired
Output the number of CPU cores in Python
[Python] A program that counts the number of valleys
A python script that gets the number of jobs for a specified condition from indeed.com
Command to check the total number of CPU physical cores / logical cores / physical memory on Mac
A Python script that compares the contents of two directories
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
[Note] A shell script that checks the CPU usage of a specific process in a while loop.
A Python script that allows you to check the status of the server from your browser
[Python] A program that finds the maximum number of toys that can be purchased with your money
[python] A note that started to understand the behavior of matplotlib.pyplot
[Python] A program that rotates the contents of the list to the left
Create a bot that posts the number of people positive for the new coronavirus in Tokyo to Slack
A story about creating a program that will increase the number of Instagram followers from 0 to 700 in a week
[Python] A program that calculates the number of chocolate segments that meet the conditions
How to put a line number at the beginning of a CSV file
How to create a wrapper that preserves the signature of the function to wrap
How to play a video while watching the number of frames (Mac)
Script to change the description of fasta
Set the number of elements in a NumPy one-dimensional array to a power of 2 (0 padded)
The story of IPv6 address that I want to keep at a minimum
How to count the number of elements in Django and output to a template
Create a BOT that displays the number of infected people in the new corona
Use twitter API to get the number of tweets related to a certain keyword
I wrote a script to revive the gulp watch that will die soon
[Python] A program that calculates the number of updates of the highest and lowest records
Python script to get a list of input examples for the AtCoder contest
I made a script to record the active window using win32gui of Python
How to make a Raspberry Pi that speaks the tweets of the specified user
Upload a large number of images to Wordpress
Python tricks: a combination of enumerate () and zip (), checking if a string can be converted to a number, sorting the string as a number
Find the number of days in a month
A python script that generates a sample dataset for checking the operation of a classification tree
[Curse of dimensionality] If the number of sensors is changed to ∞, can anomaly be detected?
A script that combines margins when pasting a number of graphs on tiles with gnuplot
[Ansible] Example of playbook that adds a character string to the first line of the file
[Python] A program that finds the shortest number of steps in a game that crosses clouds
The story of Linux that I want to teach myself half a year ago
How to create a property of relations that can be prefetch_related by specific conditions
Find a guideline for the number of processes / threads to set in the application server
Try to create a waveform (audio spectrum) that moves according to the sound with python
A script that pings the registered server and sends an email with Gmail a certain number of times when it fails
python beginners tried to predict the number of criminals
A story that reduces the effort of operation / maintenance
How to know the port number of the xinetd service
A script that takes a snapshot of an EBS volume
Template of python script to read the contents of the file
How to get the number of digits in Python
A memo to visually understand the axis of pandas.Panel
# Function that returns the character code of a string
Try to estimate the number of likes on Twitter
Steps to calculate the likelihood of a normal distribution
A script that outputs a list of SoftLayer portal users
Generate that shape of the bottom of a PET bottle
Script to get the expiration date of the SSL certificate
A story that analyzed the delivery of Nico Nama.
Automatically select BGM according to the content of the conversation
[Python] A program that compares the positions of kangaroos.