用于自动缩放 Heroku dynos 和 worker 的 Gems/服务 [英] Gems/Services for autoscaling Heroku's dynos and workers

查看:23
本文介绍了用于自动缩放 Heroku dynos 和 worker 的 Gems/服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何好的解决方案可以在生产环境中自动缩放 Heroku 上的 dynos 和 worker(可能对每个解决方案都有不同的解决方案,因为它们非常不相关).您/公司在这方面使用什么?

I want to know if there are any good solutions for autoscaling dynos AND workers on Heroku in a production environment (probably a different solution for each of those, as they are pretty unrelated). What are you/companies using, regarding this?

我发现了很多选择,但对于生产环境来说,似乎没有一个是真正成熟的.有 Heroscale,它似乎引入了一些延迟,因为它不在本地运行,而且我也听说过一些停机时间.有delay_jobs的修改,已经很久没有更新了,目前bundler存在一些问题.还有一些与 reque 相关的替代方案,它们似乎不能很好地处理一些 HTTP 异常,这会导致应用程序崩溃,而其他一些似乎需要一个始终运行的 worker 来调度其他 worker,并且还可能遭受一些 HTTP 异常的困扰问题.

I found lots of options, but none of them seem really mature for a production environment. There is Heroscale, which seem to introduce some latency as it does not run locally, and I also heard of some downtime. There are modifications of delayed_jobs, which have not been updated for a long time, and there are some issues with current bundlers. There is also some alternatives related to reque, which seem not to handle very well some HTTP exceptions, which results in app crashing, and others which seem to need an always-running worker to schedule other workers, and may also suffer from some HTTP exceptions problems.

嗯.到底.现在,在使用 Rails3 的生产环境中自动扩展 Heroku 的 dynos 和 worker 的用途是什么?

Well. In the end. What is being used, nowadays, for autoscaling Heroku's dynos and workers on a production environment with Rails3?

提前致谢.

推荐答案

我们不久前遇到了这个问题,我花了很多时间来解决这个问题,这让我非常沮丧.我会尽量坚持重点.有几个 Heroku 自动缩放解决方案乍一看似乎不错.

We ran into this a while ago and I spent quite a bit of time on this to my great frustration. I'll try to stick to the salient point. There are several Heroku autoscaling solution that seem decent at first glance.

已经给出的例子heroku-autoscaler实际上是用于自动缩放dynos的,很漂亮这是唯一声称可以做到这一点的解决方案(而且它肯定做得不好).大多数其他人只会声称为您自动缩放工作人员.所以,让我们首先关注这一点.您将为工作人员查看的自动缩放器取决于您实际为后台工作人员使用的内容,例如delayed_job重新请求.这些是人们使用的最常见的后台处理库,因此自动缩放器将尝试连接到其中之一.您可以使用以下内容:

