python - 如何在 python 中模拟 cpu 和内存压力

标签 python cpu

我想知道是否有人用 python 编写了模拟 cpu 和内存压力的代码。 我看到加载 CPU 的代码,但我如何才能强制它们在 90% 的使用率下工作?

最佳答案

一个节点主要有4种经常使用的资源-

  • 可用内存
  • CPU 周期
  • 存储空间
  • 网络负载(上传和下载)

这就是 Windows 上的任务管理器或 macOS 上的事件监视器(或 *nix 系统上的顶级免费命令)的原因。

如果需要特定的 python 解决方案,那么我会推荐 stress 和 stressypy 模块。这是链接- https://pypi.org/project/stress/ https://pypi.org/project/stressypy/

简单的 pip 安装就可以完成这项工作。

但就个人而言,我是 stress-ng 应用程序的粉丝。您可以轻松安装上述所有资源并将所需的负载放在上面 在这里,找到它- https://www.mankier.com/1/stress-ng

引用这些例子- 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.

关于python - 如何在 python 中模拟 cpu 和内存压力,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35312756/

相关文章:

python - 如何向 Qthread 发送参数

python - 从 pandas 转移到 dask 以利用所有本地 cpu 内核

android - 在 Android 设备上停止 ARM Cortex A8 CPU

cpu - Sandy-Bridge CPU 规范

ruby - 这个 Ruby 代码和 shell 代码有什么区别?

python - 如何在 PyBox2D 中绘制圆形

python - 类型提示和链式赋值和多重赋值

python - 如何避免重复创建对象

python - 使用Jenkins和Docker运行Python脚本

visual-studio-2005 - 无法在 Visual Studio 2005 中将 objective-c PU 更改为 x86 或 x64