JavaRush /Java Blog /Random EN /Little tricks with Heroku
Игорь
Level 40
Киев

Little tricks with Heroku

Published in the Random EN group
Let's imagine the situation. You completed the JavaRush course, completed an online internship, and you have your first project on the Heroku PaaS platform . You send out your resume and start going for interviews. And at one of them you are asked to show your project (or they will want to quickly look at it even before the interview by following the link from your resume). The browser opens and your site takes a long time to load. Yes, you can explain that this is a free Heroku and that’s how it works, but the impression is ruined. We will try to understand the reasons for this behavior and methods of combating it in this article.
Little tricks with Heroku - 1
Let's start with the concept of dyno hours . According to the documentation , Dyno hours is essentially the running time of your application/applications expressed in hours/month. Immediately after registering a free account, you are given 550 hours per month. Having carried out simple calculations, we get about 17 hours a day for one application. It won't be enough. Therefore, we link a credit card in Account settings - Billing and get another 450 free hours (32 hours a day already). This problem has been resolved. There is one more. The above document also states that the application will "dyno sleep" if there is no activity for 30 minutes. There are three main approaches on the Internet:
  1. Regularly (for example, once every 5 minutes) send requests to the application from within the application itself.

    Using JavaScript it would look like this:

    var http = require("http");
    setInterval(function() {
        http.get("http://<your app name>.herokuapp.com");
    }, 300000); // every 5 minutes (300000)
  2. Use external ping sites that will check your site at specified intervals.

    Examples of such sites are Pingdom , Uptime Robot , Kaffeine and others. The principle is simple. We go in, register (if necessary), indicate the site and time interval and apply the settings.

  3. Use Heroku Newrelic addon This plugin is designed to monitor and notify about site crashes, but as a useful “side effect” it will prevent the application from falling asleep. I settled on this method, which, in my opinion, is the most beautiful. I will describe it in more detail.

    To install the addon, you need to follow this link and click the "Install New Relic APM" button . In the window that opens, you need to select a tariff plan and the name of the application to which this addon will be applied.

    Little tricks with Heroku - 2

    Then press the "Provision add-on" button .

    After installation, New Relic will be available on the application settings page in the list of installed addons.

    Little tricks with Heroku - 3

    Click on the link and you will be taken to the add-on settings page.

    Go to the "Synthetics" tab and click the "Add new" button.

    Little tricks with Heroku - 4

    In the window that opens, in the “Enter the details” section , indicate an arbitrary name of the monitor and the address of the site that we will monitor. We select the location from where the site will be checked in "Select monitoring locations" .

    We indicate the frequency of checking in “Set the shedule” (I set it to 15 minutes) and the email for notifications in “Get notified”.

    After all the settings, don’t forget to click the “Create monitor” button.

Voila, the monitor has been created and now your application will work 24/7 and will not fail at the most crucial moment :)
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION