开发者

Bash: easy way to put a configurable load on a system?

In order to test how a program reacts when system resources become scarce (mainly the CPU but I'm interested in disk I/O too), I'd like to put an arbitrary load on the system.

Curr开发者_运维知识库ently I'm doing something like this:

#!/bin/bash

while true
do
    echo "a" >> a.txt
    md5 a.txt
done

I could also start mp3-encoding audio files, or whatever.

What would be an easy and small Bash script that could be used to simulate an arbitrary load, ideally configurable using parameter(s)?


If you are looking for only CPU load, you may simply execute an empty loop:

while :; do : ; done

for disk I/O you can use a sequence of file copy od disk dump (see "dd" command)

Regards


Well, you can test CPU load by doing an empty loop as stated above.

For disk I/O, it depends how sophisticated you need. If you just want something that can test I/O speed at constant full blast, try something like this:

yes "a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long string (longer than this example)" | dd if=/dev/stdin of=file

Which will give you a nice speed reading when you kill the command.

If you want to tune the exact amount of load, it gets a bit tricker.

However, why are you rolling your own benchmarks? There are plenty already existing, and you can get a bunch of good ones with the Phoronix Test Suite.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