Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Artificially modify server load in Ubuntu

Tags:

linux

ubuntu

load

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

I am currently running an over-active program that will literally generate load, but I'd prefer to not continue overheating my laptop (it's getting hot!).

like image 665
GoldenNewby Avatar asked Mar 14 '12 00:03

GoldenNewby


People also ask

Is Ubuntu Server free for commercial use?

Ubuntu is freely available to all users for personal, or in the case of organisations, internal use.

What can I do with my Ubuntu server?

Ubuntu Server is a server operating system, developed by Canonical and open source programmers around the world, that works with nearly any hardware or virtualization platform. It can serve up websites, file shares, and containers, as well as expand your company offerings with an incredible cloud presence.

Can you use Ubuntu desktop as a Server?

Furthermore, you can utilize any Ubuntu Desktop as a Ubuntu Server by setting up the server software. Choose Ubuntu Server over the Desktop version if you want to operate your Server headless. You can always have the option to install a GUI later because these two Ubuntu variants share the same kernel.


3 Answers

One of the most important things to know about Linux (or Unix) systems is, everything is just a file. Since you are just reading from /proc/loadavg, the easiest was for you to accomplish what you are after is simply make a text file that contains a line of text that you would see when running cat /proc/loadavg. Then have your program read from that file you created instead of /proc/loadavg and it will be none the wiser. If you want to test under different "artificial" situations, just change the text in this file and save. When your testing is done, simply change your program back to reading from /proc/loadavg and you can be sure it will work as expected.

Note, you can make this text file anywhere you want...in your home directory, in the program directory, wherever. However, you shouldn't make it in /proc. That directory is reserved for system objects.

like image 114
austin1howard Avatar answered Sep 18 '22 20:09

austin1howard


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

A tool to impose load on and stress test a computer system

sudo apt-get install stress

To avoid CPU warm, you can install a virtual machine with small cpu capacity. virtualbox and qemu-kvm are free.

like image 26
Gilles Quenot Avatar answered Sep 19 '22 20:09

Gilles Quenot


Use chroot to run the various pieces of software you're testing with a specified directory as the root directory. Set up a manufactured/modified /proc/loadavg relative to that new root directory, too.

chroot will let you create a dummy file that appears to have /proc/loadavg as its path, so the software will observe your manufactured values even if you can't change your code to look for load data in a different location.

like image 25
inquiryqueue Avatar answered Sep 18 '22 20:09

inquiryqueue