Heroku: Depriving Your Free Dyno of Sleep

I’ve been using Heroku more and more, but not for anything really valuable to me. I mostly use it for hosting one-off projects that are low traffic. A lot of times, it’ll take 30 seconds or so for the site hosted on Heroku to respond, while the Heroku dyno is woken up. If your site goes without any traffic for a certain period of time, it will go to sleep.

Heroku does this to save server resources, which is a logical thing for them to do. Sometimes though, I don’t want to wait to see my site, even if I only have a free account.

I’ve seen a lot of tutorials on how to do this with Ruby, but no language-agnostic way of doing it. I also haven’t seen any way of doing this with PHP. There’s 2 methods you can use to keep your site from going to sleep.

1. UptimeRobot

This is the easiest and quickest way to keep your app awake, and is language-agnostic. UptimeRobot is a free service that monitors your sites. When you’re adding a new site to monitor in UptimeRobot, make sure to set the monitor type to “HTTP(s)”. UptimeRobot will check to make sure your site is up every 5 minutes, which will prevent your site from sleeping.

2. Heroku Scheduler

This method is a little more involved, but is probably the Heroku-preferred method.

This topic has been covered many times, but always seems to focus on Ruby apps. So here’s something that will work for everyone.

While you’re viewing your app resources on the Heroku dashboard, click the “Get Add-ons” link. Add the Heroku Scheduler add-on to your app, it’s free.

Go back to managing your app’s resources on the Heroku dashboard, then click “Heroku Scheduler Standard” to manage the Heroku Scheduler for your app. Add a new job, and set the frequency to Every 10 minutes. For your task, enter curl -I http://your-app-name.herokuapp.com. This will fetch HTTP response headers from your app, using Curl, every 10 minutes.

It should be noted that method 2 could potentially cause you to have a balance to pay at Heroku. That’s because Heroku Scheduler has Dyno Hour Usage.

So, there’s two options that everyone can use to keep your Heroku apps from sleeping, no matter what language your app is written in.


How-To: Continuously Monitor System Load And Track Down Resource Hogs

I’ve been using Linux for 12+ years. In all that time I’d never used, or even heard of, a program called tload. tload is similar to the top program, in that is sits running in your terminal, showing you the current system load.

tload gives you a basic text “graph” of the current system load average. It uses data from /proc/loadavg to operate. If you’re really into how tload operates, check out this post by Baron Schwartz.

I’ll usually open up a connection to a server via SSH and just let tload run for a while. If the load gets to be too high, I’ll usually use top to see which processes are sucking up all my resources, processor resources typically. I usually just run top like so:
top -H

After that, there’s a couple commands that I use to find how many threads are running under a specific user or under a specific service. To find the users (5 in this case) with the largest number of threads running under them, run the following:
ps aux | awk '{print $1}' | sort | uniq -c | sort -nk1 | tail -n5

To get the processes with the most threads running under them, run the code below. It’ll also show the top 5 processes. Change the tail -n5 part to tail -n10 to see the top 10 instead.
ps aux | awk '{print $11}' | sort | uniq -c | sort -nk1 | tail -n5

That’s really all I use when I encounter extremely high loads, whatever the reason may be. They should work nicely for you too. tload comes bundled with pretty much every linux distribution in existence. And from the info you gather with top and the awk commands above, you can easily narrow down what the issue is. Figuring out why that issue is happening in the first place is an entirely different story though.

There’s one other really good method involving top that is discussed at Joomlaperformance.com. The code example they give is top -b -i -n 20 >> ./top_procs. It basically saves information from top into a file, top_procs, and runs the top command 20 times. They describe it better than I do.

What that does is tell TOP to run in “batch” mode (not look for any user input), show only running processes, loop 20 times, and append the output to the file /top_procs. Run that command when you are experiencing a high server load. Then you can view the contents of that file to tell you some information.

So that’s that. Should be relatively easy for you to track down what’s causing high load on your vps, server, desktop, or whatever other linux system you use.


How-To: Full Featured Time-Lapse on Android

I’ve used Lapse It for a long time. I didn’t use it often enough to buy the Pro version though. I discovered an app named Droid Timelapse the other day, and I love it. Droid Timelapse is developed by Neximo Labs.

Droid Timelapse has a really nice user interface. It’s also got a lot of features that you don’t get in the free version of Lapse It.

