Skip to main content

How to keep your free hosted Heroku web app awake 24/7


Heroku is a very exciting free hosting service that allows us, developers to host free web apps or websites on the cloud in minutes. This service is especially famous among python developers, as it is probably the only free hosting service that supports python (If you know any other service, let me know in the comments). It is very convenient to deploy experimental code or small scale apps. For those of you who don't know, this format of cloud service is called PaaS, which stands for Platform as a Service.

The problem

The thing about all these free services online are, they all come with strings attached. Some of them are free only for a limited period of time, and some are free for a limited set of features. I personally prefer the later. An example of the first kind is Microsoft Azure. They have a 30 day trial period and they take your credit card information while registering. Whereas Heroku doesn't take your credit card information while registering. But it has limited features and resources.

One of the limitations is that, the free servers that they provide come in a container which they call a dyno. And each free app is assigned only one dyno. And these dynos act as the "platform" for your web app/ website. Also, another catch is that these dynos are not awake 24/7. When your web app is inactive for a certain amount of time, they reassign that particular dyno to some other web app that needs it. This way they reuse their resources for free accounts.

The consequence 

So, during the time it is inactive if somebody tries to access the web app, it will take a lot of time to load. Because in the background, it has to search for some other inactive web app and grab its dyno. This delay in time can sometimes cause a problem. For example, me and a friend are making a native android app which uses a REST API that we have deployed on Heroku. This delay in response sometimes caused a connection time-out exception in the app.

The solution

So the simple solution to this is, keep your server active. You can do this by simply pinging the server every 5-10 minutes. This will make Heroku think that your web app needs the dyno. There are many ways to implement this hack. One of the ways is by manually going to the web app on your browser via PC or phone which is stupid. The smarter way to deal with it is by writing a script that automates it. So, here is a sample code to implement it.



You can deploy this script on Heroku itself (I know right!). I have done something similar in this post do check it out.

So I hope this helps you deploy better app/API/website experiences and achieve your goals. If you have any alternate solutions to this problem, I'd love it if you shared it in the comments.

Comments

Popular posts from this blog

HOW TO USE THE DELAY FUNCTION IN C++

Hello programmers!!

Have you ever wondered how people use that effect, in C++ console applications, in which they make characters appear after a certain time. Like they say "loading..." and the cots appear one by one at a particular time interval. This effect looks very cool and makes the applications look very professional.Also see : Basic Algorithms 101 : Checking the validity of an email address (simple beginner approach)

Also see :Basic Algorithms 101 : Checking the validity of an email address (simple beginner approach) 
This 'effect' is called delay. Delay is a more professional term used for some thing that happens a little later than it is expected to happen. This is used in c++ intentionally to either create an 'effect' or to easy the procedures of the application for the user.  Like there are manyuses of the delay function.

Usually in C++ the output appears in the console as soon as it is executed. This might make it look like the application is mad…

HOW TO COPY ANY TEXT TO TURBO C++

Hello!!

Are you one of those people who is in the middle of a C++ program and you know what to do, but you don't know the syntax? So you google and find out the syntax. But in turbo c++ you cannot use ctrl+v. That might be a little pissing off. So the easiest solution would be to get rid of Turbo C++ and get a modern day compiler. But anyway, here is a post on how one can copy text from an external source into the turbo C++ environment.



Also see:Basic algorithms 101 : Checking for the validity of an email address (simple beginner approch) 
C++ is a very powerful language, but the Turbo C++ compiler is bloody ancient and very conservative. The Unix environment it has can be a pain in the neck sometimes. With the modern day compilers like C++ builder, eclipse, and stuff, programming in C++ has become so much easier. Unix environment is not really necessary to build an application. And these new compilers also have a lot of predefined functions for graphics, user interface etc.

Somet…

Basic algorithms 101 : Coin toss (unbiased and biased)

Welcome to the first post of the new series “simple algorithms”. In this series we will be dealing with simple to understand programming algorithms. If you are a beginner at programming or aspiring to be a programmer, this series is meant for you.  For convenience we will be taking python as an example for the code. In this first post, will be dealing with a very simple algorithm which is “The Coin Toss algorithm”. In case you don’t know a coin has two sides, a head and a tail. When you flip it, the outcome is either a head or a tail.  As you can see, there are only two cases. So that makes it very easy.  Some people might want to know the algorithm for a biased coin. So we will be looking at that too. The biased one is slightly trickier than the unbiased one. First, let’s look at the unbiased and then get to the biased coin.  So without any further ado, let’s just get right into it.