Artificially modify server load in Ubuntu

I am curious if it is possible to artificially modify server loading in Ubuntu or, in general, linux. I am working on an application that responds to server load, and it would be nice to test it if I could easily change the server load.

I am currently launching an over-active program that will literally generate a load, but I would prefer not to continue to overheat my laptop (it gets hot!).

+6
source share
5 answers

Use chroot to run the various software components that you are testing with the specified directory as the root directory. Configure the created / modified / proc / loadavg with respect to this new root directory.

chroot will allow you to create a dummy file that appears to have / proc / loadavg as its path, so the software will keep track of your derived values, even if you cannot change your code to find the boot data elsewhere.

+2
source

One of the most important things you need to know about Linux (or Unix) systems is just the file. Since you are just reading from /proc/loadavg , the easiest way to accomplish what you need is to simply create a text file containing the line of text that you will see when you run cat /proc/loadavg . Then ask your program to read from this file, which you created instead of /proc/loadavg , and it will not be wiser. If you want to test in different "artificial" situations, just change the text in this file and save. When your testing is complete, just change your reading program from /proc/loadavg and you can be sure that it will work as expected.

Note that you can make this text file anywhere ... in your home directory, in the program directory, anywhere. However, you should not do this in /proc . This directory is reserved for system objects.

+6
source

You can use the stress command, see http://weather.ou.edu/~apw/projects/stress/

A tool for applying a load and stress test to a computer system.

 sudo apt-get install stress 

To avoid CPU heating, you can install a virtual machine with a small processor bandwidth. virtualbox and qemu-kvm are free.

+3
source

Since you do not want to actually / literally push the machine, something like stress is not what you are after.

As indicated, / proc / loadavg will be the place to set the average values โ€‹โ€‹of the system load (false loads).

But if this is also not what you need, I would absolutely suggest

getloadavg

watchdog

and maybe even Munin Plugins

0
source

There are two methods.

Hacking / proc / loadavg

  • The machine is not overstrained
  • Your program reads load valus from a file

Todo: hack Linux to report fake boot value

Change your prg

  • The machine is not overstrained
  • Your program reads load valus from a file

Todo: change 4 characters in your prg: replace / proc / loadavg with / tmp / loadavg

Now you can decide. Calculate costs;)

0
source

Source: https://habr.com/ru/post/910650/


All Articles