我想知道是否有人用 python 编写了模拟 cpu 和内存压力的代码。
我看到一段加载 cpu 的代码,但如何强制它们在 90% 的使用率下工作?
一个节点主要有 4 种经常使用的资源 -
- 有效内存
- 中央处理器周期
- 储存空间
- 网络负载(上传和下载)
这就是 Windows 上的任务管理器或 macOS 上的活动监视器(或 *nix 系统上的顶级免费命令)的原因。
如果需要特定的Python解决方案,那么我会推荐stress和stressypy模块。这是链接-https://pypi.org/project/stress/ https://pypi.org/project/stress/
https://pypi.org/project/stressypy/ https://pypi.org/project/stressypy/
简单的 pip install 就可以完成工作。
但就我个人而言,我很喜欢stress-ng 应用程序。您可以轻松安装上述所有资源并将所需的负载放入其中
在这里,找到它——https://www.mankier.com/1/stress-ng https://www.mankier.com/1/stress-ng
请参阅这些示例 -https://www.mankier.com/1/stress-ng#Examples https://www.mankier.com/1/stress-ng#Examples
stress-ng --cpu 4 --io 2 --vm 1 --vm-bytes 1G --timeout 60s
runs for 60 seconds with 4 cpu stressors, 2 io stressors and 1 vm stressor using 1GB of virtual memory.
stress-ng --iomix 2 --iomix-bytes 10% -t 10m
runs 2 instances of the mixed I/O stressors using a total of 10% of the available file system space for 10 minutes. Each stressor will use 5% of the available file system space.
stress-ng --cpu 8 --cpu-ops 800000
runs 8 cpu stressors and stops after 800000 bogo operations.
stress-ng --sequential 2 --timeout 2m --metrics
run 2 simultaneous instances of all the stressors sequentially one by one, each for 2 minutes and summarise with performance metrics at the end.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)