Cheyne Wallace

Web Developer & General Unicorn

Follow Me

Heroku Postgres Row Limit Email Notifications

Heroku Postgres Row Limit Email Notifications

05/14/2013

So, you’ve got a side project hosted with Heroku, you only have basic database requirements so the 10,000 row limited Postgres dev plan seems like a good choice and could possibly be a free alternative for a descent amount of time until you need to upgrade.

Heck, at $35 a month per dyno, you need to try and save some money somewhere, right?

Take for example one of my side projects, it’s called NoteShred.com. It allows you to send password protected, encrypted notes to people over the internet with a unique URL and have the note automatically destroy its self after it’s been read.
The beauty of this application is that it is constantly deleting rows from the database every time a note is “shredded“, so a 10,000 row count is actually a descent amount of space for this application.

The problem is that 10,000 isn’t a huge number, and all it takes is one big spike of traffic and you’ve hit the limit.
Heroku provides a basic alerting service that will tell you once you’re at 7,000 records and again once you’ve hit the limit. You will have 24 hours to get your row count back under the limit before you will lose write access to your database. (Thanks to @hgmnz and @ctshryock for pointing this out)
More Info Here.

Unfortunately, This is not configurable and the cut off may come at a bad time, say if you’re on holidays or are not able to dive in and trim back the records before this 24 hour window expires.

The 7,000 row alert is nice how ever not terribly useful for applications like NoteShred where you have a slow creeping database and the difference between 7,000 records and 10,000 records is a large gap in time.
I am most likely going to disregard the 7,000 row alert email because I still have 3,000 left, the next email would be informing me that I have hit the limit and have 24 hours to get it back under control.

A configurable threshold with a series of alerts leading up to the cut off point would be more useful, or even just an alert closer to the limit, say at 9000 rows.

You want to keep an eye on this row count, you can do so using the Rails built in Mailer and a basic Rake task with this simple solution and be alerted when your application reaches a threshold nearing that 10,000 mark. You can easily customize this rake task to alert you at times when feel it’s more useful than the standard 7,000 and 10,000 alerts.

In a nutshell, this will:

  1. Check your row count every hour
  2. Email you if you’re over the threshold

Read More

Ruby on Rails Performance

Ruby on Rails Performance Tuning

04/14/2013

For something that is touted as being an “easy” to use framework, Rails is a pretty complex beast. Over the years it has progressed from a seemingly simple framework that “anyone” can learn to the intricate collection of add-ons, gems and extensions that make it the power house it is now.

Optimization is an overlooked aspect of Rails development that often isn’t covered in the tutorials you find online.  With the sheer simplicity of snapping in a few gems, throwing together some quick Active Record queries, pushing to Heroku and forgetting about the rest, it’s all too easy to find your application running slow and sluggish, before long you need to backtrack and try to figure out what exactly you did that caused the slow down.

Writing better, leaner code is often the answer, although this article isn’t a coding guide, instead I’m going to list a few simple things you can do to get better performance from your application.  These might not be applicable for everyone, but merely some tricks that iv learned that have helped me squeeze a bit more performance out of some recent projects of mine. Read More

Sending Private Information Over The Web

Sending Private Information Over The Web

04/05/2013

If you read this blog, then chances are you’ve had to at some time send passwords, server details, social security numbers or any other number of sensitive bits of information over email or instant messenger.

Don’t deny it, you know you’ve done it. I know I have. It’s not something to be proud of, but it’s a necessary need sometimes.
It’s not always feasible to try and talk your client through setting up encrypted email for a one time transfer of a password or a social security number. Read More

ga-event-tracker

jQuery Google Analytics Event Tracking Using HTML Attributes

03/07/2013

Setting up Google Analytics event tracking can be a pain sometimes. Often you may want to track a dozen or so clicks on a page that doesn’t make and post backs so you end up with a bunch of spaghetti JS, wiring up events and click handlers.

It’s just messy. So I write this little bit of script that allows you to enable events to be fired on clicked elements with simple HTML attributes.
Read More