如何将 AWS EC2 实例 CPU 利用率提高到 100% 以测试创建新实例的自动缩放组?

How to increase AWS EC2 instance CPU utilization to 100% to test autoscaling group creating new instances?

我需要测试当 CPU 利用率超过特定阈值(例如 70%)时创建新实例的自动缩放组。

是否有任何方法可以提高 CPU 利用率以进行测试?

如果您正在测试基于 Web 的应用程序,我建议您尝试 Bees With Machine Guns

它是一个 python 脚本,它将启动微型 EC2 实例并将许多 Web 请求从这些实例发送到您的应用程序。这将模拟性能测试的流量激增。

请注意页面底部的警告:

If you decide to use the Bees, please keep in mind the following important caveat: they are, more-or-less a distributed denial-of-service attack in a fancy package and, therefore, if you point them at any server you don’t own you will behaving unethically, have your Amazon Web Services account locked-out, and be liable in a court of law for any downtime you cause.

You have been warned.

在 Posix 系统上提高 CPU 利用率的另一种方法是使用 stress 命令。根据您的配置,压力会产生 CPU、内存、I/O 或磁盘工作负载。

一个示例 answer here 展示了如何使用压力将实例的内存提高到 90%。

您可以在Linux中使用压力命令:

stress --cpu 2 --timeout 60

cpu指定核心数,timeout指定此命令执行的秒数运行。

对于Windows: 安装 Windows Server 2003 Resource Toolkit。 然后运行cmd中的这个命令:

consume -cpu-time -time 5