Long Noodle: Heroku Long Polling with Node.js, jQuery, Rails, Cross Site

June 24, 2011

I like using servers that manage all the layers except the one I care about: the application. I was using Rails grid servers at Media Temple for awhile but they shut those down. More recently I’ve been using Heroku.

I was thinking about ways to get data into and out of Spongecell’s dynamic ads. A few dozen rails unicorns would quickly be overloaded. A CDN is great for pushing cached content to millions of viewers but what if I wanted live data or live interactions? One way to get instant data is using long polling which is an http request that is left open until data arrives.

Heroku’s new Cedar stack is perfect for this! You can even use their old Rails stack for standard web requests and then use Cedar for lighter connections.

Try out Long Noodle for Long Polling and fork it on github.

Long Noodle GET requests subscribe to a key and POST requests broadcast for a key using token authentication. The key is simply the path of the url just like S3.

In the setup above imagine the web server is hosting a panel conversation between 10 famous astronomers. Anyone can listen in. The web server displays the conversation when you first visit the site. To get updates a long poll is opened to the Long Noodle server. The astronomers are authenticated and post their wise words to the web server which in turn passes to Long Noodle to trigger client updates.

Long Noodle is very lightweight. Messages are not persisted and clients have no guarantee they receive every message, just the most recent message. This is similar to Apple Push Notifications.

As a bonus, Long Noodle works cross site using javascript callbacks so you can set it up anywhere.

UPDATE: I did some quick load testing of Long Noodle on a free server at Heroku. For returning data immediately Node was able to pump out 1300 requests/second! For long polling errors started to occur once passing about 500 concurrent requests.


Use Your Existing Newrelic Key on Heroku

June 9, 2011

We had an existing Newrelic account and wanted to track some other apps on Heroku. I thought getting our Newrelic key into the Heroku apps would be the easiest solution. Here’s what I did.

Add this to Gemfile:

gem ‘newrelic_rpm’

 

Add a Heroku config:

heroku config:add NEWRELIC_LICENSE_KEY
=YOUR_KEY

 

Add this to environment.rb or a lib somewhere:

if ENV['NEWRELIC_LICENSE_KEY']

NewRelic::Control.instance['license_key'] = ENV['NEWRELIC_LICENSE_KEY']

NewRelic::Agent.agent.shutdown

NewRelic::Control.instance.start_agent

end

 

I have a feeling I didn’t do this the easiest way but it works. Or that I’m breaking some terms of service.


Resurrection

June 7, 2011

This blog has been neglected. Let’s resurrect it!

Did you see this recent post about a hot display advertising company? There’s some good quotes in there.


Follow

Get every new post delivered to your Inbox.