简体   繁体   English

使用 NGINX 和 Puma 部署的 Rails 应用程序的 Auto Scaling Group 的最佳配置

[英]Best configuration of Auto Scaling Group for Rails application deployed using NGINX and Puma

I am using the Amazon Auto Scaling group for Rails application deployed on an EC2 instance using NGINX and Puma.我正在为使用 NGINX 和 Puma 部署在 EC2 实例上的 Rails 应用程序使用 Amazon Auto Scaling 组。 I am facing some challenges with the configuring of the Auto Scaling policy.我在配置 Auto Scaling 策略时面临一些挑战。

I am using r5.xlarge for the main instance that is hosting my corn jobs and r5.large for the autoscaling instance.我将 r5.xlarge 用于托管我的玉米作业的主实例,并将 r5.large 用于自动缩放实例。 My current scaling trigger is defined on the 50% CPU but apparently, that does not work due to the following reasons我当前的缩放触发器是在 50% CPU 上定义的,但显然,由于以下原因,它不起作用

  1. Since the main instance has 4 CPUs the overall consumption did not hit 50% unless there is some corn job running that is consuming all resources.由于主实例有 4 个 CPU,因此总体消耗没有达到 50%,除非有一些正在消耗所有资源的玉米作业正在运行。
  2. Even if the CPU will hit 50% the startup time of rails application is 30-40 seconds and in the meantime, all requests received by the server returns 503.即使 CPU 会达到 50%,rails 应用程序的启动时间也是 30-40 秒,同时服务器收到的所有请求都返回 503。
  3. If the CPU consumption is less than 50% but the system receives a lot of concurrent requests it does not start a new instance and either start returning 503 or the response time increases significantly.如果 CPU 消耗低于 50%,但系统接收到大量并发请求,它不会启动新实例并开始返回 503 或响应时间显着增加。

I have tried changing the auto-scaling group from CPU consumption to the number of requests but the start time issue of instance still prevails and sometimes it starts a new instance when it is not even needed.我尝试将自动缩放组从 CPU 消耗更改为请求数,但实例的启动时间问题仍然存在,有时它甚至在不需要时启动一个新实例。

Have you ever faced any such issue with Rails deployment, anything that you thinks worked for your out of the box?您是否曾在 Rails 部署中遇到过任何此类问题,您认为任何开箱即用的方法?

We are running Ruby application with PUMA in ECS Tasks, but should be quite the same problematic that with EC2.我们在 ECS 任务中使用 PUMA 运行 Ruby 应用程序,但应该与使用 EC2 的问题完全相同。

Since Ruby is single threaded, your Ruby Process running your PUMA server is only going to use one CPU at a time.由于 Ruby 是单线程的,因此运行 PUMA 服务器的 Ruby 进程一次只会使用一个 CPU。 If you have 4 CPU, I imagine one PUMA process will never manage to saturate more than 25% of the overall machine.如果你有 4 个 CPU,我想一个 PUMA 进程永远不会饱和超过整台机器的 25%。

Note: Also have a look at your configuration regarding the number of PUMA Threads.注意:还请查看有关 PUMA 线程数的配置。 This is also critical to configure, since you are doing auto-scaling, your application NEED to be able to saturate the CPU it's using, to be able to kick in. With too few Puma Thread it will not be the case, with too much your application will become unstable, this is something to fine tune.这对配置也很重要,因为您正在执行自动缩放,您的应用程序需要能够使其使用的 CPU 饱和,才能启动。如果 Puma 线程太少,情况就不会如此,太多您的应用程序将变得不稳定,这是需要微调的。

Recommendation:推荐:

  1. Run one PUMA process per CPU you have available with the EC2 class you have chosen, each PUMA server listening on a different port, have your load-balancer manage that.使用您选择的 EC2 class 每个 CPU 运行一个 PUMA 进程,每个 PUMA 服务器侦听不同的端口,让您的负载均衡器管理它。 This should allow your machine to reach potentially 100% CPU during saturation (in theory), allowing auto-scaling base on CPU to work这应该允许您的机器在饱和期间达到潜在的 100% CPU(理论上),允许基于 CPU 的自动缩放工作
  2. Preferred solution: Pick smaller machines, with 1 CPU, so you only need to run one PUMA server per machine.首选解决方案:选择较小的机器,配备 1 个 CPU,因此每台机器只需要运行一个 PUMA 服务器。

From my experience with ECS, Ruby and other single threaded languages should not use more than 1 (v)CPU machines, and you should instead really on heavy horizontal scaling if necessary (some of our service are running 50x ECS instances).根据我在 ECS 方面的经验,Ruby 和其他单线程语言不应使用超过 1 (v) 个 CPU 机器,如果需要,您应该真正进行大量水平扩展(我们的一些服务正在运行 50x ECS 实例)。

Hope this helps.希望这可以帮助。

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

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