如何使用Heroku和CleverCloud在Java应用程序上加快应用程序启动的速度?
上下文:我正在学习通过由我国政府运营的课程编码。我们正在使用Angular,Java Spring Boot和SQL来创建投资组合。他们没有在不同的事情上详细介绍,他们将我们指向Google(堆叠溢出)以及学生之间的合作,出于任何疑问。我设法创建了一个应用程序,目前托管在Firebase(Frontend),Heroku(Backend)和CleverCloud(数据库)上,并提供了每个应用程序的免费版本。
在本地运行该应用程序时,它在大约10秒内开始。在与CleverCloud连接时,在Heroku中运行该应用程序或进行清洁并在Apache Netbeans中构建时,它在大约2分钟内开始。我想尽可能减少启动。显而易见的解决方案可能是使用非免费版本的Heroku版本,而不是让应用程序停止,而是鉴于我的国家和瞄准免费版本的课程,这不是一个选择。
我尝试的是:
- 删除对实体的未使用的导入并添加“排除测试 依赖项“本heroku指南的一部分: https://devcenter.heroku.com/articles/减少java-applications of-size of-size , 但是完成干净并在Apache Netbean中构建后,加载时间 大约2分钟,花了另一分钟才能做其他 以前不存在的过程。我结束了变化。
- 向前端添加了一个加载屏幕,以告诉用户Heroku在启动时需要2分钟,而从前端进行的HTTP呼叫中,HTTP呼叫的超时时间为1800000,但是HTTP调用大约一分钟后仍会崩溃,使用户必须必须使用户必须使用。刷新页面并等待。
我想在某个时候检查该应用程序,要么在工作日的工作日不停地运行该应用程序,要么让它快速开始。我看到了一些页面,例如 https://kaffeine.herokuapp.com/ 知道如何使用它们,如果我可以在工作日和工作日中免费使用它们。
鉴于该创业公司在Heroku上都很慢,并且在连接到CleverCloud的同时进行干净并在Apache Netbeans进行构建时,我什至不知道问题是否在Heroku本身上。作为一个完全不熟悉编码的人,并且它的暴露是“做到这一点”的,而没有太多的解释,这有点令人沮丧。我看到了一个叫做“ cron”的东西,但是我不明白它们是如何工作或创建它们的,或者它们是否会在仅支持Crud的Java应用程序上工作(也许在前端做这种Cron的事情,但我仍然一无所知关于他们)。
TLDR:有什么方法可以加快Java应用程序的构建或启动,还是在工作日和Dummies的Workhours自动启动免费的Heroku应用程序的指南?
抱歉,如果问题很明显,因为我是一个不得不依靠指南和视频代码的初学者。
Context: I am learning to code with a course run by my country's government. We are using Angular, Java Spring Boot and SQL to create a portfolio. They did not go into much detail on different things, and they pointed us to Google (and Stack Overflow), as well as cooperation between students, for any doubts. I managed to create an app, and is currently hosted on Firebase (frontend), Heroku (backend) and CleverCloud (database), with the free versions of each.
When running the app locally, it starts in around 10 seconds. When running the app in Heroku or doing clean and build in Apache Netbeans while connected to CleverCloud, it starts in around 2 minutes. I would like to reduce the start up as much as possible. The obvious solution would probably be to use a non free version of Heroku and not let the app stop, but given both my country and the course aiming for the free version, that is not an option.
What I tried:
- Deleting unused imports on entities and adding the "Excluding test
dependencies" part in this Heroku guide:
https://devcenter.heroku.com/articles/reducing-the-slug-size-of-java-applications,
but after doing a clean and build in Apache Netbeans, the load time
was around 2 minutes, and it took like another minute to do other
processes that were not there before. I ended rolling back the changes. - Added a loading screen to the frontend to tell users that Heroku takes 2 minutes on startup, and a timeout of like 1800000 on the HTTP calls made from the frontend, but the HTTP call still crashes after like a minute, making it so user have to refresh the page and wait.
I would like, as the app is going to be checked at some point, to either have the app running nonstop on weekdays on workhours or for it to start fast. I saw some pages like https://kaffeine.herokuapp.com/ that ping the app, yet I dont know how to use them o if I can set them for free to be used on weekdays and workhours.
Given the startup is slow on both Heroku and while doing a clean and build in Apache Netbeans while connecting to CleverCloud, I dont even know if the issue is on Heroku itself. As someone who is completely new to coding, and its exposure has been a "do this" without much explanation, this is kinda frustrating. I have seen something called "cron", but I dont understand how they work or to create them, or if they would work on a Java app that only supports CRUD (maybe doing this cron thing on the frontend, but still I dont know anything about them).
TLDR: Are there any ways to speed up the build or start up of a Java app, or guides to autoping free Heroku apps on weekdays and workhours for dummies?
Sorry if the question is obvious, as I am a total beginner that had to rely on code along guides and videos.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
免费Heroku上的Hobby版本
免费
版本将入睡,到达网站后将需要一段时间才能加载。每月7美元,您可以删除此限制并获得更多的功率
hobby版本
- 我认为这是完全值得的,我将其用于我的个人项目。 https://www.heroku.com/pricing如果您使用某些东西来使Heroku保持活力您将用完快速小时(您的应用程序可以运行的小时),即使这样,免费层也会很难运行应用程序。
Heroku也支持SQL(Postgres),因此将DB,Frontend和后端放在同一位置也是一个奖励。一切运行顺利,环境变量和自动部署易于设置。
如果这是您第一次在AWS上,您也可以在那里使用免费层,并使用Elastic Beanstalk部署。但是,对于一个简单的免费项目,AWS基础架构可能是压倒性的 - 当他们开始向您收费时,请注意。
For the Free & Hobby version on Heroku you application on
Free
version will go to sleep which after arriving on the site will take a while to load up.For 7 bucks a month you can remove this restriction and get more power
Hobby version
- I think it's totally worth it and I use this for my personal projects quite a lot. https://www.heroku.com/pricingIf you use something to ping Heroku to keep it alive you will run out of dyno hours (hours that your app can run) and even then the free tier will have hard time running applications.
Also Heroku supports SQL (Postgres) so having db, frontend and backend in the same place is a bonus. Everything runs smoothly, environment variables and automatic deploys are easy to set up.
If it's your first time on AWS you could also use free tier over there for some time and deploy using elastic beanstalk. But AWS infrastructure can be overwhelming for one simple free project - gotta watch out when they start charging you.