13

I would like to test fake load on the server, I'm looking for some burn-in or benchmark command line utility that would generate CPU load on the system.

I would like to be able to burn-in only CPU (no harddisk load, network and co) and that I would be able to set the period in which the load will run. Meaning I want something that would be able to run: CPU load for 10min on the system.

Any ideas?

Maxim Veksler
  • 2,555
  • 10
  • 27
  • 32

6 Answers6

12

You can download and install the "stress" utility... It allows you generate CPU, Memory, Disk and IO load from the command line.

Homepage: http://people.seas.harvard.edu/~apw/stress/

FAQ: http://people.seas.harvard.edu/~apw/stress/FAQ

ewwhite
  • 194,921
  • 91
  • 434
  • 799
7

I prefere floating point ops:

for i in `seq 64`; do perl -e '$z=time()+(10*60); while (time()<$z) { $j++; $sqrt = sqrt($j) for (1..9999); }' & done

Be aware of your CPU number :-)

3

This is something I frequently want to do. But I don't have a good way of doing it. I just write a small Perl script that will just loop for as many seconds as I want.

E.g. (for 10 minutes):

perl -e '$z=time()+(10*60); while (time()<$z) { $j++; $j *= 1.1 for (1..9999); }'

Of course if you have n processors you might want to add a bash loop to create that many processes:

#!/bin/bash
# e.g. for 4 processors
for i in 1 2 3 4; do
    perl -e .... &
done
wait
PP.
  • 3,246
  • 6
  • 26
  • 31
  • 4
    Minor point: Won't that `for` loop run them in series, rather than parallel? I think `(perl -e '...' &)` to detach them from the shell would do the job, though. – SmallClanger Dec 07 '10 at 09:36
  • You're right. I'll correct my post. Thanks for pointing that out. – PP. Dec 07 '10 at 15:02
1

I recommend using stress-ng, it has a lot more features than stress and can exercise far more of the operating system.

http://kernel.ubuntu.com/~cking/stress-ng/

Colin King
  • 21
  • 1
1

Here is a pure shell (at least bash & ksh) way that I already posted as a reply to a similar question here

# Usage: lc [number_of_cpus_to_load [number_of_seconds] ]
lc() {
  (
    pids=""
    cpus=${1:-1}
    seconds=${2:-60}
    echo loading $cpus CPUs for $seconds seconds
    trap 'for p in $pids; do kill $p; done' 0
    for ((i=0;i<cpus;i++)); do while : ; do : ; done & pids="$pids $!"; done
    sleep $seconds
  )
}
jlliagre
  • 8,691
  • 16
  • 36