The example that has already been given heroku-autoscaler is actually for autoscaling dynos and is pretty much the only solution out there that claims to do this (and it certainly doesn't do it well). Most others will only claim to autoscale workers for you. So, let's focus on that first. The autoscalers you'll look at for workers depend on what you're actually using for you background workers e.g. delayed_job, resque. Those are the most common background processing libs that people use, so the autoscalers will try to hook into one of them. You can use things like:

其中一些在 Cedar 堆栈上工作,有些可能需要进行一些调整.所有这些的问题在于,这就像试图通过自己的头发将自己拉出沼泽.让我们以租用火为例(它可能是最好的一个).它修改了 delay_job 以便工作人员自己可以查看队列并在必要时启动更多工作人员,如果队列中没有更多工作,工作人员将互相关闭.有几个问题:

Some of these work on the Cedar stack some might need a bit of tweaking. The problem with all of them is that it's like trying to pull yourself out of the swamp by your own hair. Let's take hirefire as an example (it's probably the best one of the lot). It modifies delayed_job so that the workers themselves can look at the queue and spin up more workers if necessary, if there are no more jobs in the queue, the workers will all shut each other down. There are several problems:

  • 如果您想将一项作业放入队列以供将来执行而不是现在执行,那您就不走运了.当作业进入队列时工作人员启动,但由于工作将在将来执行,因此工作人员将关闭并且不会启动,除非另一个工作进入队列(这是唯一提示工作人员启动的事情)
  • 您失去了重试失败作业的能力,这在 delay_job 中默认是可能的,但是如果多次失败,则需要一段时间才能重试失败的作业(并且逐渐延长),但工作人员将关闭在这段时间延迟期间关闭并且没有任何提示他们再次启动(本质上这与第一个场景中的问题相同)

解决这个问题的方法是让一个 worker 连续运行,因此它可以定期监视队列,并在必要时执行作业,甚至可以启动更多 worker.但是如果你这样做,你就不会节省任何钱(你有一个工人 24/7 连续运行并且必须为此付费),这就是 heroku 上自动缩放器背后的全部前提.从本质上讲,如果您只是偶尔进行后台处理,或者您的后台作业可能会失败但重试成功,或者您的后台作业不需要立即执行,则没有您可以使用的自动缩放库使用对您有用的方法.

The thing that solves this problem is to have one worker running continuously it can therefore monitor the queue periodically and can execute jobs when necessary or even spin up more workers. But if you do that, you're not saving any money (you have a worker running continuously 24/7 and have to pay for that) and that's the whole premise behind autoscalers on heroku. In essence, if you only have occasional background processing to do, or you have background jobs that are likely to fail but succeed on retry, or you have background jobs that don't need to be executed instantly, there is no autoscaling library you can use that will work for you.

这是一种选择.写 Hirefire 的人,后来把它分拆成一个 webapp(Hirefire app),其本质是外部监控您的 Heroku 工人/dynos 为您,并在必要时启动/关闭工人 dynos.这在测试版中是免费的,但现在它要花钱,比你为 24/7 全天候运行工作人员所支付的要少,但如果你偶尔只需要一些后台工作,这仍然不是微不足道的.无论哪种方式,这是确保您的后台作业基础架构满足您的要求的唯一可行方法(好吧,并推出您自己的解决方案,这意味着拥有一台像 EC2 实例这样的机器,您可以在其中放置一些脚本,这些脚本将 ping 您的 heroku 应用程序并旋转根据需要关闭/关闭工人 - 一个不平凡的努力).

Here is one alternative. The guy who wrote Hirefire, later spun it off into a webapp (Hirefire app), the essence of which is to externally monitor your Heroku workers/dynos for you and spin up/shut down workers dynos as necessary. This was free in beta but it now costs money, less than what you'd pay to run a worker 24/7 but still not insignificant if you only need a few background jobs once in a while. Either way this is the only viable way to make sure your background job infrastructure does what you want (well that and rolling your own solution which means having a machine like an EC2 instance where you can put some scripts which will ping your heroku app and spin up/shut down workers as needed - a non-trivial amount of effort).

现在 Hirefire 应用程序也为您提供自动缩放您的 dynos,它是基于挂钩到您的 heroku 请求队列的延迟来实现的.但是我发现这并不奏效,也许如果您靠近您的 heroku 应用程序实际所在的 Amazon 数据中心(我们不是),您可能会有不同的体验.但是,对我们来说,它不必要地启动了一大堆测功机,而且无论我如何调整设置都不会停止它们.你可以把它归结为它是一个测试版,从那时起它可能会有所改进,但这就是我的经验.

Now Hirefire app does offer to autoscale your dynos for you as well, it does this based on hooking in to the latency of your heroku request queue. However I found that this didn't work well, perhaps if you're close to the Amazon datacenter where your heroku app actually lives (we weren't), you might have a different experience. But, for us it unnecessarily spun up a whole bunch of dynos and would never spin them down no matter how much I tweaked the settings. You can put it down to the fact that it was a beta it may have improved since then, but that's the experience that I had.

长话短说,如果你想自动调整你的员工,使用 Hirefire 应用,你节省的钱会比你想象的少很多,但它仍然是最便宜的选择.如果您想自动缩放 dynos,那么您基本上就不走运了.这只是您在享受 Heroku 等平台的便利性方面所面临的限制之一.

Long story short, if you want to autoscale your workers, use Hirefire app, you'll be saving a lot less money than you thought, but it is still the cheapest option. If you want to autoscale dynos you're basically out of luck. This is just one of those limitations you live with for having the convenience of a platform like Heroku.

这篇关于用于自动缩放 Heroku dynos 和 worker 的 Gems/服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