If you want to take a time-lapse photo now and then, I’d definitely suggest Droid Timelapse. Lots of features, it’s free, has no ads, and has awesome reviews on the Play Store.

There’s a pro version of Droid Timelapse as well. It allows recording with the screen off and allows you to set custom capture rate intervals, up to 24 hours. It’s tempting to buy the pro version just to support development, but I really don’t use the app often. Maybe a few times a year when there’s some cool clouds rolling overhead.

I’ve included a gallery of screenshots below, but you’ll have to be viewing the full article to see them, they won’t show up on the front page.
Continue reading “How-To: Full Featured Time-Lapse on Android”


How-To: Monitor VPS Status From Heroku

I built and released this tool to monitor the status of your SolusVM client API-enabled VPS. It’s really easy to host it on Heroku, which is great since we don’t want to host the monitoring site on the VPS we want to monitor. You’ll need a Heroku account if you don’t already have one, the free account will do just fine.

Before we begin, you should probably install the Heroku Toolbelt. You’d also benefit from reading through some of the Heroku Dev Center articles. This one about deploying to Heroku with git is probably the most relevant for what we’re doing here.

You’ll need a terminal/command line for deploying to Heroku with git. A really great resource for new git users is Git Immersion, just click the green “Start Git Immersion” arrow to get started with git. Anyway, the 5 steps that follow assume you’ve created a Heroku account and have git installed and working.

  1. Fork tlongren/vps-status on GitHub and make a local clone.
  2. Install the Heroku Toolbelt and login to Heroku with the command “heroku login“. Enter you username and password to login with the Heroku Toolbelt.
  3. Create a new app on Heroku either through the web interface, or with the command “heroku create“. If you do it with the command line the app name will be shown to you, see here.
  4. Open a terminal and go into the folder that you cloned your fork into and run the command “heroku git:remote -a heroku-app-name“. That will add a remote named “heroku” to your local clone.
  5. Now, while still in your local clone folder, run “git push heroku master” to push your app to Heroku. If your app is named “heroku-app-name”, you can access your app at http://heroku-app-name.herokuapp.com.

That’s all there is to it. It might not seem simple at first glance, but it really is. To make changes, just edit the files in your local clone and commit those changes with git. Then run “git push heroku master” again to push the new code to Heroku.

Make sure you don’t send your changes back to GitHub, unless you’ve got private repositories. If you do a push to GitHub, your API key and hash will be accessible by the public, which isn’t something you want. Instead, you could either make a private repository at BitBucket or create a private repo using Dropbox like I do. The DropBox option is only reliable if you’re the only one editing the code, and if you’re only making changes from one machine at a time.

Let me know if you have any issues or think I’ve missed something.


How-To: Install/Update Custom Recovery on Nexus 4 (Mako)

I use TWRP (Team-Win Recovery Project) as a custom recovery. It’s easy to use and, as the name suggests, has a nice touch interface. TWRP supports a bunch of devices, including the Nexus 4 (Mako).

Here’s the full description straight from the TWRP site:

Team Win Recovery Project 2.4, or twrp2 for short, is a custom recovery built with ease of use and customization in mind. We started from the ground up by taking AOSP recovery and loading it with the standard recovery options, then added a lot of our own features. It’s a fully touch driven user interface – no more volume rocker or power buttons to mash. The GUI is also fully XML driven and completely theme-able. You can change just about every aspect of the look and feel.


Installing TWRP on your Google Nexus 4 is pretty simple. The TWRP site has good instructions, but I always forget how to update when a new version is released. And checking the actual TWRP site was something I didn’t think of doing, because I thought I had installed TWRP through a separate tool (which I did).

So, the suggested method for installing TWRP to your Google Nexus 4 (and the method I use) is really straight forward. You’ll need root.

  1. Install GooManager from the Play Store and open it up (grant it root permissions).
  2. Select the menu and then tap “Install OpenRecoveryScript”, then tap “Yes”.
  3. Make sure the filename says “mako” in it somewhere, this ensures you’ll get the Nexus 4 recovery.
  4. Tap “Yes” again.
  5. That’s it, TWRP will be downloaded and installed automatically.

Below are some TWRP2 screenshots, taken straight from the TWRP website. If you’re interested in contributing to TWRP, you can check out their project on Github.