I'm doing some testing on a Linux server and I need the server to be on a heavy load. I was wondering how I would simulate this? Right now the server goes upto 20% CPU but I need to force it to around 80% and do some testing to see how it copes.
Asked
Active
Viewed 5,488 times
2 Answers
12
If you want to force CPU's occupation, try this :
for cpu in 1 2 ; do
( while true; do true; done ) &
done
If you want to simualte IO charge too, try with this :
for cpu in 1 2 ; do
( while true; do find / -type f -exec cp {} /dev/null \; ; done ) &
done
with for cpu in 1 2
for 2 cores, for cpu in 1 2 3 4
for 4 cores ;)

Cédric Julien
- 78,516
- 15
- 127
- 132
-
I'm guessing this does some searching or something in dev/null ? – unleashed May 19 '11 at 09:28
-
1the `find` command with those arguments are copying every file in the filesystem to `/dev/null`, so generating a lot of IO as @Cédric said. – Carlos Campderrós May 19 '11 at 09:37
-
Certainly works although i'm abit worried with the copying of files to /dev/null. The files don't actually get permanently stored in /dev/null right? – unleashed May 19 '11 at 09:47
-
1@unleashed no, `/dev/null` is some kind of black-hole or sink. Anything you store in there just disappears, and does not use a single byte of your hard disk space. – Carlos Campderrós May 19 '11 at 09:54
-
find generates a lot of file system i/o. But @unleashed like to know, how to rise the CPU usage much as possible. So don't use filesystem-components for that, because the CPU generates filesystem-wait-i/o which is not the same as CPU usage. – The Bndr May 19 '11 at 12:58
-
@The Bndr : my first loop burn only CPU, my second loop burn IO (if your filesystem are in a RAMFS, it will burn some CPU too), if you want to burn CPU and IO, launch the 2 loops in parallel ;) – Cédric Julien May 19 '11 at 13:01
-
@Cédric Julien Sorry, I did an mistake be reading your post. So: everything is fine. Sorry. :-) – The Bndr May 19 '11 at 13:18
-
To kill them, use `kill %1 %2`, replacing the numbers with the ones printed at the beginning of the lines when starting the jobs. – l0b0 Apr 07 '14 at 10:18
-
Copying a file to /dev/null overwrites /dev/null. – Felipe Alvarez Jun 16 '16 at 22:50
2
If you are looking for generating cpu usage, so you have to choose commands, which are CPU intensive. For example generation random-numbers.
Try this:
dd if=/dev/urandom of=/dev/null
Add on of those line for every CPU core. If you have an dual-core CPU use:
dd if=/dev/urandom of=/dev/null &
dd if=/dev/urandom of=/dev/null &
Check the jobs with
jobs
End the jobs with
kill %1
(where %1 is the number of job 1)

The Bndr
- 13,204
- 16
- 68
- 107