如何监控由heroku调度程序运行的重复rake任务?

发布于 2025-01-02 01:03:45 字数 260 浏览 1 评论 0原文

我刚刚收到上个月的heroku账单,预定的rake任务是一个比较重的负担。我们还处于开发过程的早期阶段,所以我们最近只是开发了一些 rake 任务来完成工作,并没有太多关注它们的优化。

现在我们希望提高他们的性能和 heroku 处理时间的使用情况。我们使用 New Relic 来监控 web 应用程序的性能,但显然默认情况下会忽略这种类型的 rake 任务,并且不清楚如何覆盖它。

有人遇到过类似的问题吗?如何近乎实时地跟踪计划任务以监控性能、优化并且不会收到意外账单?

I just got the last month heroku bill, and the scheduled rake tasks were a relatively heavy burden. We are pretty early in our development process, so we just developed some rake tasks to get the job done recently, and didn't had much concern in theirs optimization.

Now we want to improve theirs performance and theirs heroku processing hours usage. We use New Relic to monitor the webapp performance, but apparently this type of rake tasks are ignored by default, and it's unclear how to override that.

Anyone had a similiar problem? How can I track the scheduled tasks in close to real time to monitor performance, optimize, and don't get suprise bills?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

儭儭莪哋寶赑 2025-01-09 01:03:45

虽然您无法真正很好地监控 rake 任务,但您可以做一些小事情。一是使用日志记录。将任务的开始和结束时间输出到日志,然后您可以查看持续时间发生的情况。如果您将其与 Papertrail 插件之类的东西结合起来,那么您可以稍后进行额外的询问。

至于运行作业本身,您可以通过多种方式来运行后台进程,具体取决于它们需要如何运行:

如果您需要按计划运行作业,则有一些可用选项。首先是 Heroku 调度程序,它非常好,但不能保证执行会发生。通常,您会使用它来启动 rake 任务,该任务将在任务期间启动一次性测功机 - 因此您需要确保在开发过程中这些任务尽可能高效。

或者,如果您正在寻找需要更多控制或使用时钟进程的作业。本质上,这是一个 24/7 运行的测功机,除了按预设的时间间隔和时间启动其他作业外什么也不做。这通常可以使用发条宝石来完成。这种方法的缺点是您需要一直为时钟进程付费。

第三种方法(可能有效)是延迟作业,它具有 runat 选项,允许您对将来要运行的作业进行排队(并且作业可以自行重新排队)。这有一些问题,因为故障可能会杀死整个链,并且您需要一个全职工作人员运行来处理所有这些问题。

因此,为了最大限度地减少您的账单,请确保您的 Rake 任务高性能且可靠,然后选择适合您的计划选项。如果您正在查看时间表以及用户创建的事件,delayed_job 可能是最佳选择。如果您正在查看定期运行的一些任务,那么请使用调度程序。如果您打算定期运行大量时间紧迫的作业,请选择发条工作。

无论哪种方式,您都应该能够根据您的方法将相当多的处理限制为一个或两个进程。

Whilst you can't really monitor rake tasks that well, there are a few little things you can do. One is the use of logging. Output start and end times of tasks to logs, and you can then see what's been happening duration wise. If you couple this with something like the Papertrail add-on then you can do additional interrogation later on.

As for running the jobs themselves, there's a couple of ways that you can run background processes which are dependant on how they need to run:

If you're needing to run jobs on a schedule, there's a few options available. Firstly there's the Heroku scheduler, which is pretty good, but doesn't guarantee executions will happen. Normally you would use this to kick off a rake task which will bring up a one-off dyno for the duration of the task - therefore you need to ensure in development that these tasks are as efficient as possible.

Alternatively, if you're looking at jobs that need a little more control or using a clock process. Essentially this is a dyno running 24/7 that does nothing but kick off other jobs at preset intervals and times. This would normally be done using the clockwork gem. The downside of this approach is that you need to pay for a clock process all the time.

A third approach, and one that might work is delayed job, with it's runat option, allowing you to queue a job to be run in the future (and jobs can re-queue themselves). There are a few issues with this in that a failure can kill the whole chain, and you need a full time worker running to process them all.

Therefore, in order to minimize your bills, ensure that your rake tasks are as performant and reliable, and then choose the scheduling option that suits you. If you're looking at schedules plus user created events, delayed_job might be the best option. If you're looking at a few tasks running periodically, then go scheduler. If you're looking at running lots of time critical jobs on a regular basis, go with clockwork.

Either way, you should be able to constrain a fair amount of processing into just one or two processes depending on your approach.

摇划花蜜的午后 2025-01-09 01:03:45

我知道这个问题已经有近 10 年历史了,但是有一个新方法!

您现在可以使用一次性 Dyno Metrics 监控 Heroku Scheduler 作业。这个 Heroku 插件收集 Heroku 应用程序中运行的所有独立的一次性测功机的指标。它是作为 Heroku 应用程序指标的扩展而创建的,并且开箱即用。

I know this question is almost 10 years old, but there is a new way!

You can now monitor your Heroku Scheduler jobs using One-off Dyno Metrics. This Heroku add-on gathers metrics for all detached one-off dynos running in your Heroku app. It was created to be an extension of Heroku's Application Metrics and works out of the box.

浮光之海 2025-01-09 01:03:45

当您在 heroku cedar 上运行时,有一种方法可以为您的工作人员获得免费设置。这不是您的监控问题的答案,但无论如何它可能很有趣: http://blog.nofail.de/2011/07/heroku-cedar-background-jobs-for-free/

when you are running on heroku cedar there is a way to get a free setup for your workers. this is no answer to your monitoring question, but it might be interesting anyways: http://blog.nofail.de/2011/07/heroku-cedar-background-jobs-for-free/

盗梦空间 2025-01-09 01:03:45

您可以强制 New Relic 代理启动抓取任务并报告其性能数据。

You can force the New Relic agent to start in your rake tasks and report their performance data.

浊酒尽余欢 2025-01-09 01:03:45

不是具体问题的答案,但是......
减少开销的一种方法是使用 Unicorn 服务器让多个工作人员在一台测功机上工作。这取决于您的设置,但大多数花时间测试它的人都可以轻松地同时运行 3 - 4 个工作进程。这对清除线索或任务有巨大的促进作用。请注意不要最大化为测功机分配的内存。

Not the answer to the specific question,but...
One method of reducing overhead is using Unicorn server to get multiple workers working on one dyno. It depends on your set up, but most people who've taken the time to test it can comfortably get 3 - 4 worker processes running concurrently. It's a huge boost in clearing cues or tasks. Just be careful not to max out the allocated memory for the dyno.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文