java - 迁移到 Heroku 免费 : dynos, sleep 和 quartz

标签 java spring heroku quartz-scheduler

我有一个小型的 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 ) 表示每个应用程序有 1 个 Web dyno。 Web dyno 是否涵盖 Web 服务器和数据库?我在使用数据库时没有找到任何关于dynos的信息https://devcenter.heroku.com/articles/getting-started-with-java#use-a-database

此外,我的应用程序每小时运行一次 quartz 作业。它基本上调用一个网络服务,获取信息并在 bbdd 中生成统计数据。我发现 Heroku 应用程序在 30 分钟不活动后会自动 hibernate 。这对我的应用程序有何影响?似乎应用程序是通过网络请求唤醒的,但是后台任务呢?我需要将 quartz 作业移至 worker 测功机吗?看起来worker dynos不 sleep ,但是……他们是只在执行时消耗dyno小时(每小时3分钟)还是在空闲时也消耗dyno小时(24/7)?

如果经过验证的帐户每月有 1000 小时,并且应用程序仅消耗 1 个网络测功机,那么就无需让应用程序 hibernate ,对吧?仅使用 1 台测功机,一个月应少于 750 小时。有什么办法可以让应用程序保持活力吗?
另外,应用程序 hibernate 时涉及什么?每次唤醒时都会更改应用程序 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用于 MySQL 附加组件。了解如何添加/使用它们 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?

你应该将你的工作转移到 worker 测功机上。查看更多: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 - 只要你的 worker 角色正在运行(它将会运行) - 你就会消耗 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 个 dyno,1 个 web 和 1 个worker。使用此配置,如果您想让它们保持 24/7 运行,即使您是经过验证的帐户,免费层也不够。

关于java - 迁移到 Heroku 免费 : dynos, sleep 和 quartz ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53836944/

相关文章:

java - 检查一个字符串是否只包含一组字母

java - XSS攻击: change exception thrown in a Spring Boot CRUDRepository ?

java - 防止 Spring 尝试读取旧的资源流

r - 使用 R/Rserve 运行 Node.js 的良好托管解决方案是什么?

python - Redis 还是 Python/Heroku 中的线程?

java - 在Java中创建具有多个子节点的XML文件

java - 如何将两幅图像组合成混合图像?

java - Javers - 双向 OneToMany 上的 DiffIgnore

java - 如何添加外部库,使用 Gradle 的 Java Spring MVC 框架,PyramidIO

heroku - 未知网址展示次数