Stress Test Your Ubuntu Computer with ‘Stress’

Sometimes, stress testing a computer can be a very useful thing. For example, if you have a faulty hardware, say a hard disk drive that is having performance issues, then you can run disk I/O intensive tests to see whether it is stable or not.

Or, if you have just overclocked your hardware (CPU, GPU, RAM …) and want to make sure that it won’t make your computer unstable, before applying those changes permanently, then stress testing is among the best ways of knowing that also (or for evaluating the capability of your PC in general).

Stress testing can also be used to benchmark certain software applications, such as an I/O scheduler or a task scheduler (for instance) as well.

Anyway, if you use Ubuntu and prefer a tool with a GUI, then you can use ‘lbench’. It has a simple user interface and very easy to use, and is primarily a benchmarking tool. But, if you are okay with using the command-line, then you can also try ‘Stress’.

It lets you put stress on your:

*. CPU

*. RAM

*. Disk Drive (only supports write tests).

It can not stress other hardware such as the GPU though. You can also delay the starting of the stress tests and make it automatically exit after running for a certain amount of time (in seconds) as well.

Remember, ‘Stress’ is not actually a benchmarking utility, as it does not give you any speed related outputs (like ‘lbench’ does), but is only a utility that lets you stress your computer. Still, you can use it as a work load generator, for while benchmarking other utilities, such as an I/O scheduler, as mentioned above too.

If interested, you can install it in Ubuntu 12.10 Quantal Quetzal, 13.04, 12.04 Precise Pangolin, 11.10, 10.10 and 10.04 by using the below command in your Terminal window.

sudo apt-get install stress

How to use it?

You can use ‘Stress’ to stress the above mentioned hardware individually or you can stress them all at the same time too.

Stressing the CPU

If you want only to stress the CPU, then you can use it in the below format (on your Terminal window, of course).

stress -c 1

Depending on the type of your CPU, make sure to replace ‘1‘ accordingly. For example, if you have a CPU with four cores and would like to stress them all, then you should be using the below command.

stress -c 4

You can also enter a number, higher than the available CPU cores for adding a lot more stress on the CPU as well. In other words, if I put 50 individual processes to stress my CPU (‘stress -c 50‘), rather than using 4 processes, it will make the OS more unstable.

Note: You can cancel (exit) ‘Stress’ anytime by pressing ‘Ctrl’ + ‘c’ keys or by closing the Terminal window.

Stressing the Memory (RAM)

Let’s say that I wanted to stress my 4GB RAM module using three processes, with each about 256MiB in size (by default). Then I’ll use the below command.

stress -m 3

You can again replace ‘3‘ with the number of processes to be used, plus, can also change the size of the processes by using the ‘--vm-bytes …’ attribute.

So if I wanted to use 4 process with each sizing around 300MiB, then I’ll use the below command.

stress -m 4 --vm-bytes 300M

Note: However, for stressing your RAM, the CPU also has to do a lot of work as well. And as a result, if the used processes were more or equal to the available cores, then they will use 100% of your CPU power.

Stressing the Disk Drive

If you want to stress the disk drive only, then use the below command.

stress -d 1

1‘ represents the number of processes that will be used to stress your disk drive. Again, you can replace this number accordingly. By default, ‘Stress’ uses 1GB file size for each process (you use the ‘--hdd-bytes’ argument for changing that), so make sure your have enough free space left before running this test.

For stressing my HDD with 2 processes, with each sizing around 512MB, I can use the below command.

stress -d 2 --hdd-bytes 512M

Note: Unlike with the RAM stress test, HDD stress test does not require a lot of CPU usages.

Stressing CPU, RAM and HDD simultaneously

If I wanted to stress the CPU, RAM and the HDD at the same time, then I can use it in the below format.

stress -c 4 -m 2 -d 1

As you can see, in this instance, ‘Stress’ will stress the CPU using four processes, RAM will be stressed using 2 processes (each sizing around 256MiB) and the disk will be stressed with a process that is about 1GB in size.

Setting up a timeout

‘Stress’ also lets you run these tests for a chosen time frame. Let’s say that I wanted to run the above test, only for 40 seconds, then I’ll simply add the ‘-t’ argument and the new command will look like the below one.

