How to speed up the app startup on a Java app using Heroku and CleverCloud?

67 Views Asked by At

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.

1

There are 1 best solutions below

1
Joosep Parts On

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.

Sleeps after 30 mins of inactivity, otherwise always on depending on your remaining monthly free dyno hours.

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/pricing

If 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.