免费迁移到 Heroku:dynos、sleeps 和 quartz

Moving to Heroku free: dynos, sleeps and quartz

我有一个小型 java spring Web 应用程序托管在 openshift starter(免费计划)中,但他们将使免费帐户在 60 天后过期 https://blog.openshift.com/changes-to-openshift-online-starter-tier/

我正在尝试寻找一个免费平台来托管我的应用程序,我找到了 Heroku,但我不知道它是否适合(请不要难,我只是想知道heroku 是如何工作的!)。

目前我有一个 wildfly 服务器和一个 mysql 数据库 运行,每个都在 1 个 pod 中。 Heroku 免费计划 (https://www.heroku.com/free) says that you have 1 web dyno per app. Does the web dyno covers the web server and the database? I haven’t found anything about dynos when using a database https://devcenter.heroku.com/articles/getting-started-with-java#use-a-database

此外,我的应用程序每小时有一个 quartz 作业 运行。它基本上调用一个网络服务,获取信息并在 bbdd 中生成统计信息。我已经看到 Heroku 应用程序在闲置 30 分钟后会自动休眠。这对我的应用有何影响?应用程序似乎是通过网络请求唤醒的,但是后台任务呢?我需要将石英工作转移到工人测功机上吗?似乎 worker dynos 不睡觉,但是......他们是只在执行时消耗 dyno 小时(每小时 3 分钟)还是在空闲时也消耗 dyno 小时(24/7)?

如果经过验证的帐户有 1000 小时/月并且该应用程序仅消耗 1 个网络测功机,那么就没有必要让该应用程序休眠,对吧?仅使用 1 个测力计,1 个月应该少于 750 小时。有什么方法可以让应用程序保持活跃吗?
另外,当应用程序休眠时涉及什么?它每次唤醒都会更改应用程序 IP?

抱歉,如果其中一些是新手问题,请提前致谢!

我会尽量一一解答您的问题。

Heroku free plan (https://www.heroku.com/free) says that you have 1 web dyno per app. Does the web dyno covers the web server and the database?

不 - 它没有。 Heroku 有附加组件,你可以为你的应用程序配置,see here for MySQL add-ons. See how you can add / use them here.

Also, my app have a quartz job running each hour. It basically calls a webservice, takes the info and generate statistics in the bbdd. I have seen that Heroku apps sleep automatically after 30 mins of inactivity. How does this affect to my app?

这意味着如果您收到一个服务请求(并且服务器还没有预热),您将消耗 30 分钟的 dyno 小时。每 30 分钟仅 1 个请求唤醒服务器 效率不高,但这就是系统。

Seems that apps wake with web request, but what about background task? Do I need to move the quartz job to a worker dyno?

你应该把你的工作转移到工人测功机上。查看更多:https://devcenter.heroku.com/articles/free-dyno-hours

Seems that worker dynos don’t sleep, but… are they consuming dyno hours only while they are being executed (3 mins each hour) or they consume dyno hours while they are idle too (24/7)?

这是不正确的。 Computing usage is calculated from the wall-clock time and not CPU time - 只要你的工人角色是 运行(它会是) - 你就会燃烧 dyno 小时。

If verified accounts have 1000 hours / month and the app consumes only 1 web dyno then there is no need to let the app sleep, right? One month should be less than 750 hours using only 1 dyno. Is there any way to keep the app alive?

你说的是现在有 2 个 dynos,1 个 web 和 1 个 worker。使用此配置,即使您是经过验证的帐户,如果您想 运行 24/7 全天候保留它们,免费套餐是不够的。