stress -c 4 -m 2 -d 1 -t 40s

After running for 40 seconds, it will exit automatically.

You can also use the ‘-t’ argument while running other individual tests as well. Its manual contains all these details. You can use the below command for reading it.

man stress

But please remember that, stressing your hardware unnecessarily is not recommended as it can easily damage them. So use it only, when it is absolutely necessary.

10 thoughts on “Stress Test Your Ubuntu Computer with ‘Stress’

  1. Is there any way to load CPU with 75% or 50%? I mange to load 25% by adding some usleep into code but cant get 75% of CPU load.

    • Hi Pista,

      I’m not sure if that is possible. But if your CPU has 4 or more cores, then as I mentioned in the article, it is possible to stress each individually and get a similar effect using the below command.

      stress -c 1

      Replace ‘1’ with the number of cores that you want to stress. You can also have a look into its manual for more information.

      info stress

  2. Hi Gayan,

    I am new to linux, want to try learn it, bought a cheap second hand intel core2 dell, with 3 gig ram, and 160g HDD, I want to stress the system to check if machine is ok, like not overheating.

    What would be a nice stress that I could run for a long period to monitor it?



    • Hi Henry,

      You could use the below command which will consume 50% of your total CPU power (assuming that your CPU has two cores), 1500MiB of your RAM and will stress your HDD with 4 processess (100MB each).

      stress -c 1 -m 3 --vm-bytes 500M -d 4 --hdd-bytes 100M

      You can also add the ‘-t’ option to execute it for a given time-frame (in seconds) as well. For instance, if you want to execute the above ‘stress’ custom profile for about 3 minutes, then you should use it as below:

      stress -c 1 -m 3 --vm-bytes 500M -d 4 --hdd-bytes 100M -t 180s

      Feel free to change the arguments to suite your needs (increase the number of CPU cores that should be involved if you have more than two, for instance) but try not to be too aggressive… good luck.

  3. Is it possible to write the output of these commands to file? or is it possible to run these with vmstat etc simultaneously?
    or do i need to run the stress and compare vmstat before and after stress?

    • Hi Paul,

      Sorry about the late response. And yes, you can write the output of ‘stress’ to a file and run ‘vmstat’ while running ‘stress’ as well. The command would look something like the below one…:

      stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 30s >> stress_output.txt & watch -d -n 1 vmstat

      If you want the output of ‘stress’ to include more information, then you can include the ‘-v’ option as well:

      stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M -v --timeout 30s >> stress_output.txt & watch -d -n 1 vmstat

      Hope this helps.

  4. Hi!

    One quick question,
    If I do:

    stress -m 4

    do I actually testing all of ram but sequentially, or I’m just testing couple of megs like a range for example from 0 to 600M ? Do the program testing all of my ram just writing to different location and freeing other and then accomplish test of all of my ram eventually?

    I don’t know how to ask, but do I have to know special command for testing 8 gigs of ram to be tested properly all of them? For example:

    stress -m 4 –vm-bytes 1000M

    Do I actually testing only range of ram from 0 – 1000M or its only chunk of data tested in one sub test and freed step by step, eventually testing all of my ram?

    I’m not a specialist, but its good to know how it works, cause I don’t know how to test my 8 gigs of ram, cause I can’t do it with memtest86+ cause the never version (only new version is working properly from what I know for newer ram modules) is only for UEFI bios and I don’t have one. Its relatively new hardware but without UEFI support. The ram is Patriot 1600MHz, and when I do memtest86+, at first it just works and then it is slowing down. So the gurus from memtest are recommending me to use newer memtest like from 6 version, but It cant run from non UEFI bios and its sad…

    Also if anyone knows how to run this never memtest, let me know please.

    • Hi,

      If all you want is to test a certain portion of your RAM, all at once, then you should use the ‘–vm-keep’ argument. For instance, to test 1GB at once, the below command should be used:

      stress -m 4 --vm-keep

      As soon as it runs, it’ll increase the RAM usage by 1GB (at once), which can be confirmed if you have the system monitor opened. Does that answer your question?

Leave a Comment