在测试工作中,有时候需要对cpu施加压力来模拟环境
./stress --cpu 3
类似windows环境下的consume.exe
假设是4个cpu core的主机
for i in 1 2 3 4; do while : ; do : ; done & done
如果是bash,还支持 {1..4}
for i in {1..4}; do while : ; do : ; done & done
from multiprocessing import Pool
def f(x):
# Put any cpu (only) consuming operation here. I have given 1 below -
while True:
x * x
# decide how many cpus you need to load with.
no_of_cpu_to_be_consumed = 3
p = Pool(processes=no_of_cpu_to_be_consumed)
p.map(f, range(no_of_cpu_to_be_consumed))