Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to simulate CPU usage 1

Status
Not open for further replies.

gallows

Technical User
Jun 12, 2004
223
US
Anyone have a script or any idea of how to put a load on the system to force the cpu to 100%? Actually, anything over 80% will do:))

I am in the process of limiting Oracle to 79% max cpu utilization and need a way to test it.

Thanks,
gallows
 
I have used gzip to do this in the past. Find some very large files (preferably binary, not text) and gzip them with the switches "[tt]-9v[/tt]". This will do the most agressive compression, which will require the most CPU. Something like...
Code:
gzip -9v giantfile1.dat &
gzip -9v giantfile2.dat &
gzip -9v giantfile3.dat &
gzip -9v giantfile4.dat &
gzip -9v giantfile5.dat &
wait
That will put five in the background running simultaneously. The amount of CPU used will depend on a lot of things, but you should be able to get what you are looking for by using different files of different types.

Another thing, gzip will be hitting the disk to do the compressing, so the IO waits will reduce the amount of CPU generated. If you move the big files to [tt]/tmp[/tt] and compress them from there, it will reduce the IO impact. On Solaris [tt]/tmp[/tt] uses swap. If you have a dedicated swap partition, it doesn't do through the file system and the IOs are much faster. Thus more CPU usage generated. It's a tiny amount, but every little bit helps when you are trying to load the system.

I've also seen graphics conversion programs used to generate CPU.

 
I found this on the net. On the plus side, it does generate 100% CPU. On the negative side, it also does that by creating MANY processes. This could swamp your process table, or have other consequences that you don't want. Still, give it a try as it might give you what you need.
Code:
#!/usr/bin/perl

print "Eating the CPUs\n";

foreach $i (1..64) {
$pid = fork();
last if $pid == 0;
print "Created PID $pid\n";
}

while (1) {
$x++;
}


 
This gets close to eating one full CPU in a single Korn shell process...
Code:
#!/bin/ksh

typeset -i NUMBER=0

while (( 1 ))
do
        (( NUMBER += RANDOM ))
        (( NUMBER %= 71 ))
        (( NUMBER *= 7 ))
        (( NUMBER /= 3 ))
done
Just run more than one for multiple CPUs.


 
Hey thanks alot SamBones!! Much appreciated. I will try them all. I've got a test system so don't care what I do to it:))

Gallows
 
This is always a good one;

dd if=/dev/zero of=/dev/null bs=1024 count=104857600

Generates 100gb worth of zeroes and then gets rid of them.
This stresses the cpu without affecting disk or memory.

Run it a few times consecutively and watch your cpu usage fly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top