shell固定时间消耗固定大小内存

shell固定时间消耗内存

需求背景

产品出了一个新功能,当客户创建的任务消耗内存达到一个边界值时,后续的任务就暂时停止运行,处于排队状态,当内存释放不超出边界值时,后续的任务就可以运行

实现

#!/bin/bash
free -m > /tmp/freee
cat /tmp/freee
mkdir /tmp/memory
mount -t tmpfs -o size=$1 tmpfs /tmp/memory
dd if=/dev/zero of=/tmp/memory/block
free -m > /tmp/freee
cat /tmp/freee
sleep $2
rm -rf /tmp/memory/block
umount /tmp/memory
rmdir /tmp/memory

运行脚本时传入需要被消耗的内存,和内存被消耗的时间,轻松完成测试。

你可能感兴趣的:(测试)