简体   繁体   English

为什么 EC2 服务器上的多个 Ruby 进程会导致 100% 的 CPU 使用率?

[英]Why are multiple Ruby processes on an EC2 server causing 100% CPU utilisation?

I have a Rails application which has 100% CPU utilization most of the time.我有一个 Rails 应用程序,它的 CPU 使用率大部分时间都是 100%。 I am not able to figure out why there is so much load on the server.我无法弄清楚为什么服务器上的负载如此之大。 I am using the Puma web server with a default configuration, and am running multiple background jobs using the sucker-punch gem.我正在使用具有默认配置的 Puma Web 服务器,并使用sucker-punch gem 运行多个后台作业。 There are 7 files which are using sucker punch jobs with 5 workers:有 7 个文件正在使用 5 个工人的 sucker punch 作业:

include SuckerPunch::Job 
workers 5

I ran the top -i query and found the following processes running on the server.我运行了top -i查询并发现服务器上正在运行以下进程。 I can see multiple Ruby commands on the server.我可以在服务器上看到多个 Ruby 命令。 Can someone tell me whether this is normal behavior on a server, or if something is wrong?有人可以告诉我这是服务器上的正常行为还是有问题?

“top”命令的输出

Some Ways to Reduce Resource Contention减少资源争用的一些方法

Your user space load is high (~48%), so you'll probably want to reduce the number of workers in your web application, increase the number of CPUs available on your instance, move to a version of Ruby that has better concurrency and real multi-core support (eg Rubinius or JRuby), or some combination of these options.您的用户空间负载很高 (~48%),因此您可能希望减少 Web 应用程序中的工作人员数量,增加实例上可用的 CPU 数量,迁移到具有更好并发性和更好的 Ruby 版本真正的多核支持(例如 Rubinius 或 JRuby),或这些选项的某种组合。 Depending on what your code is actually doing, you may also need to re-architect your application to offload expensive I/O from the application server.根据您的代码实际执行的操作,您可能还需要重新构建应用程序以从应用程序服务器卸载昂贵的 I/O。

In addition, your steal time is quite high (~41%), so your EC2 instance is probably overloaded.此外,您的窃取时间相当高 (~41%),因此您的 EC2 实例可能已过载。 Simply moving your application to a less-loaded instance may free up sufficient resources to reduce application wait times.只需将您的应用程序移至负载较少的实例即可释放足够的资源以减少应用程序等待时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM