CPU Stressing

To bypass the idle compute identification bu oracle we need to have the CPU, Memory and Network cross a certain level of utilization (as of writing this document it was 20%). One of the way to achieve this is using a stress-ng ands supervisor to control its operation.

Install stress-ng and supervisor

sudo apt install supervisor stress-ng

The command below will put 15% load on each of the 4 CPUs available, we can tweak the numbers below as we wish to meet our requirements.

sudo stress-ng --cpu 4 --cpu-load 15

Now this command will only work till the command prompt is functional, to make it work consinuously and even after reboots we need to use supervisor

First we need to create a config file for supervisor

sudo nano /etc/supervisor/conf.d/stress.conf

Copy and paste the following config to your “stress.conf” this is just and example make sure to tweak it to meet your requirements. The config below will create two programs “cpu_stress” and “memory_stress” the two programs will run the two “strass-ng” commands we ran above simultaneously, it will auto start them on boot and auto-restart them if they get crash or get killed.

[program:cpu_stress]
command=/usr/bin/stress-ng --cpu 4 --cpu-load 15 
directory=/usr/bin/
user=root
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/stress.log

[program:memory_stress]
command=/usr/bin/stress-ng --vm 1 --vm-bytes 15%% --vm-hang 0
directory=/usr/bin/
user=root
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/stress.log

First Start the supervisor services using below command

sudo service supervisor start

To get supervisor to start the two program we have we first need to reload the configuration file we do that by running the following command. Run the command below anytime you make changes to this config file or create new file!

sudo sypervisorctl reread

Next we can go ahead and reload the “supervisorctl” to start the two programs.

sudo supervisorctl reload

You can check the status of the programs by running

sudo supervisorctl status

You can stop a specific program by executing

sudo supervisorctl stop memory_stress

This program will restart on a reboot so you need to edit to config file and disable autostart=true

Last updated