Category: Tools

  • Unicorn vs. Passenger on Heroku

    I’ve been hosting my flagship SaaS app on Heroku since 2008. Overall it’s been a stable, if a bit overpriced, platform. Over the past year, however, I’ve been experiencing mysterious performance problems. The app runs fine for several weeks. Then suddenly I begin receiving exception reports about certain methods not being found on certain objects. Restarting my dynos would fix the problem for a few days or a few weeks, but eventually I would start getting errors again. It definitely felt like some sort of memory issue.

    After profiling the app and discovering nothing, I installed the Librato dashboard which offers a basic line graph of memory usage across dynos. I began noticing a correspondence between this line getting above 200 MB and my app throwing errors.

    Each dyno on Heroku theoretically has 512 MB of memory. I was running my app on Unicorn with 2 processes per dyno. I wouldn’t expect problems unless each process exceeded 256 MB. I was confused why I was seeing problems at just 200 MB of usage. True, the line would continue creeping up if I didn’t restart my dynos, and would eventually exceed 256 MB which would trigger an auto-restart of the dynos. But this took a long time to happen, and in the meantime my visitors were experiencing a slower app and/or outright errors.

    I spent several days attempting to identify where the app was leaking memory. Why did the memory usage line continue climbing? I tried various techniques to identify the problem but was unable to reproduce the leak on my local system. Eventually I decided a different tactic was necessary. Heroku has been recommending Puma as an alternative to Unicorn for a while now, so my first thought was to switch to Puma which uses threads for concurrency instead of processes. However, my app runs under MRI, not JRuby, so I wouldn’t necessarily be able to take advantage of those performance gains. Instead I opted for Passenger which now runs on Heroku.

    The results have been beyond what I expected. My memory usage line is now perfectly straight. No increase over time. No eventual errors and dyno restarts due to overconsumption. What Passenger is doing under the covers is spinning up new processes during high traffic periods and killing them during low traffic periods. My app has been running for 3 months now and I haven’t had to restart any of my dynos, nor have I encountered any performance issues with the app. Success!

    I can think of two explanations as to why Passenger fixed these problems: first, perhaps Unicorn itself was causing my app to leak memory in a strange way. Second, and more likely, Passenger’s built-in ability to spin up processes on demand is keeping memory leakage to a minimum due to processes regularly being refreshed. Regardless of which explanation is correct, I’m happy the app is no longer throwing errors at inconvenient times. Most importantly, my users are having a far more consistent experience. If they’re happy, I’m happy.

  • Moving from Gmail to FastMail

    It was January, 2005. Google had launched its invitation-only beta release of Gmail just a few months ago. The initial storage capacity of 1 GB was dramatic, with its closest competitors offering an anemic 15 or 20 MB. My beta invite had finally arrived and I was in the process of signing up for an account. The excitement was palpable, “It’s email… but by Google! 1 GB of space… who could possibly use that much? And the web interface is so fast!”

    Jump ahead ten years to January, 2015 and you’ll find me ditching my Gmail account in favor of FastMail, a move that has been long overdue. “But why ditch Gmail?” you may ask. I have my reasons.

    First and most importantly, I’ve come to the conclusion that I want my email to be reasonably private. I just don’t like the idea of Google scanning my email and pulling out little bits of information about my personal life and buying habits. The speed, storage space, and features that Gmail offered used to offset the privacy disadvantage in my mind, but they don’t any longer.

    Gmail used to be fast. Really fast. It’s not anymore. Don’t get me wrong, it’s still fairly zippy, but it’s definitely slowed down over the years as the interface has grown increasingly more complex and bloated. I’ve found FastMail to be true to its name: it’s just as fast as Gmail. And the web interface is simple and non-bloated. I like simple.

    Another change in Gmail that really bothered me was the introduction of the social tabs. I know these tabs can be disabled now, but I don’t like the way it was initially forced on us. And I definitely don’t like the impact it had on legitimate email marketing. The average user isn’t going to notice their email is suddenly getting filtered into separate tabs, much less figure out how to turn it off.

    When it comes down to it, I’d rather pay FastMail for an equal amount of storage space, reliability, and speed as Gmail. I no longer have to deal with the ads, the privacy violations, or the sudden feature changes. Don’t fool yourself: you’re already paying for a free service like Gmail, just not with cash. You yourself are the payment: a consumer to be analyzed and sold to. And Google is very good at doing just that.

    And hey, Marco Arment recommends FastMail so it’s got to be good, right? Here’s what he says about the benefit of having an email address ending in a domain name that you control:

    For something as important as email, I’ve never trusted everything to a proprietary provider. My email address has never ended in someone else’s domain name, and has never been hosted in any way that would preclude me from easily switching to another provider.

    The transition to FastMail was very smooth. It was just a matter of modifying a couple of DNS records and using FastMail’s excellent IMAP import tool to transfer a decade’s worth of email from Gmail (this did take a few hours). I’m still able to check my FastMail account from my iOS devices, and I use their web interface on my desktop through a Fluid app.

    If you’re looking for a new email provider comparable to Gmail, I can recommend FastMail without hesitation.

  • Muut for Octopress

    Muut (formerly Moot) is a lightweight, customizable commenting system. Octopress is a static blogging framework built on Jekyll. Mix the two and you have a delicious recipe enabling visitors to comment on static blog posts without having to resort to a database.

    My Octopress plugin makes this integration super easy. Install the plugin, edit 2 files, and you’re off to the races. You can even control which blog posts can be commented on.

    If you’ve never worked with Octopress before it’s well worth a look see. I use it on a couple of my blogs (The Teascript Blog and The Distance Learner) and have been very happy with the performance. Nothing beats static HTML for raw speed.

  • Announcing youtube_tags extension for Radiant

    A recent project required the latest YouTube videos from a specific user to be listed inside a Radiant page. There wasn’t an existing extension that did this so I built my own. youtube_tags is based on the excellent twitter_tags extension. It enables inclusion of YouTube videos within Radiant pages using a series of Radius tags. It leverages the youtube-g gem to pull data directly from the GData API.

    For example, this is how you would display linked titles for the top 5 videos from my YouTube account (“pelargir”) using the Radius tags provided by the extension:

    <ul>
      <r:youtube user="pelargir">
        <r:videos count="5">
          <li><a href="<r:video:url />"><r:video:title /></a></li>
        </r:videos>
      </r:youtube>
    </ul>
    

    To install in your own project, visit the youtube_tags profile in the Radiant extension registry.

  • Spreedly extension for Radiant

    I built the original Spreedly extension for Radiant a couple of years ago. It’s a nice little package that makes it really easy to integrate Spreedly’s subscription payment system with your Radiant site. You can choose which pages to require a subscription to view, manage subscribers from the admin backend, and so on. It’s long overdue, but I finally got around to upgrading the extension to work flawlessly with Radiant 0.9.1. Check it out and have fun.

  • Learn about A/B testing at raleigh.rb

    I’ll be presenting on A/B testing at tonight’s raleigh.rb meetup. As developers, we use tools like RSpec and Cucumber to verify that our application is functional, but how can we verify that the layout of our home page is user-friendly? How can we determine the ideal size for our signup button? How can we maximize throughput to our signup form? A/B testing is an easy and compelling way to increase the effectiveness of our web applications. Join us tonight to learn how to leverage A/B testing in Ruby using several popular tools.

  • Amending git commits

    Git is a wonderful SCM with some very powerful features. But as a programmer, it’s very easy to aquire a rudimentary working knowledge of Git and never learn anything more. For example, how would we fix our repository if we committed the wrong piece of code? What if our commit had an error in it? How do we fix things without reverting or introducing a second commit?

    It turns out this is very easy to do. The latest versions of Git have an amend command. Amend lets us alter the last commit we made. All that’s necessary is for us to arrange our working directory the way we want the last commit to look and then execute:

    git commit --amend
    

    This will update the most recent commit based on the state of our working directory. For example, say we changed our README file in the last commit and accidentally introduced a typo. To fix the last commit, we would edit the README again, git add the change, and instead of running git commit which would create a second commit, we run git commit --amend which patches the last commit. This can be repeated as many times as necessary.

    Note that rewriting history like this can have serious implications if you’ve already published the most recent commit. But if you’re the only developer using the repository, or if you haven’t published yet, this can be a great way to fix minor mistakes without introducing an entirely new commit.

    You can read more about amend in the documentation.

  • Quick ‘n dirty Lindo step for Cucumber

    Lindo is great for verifying your Rails tests by opening the HTTP response body in a browser for inspection. It works with most popular testing frameworks including Test::Unit and RSpec. But what about Cucumber?

    It’s actually pretty easy to build a custom Cucumber step that triggers Lindo from your cukes. First, install the Lindo gem in your Rails app. Then create features/steps/lindo_steps.rb and insert this code:

    Then /^render the current page$/ do
      extend Lindo
      vr
    end
    

    The step can be named whatever you like best, but “render the current page” works for me. To trigger Lindo from within your cukes, simply reference the step like so:

    Given I am logged in
    When I follow "some link"
    Then render the current page
    

    When Cucumber hits the last step, the default browser window will open and the contents of the page at that step in the scenario will be displayed. This is very handy when troubleshooting why a specific scenario is failing. It’s also useful for determining what you should be testing for on a given page.

  • WordPress upgrade was moderately easy

    I recently upgraded my blog to WordPress 2.9.1 and I’m very pleased with the results. The upgrade itself was very straightforward. It was just a matter of replacing the correct files in my project. I have my project checked into GitHub so I was able to immediately see what had changed. I also had a safety net in case I wanted to back out of the upgrade.

    One nice benefit to upgrading was that I’m now able to leverage the Syntax Highlighter plugin. It does nifty stuff like this:

    class HelloWorld
      def say_hello
        puts "Hello world!"
      end
    end
    HelloWorld.new.say_hello
    

    If you run a WordPress blog, I would definitely recommend checking it into some sort of source control. Also, being able to run the blog on my development system is very beneficial. I was able to verify that the upgrade hadn’t borked my layout before making everything live. I use Apache to serve it up locally.

    What platform do you use for blogging? What do you like about it?

  • Delete/backspace doesn’t work in nano

    If you’ve ever performed a fresh install of Ubuntu, you’ve probably noticed that the delete/backspace key doesn’t work correctly in nano. This is frustrating, but easy enough to fix.

    This problem also occurs quite frequently for me when logging into a remote server. For example, a default Slicehost instance usually suffers from this behavior.

    If you truly want to understand what causes the problem, check out this article.