How to set CPU load on a Red Hat Linux box?

2020-07-14 09:35发布

I have a RHEL box that I need to put under a moderate and variable amount of CPU load (50%-75%).

What is the best way to go about this? Is there a program that can do this that I am not aware of? I am happy to write some C code to make this happen, I just don't know what system calls will help.

10条回答
欢心
2楼-- · 2020-07-14 10:10

Lookbusy enables set value of CPU load. Project site

lookbusy -c util[-high_util], --cpu-util util[-high_util]

i.e. 60% load
lookbusy -c 60
查看更多
Fickle 薄情
3楼-- · 2020-07-14 10:18

This is exactly what you need: http://weather.ou.edu/~apw/projects/stress/

From the homepage: "stress is a simple workload generator for POSIX systems. It imposes a configurable amount of CPU, memory, I/O, and disk stress on the system. It is written in C, and is free software licensed under the GPL."

查看更多
等我变得足够好
4楼-- · 2020-07-14 10:18

Find a simple prime number search program that has source code. Modify the source code to add a nanosleep call to the main loop with whichever delay gives you the desired CPU load.

查看更多
兄弟一词,经得起流年.
5楼-- · 2020-07-14 10:24

It really depends what you're trying to test. If you're just testing CPU load, simple scripts to eat empty CPU cycles will work fine. I personally had to test the performance of a RAID array recently and I relied on Bonnie++ and IOZone. IOZone will put a decent load on the box, particularly if you set the file size higher than the RAM.

You may also be interested in this Article.

查看更多
We Are One
6楼-- · 2020-07-14 10:24

A Simple script to load & hammer the CPU using awk. The script does mathematical calculations and thus CPU load peaks up on higher values passwd to loadserver.sh .

checkout the script @ http://unixfoo.blogspot.com/2008/11/linux-cpu-hammer-script.html

查看更多
Ridiculous、
7楼-- · 2020-07-14 10:25

You can probably use some load-generating tool to accomplish this, or run a script to take all the CPU cycles and then use nice and renice on the process to vary the percentage of cycles that the process gets.

Here is a sample bash script that will occupy all the free CPU cycles:

#!/bin/bash
while true ; do
true
done
查看更多
登录 后发表回答