Thursday, February 19, 2009

Herd It on Amazon Web Services

I've spent the past month figuring out all the details and complications of hosting my Facebook music annotation game. Herd It, on Amazon Web Services. We figured out that one of the reasons why the game didn't work well when more than 5 people connected was lack of bandwidth on our server to serve the Flash components. Also, we want to be ready for when Herd It becomes the next Desktop Tower Defense so AWS seemed like a great solution. It was an omen that, on the day that I was debating whether or not to bother to try to figure it all out, a senior manager from AWS gave a talk at UCSD...

Anyway, now that I've figured it all out, I think that AWS is great. However, there are a lot of hurdles to overcome in getting it to work so hopefully this will benefit someone (maybe even me, when I forget what I did).

Step 1 - Register for an AWS account.
If you've ever bought anything Amazon, this is as simple as adding AWS to your existing account. In particular, you will need 2 of their (many) web services:
EC2 (elastic compute cloud) - this is the "cloud" of servers that does all the processing.
S3 (simple storage service) - this is the storage bucket where you will keep all your data.

Step 2 - Figure out EC2.
EC2 works as follows:
You create an AMI - an "Amazon machine image" which is basically a complete copy of the OS, programs and data of the machine that you want to run in Amazon's cloud. Imagine you wanted to backup your computer's entire hard disk so that you could reconstruct the entire system - this is what you would need. You will replicate this image on one or more of Amazon's cloud machines.

I highly recommend following the AWS tutorial. It covers everything you'll need to know and doesn't have any distracting details. You will learn how to use images that Amazon have pre-made, how to set them up, how to change them, how to save them, and how to kill them.

Step 3 - Create your own AMI
For this, I started with the most current Ubuntu AMI at alestic.com. Some nice guy (Eric Hammond) has created a bunch of basic AMI's that have nothing more than a simple OS. From here, you will need to install all the programs that you're going to need. As someone who wasn't very familiar with Unix administration, this seemed daunting but it was surprisingly easy and I like Ubuntu a lot now. For example, this page shows you that, by typing 4 lines, you can get an Apache web server and PHP running (this is all I needed for Herd It). You will also need to copy all your data onto the AWS machine using FTP or scp (for example, I copied all the PHP and Flash files that make Herd It work).

Once you've got everything on the AMI running as you want it, you'll need to bundle your AMI and copy it into your S3 bucket. Again the AWS tutorial covers all of this.

Step 4 - Elastic DNS
This was the trickiest part... If you only want to run a single instance then you don't need to worry about this. But, the whole point of AWS is to let you create many instances to power your new web app that's going to take over the world. To achieve this, I found some help from this page but there was still a bit of work to do:

Step 4a - Register your domain.
There are a million places where you can get the domain "mykillerapp.com" or whatever.
I got www.herdit.org for $9/year from NameCheap.com
(I just discovered that, of course, there is already a site a "mykillerapp.com" and that it's a sweet applied maths quiz! For the rest of this tutorial, I'll just refer to my domain: herdit.org).

Step 4b - Set up a DNS forwarding service.
The domain name of all your new EC2 machines will be something like
http://ec2-a-bunch-of-numbers.compute.amazonaws.com/ and
http://ec2-more-different-numbers.compute.amazonaws.com/
In order for these to all map to your new domain name, herdit.org, you need to set up DNS forwarding. For this, you need a DNS service provider. You domain name service may provide this but, whether or not it does, ZoneEdit is a free service that gets the job done. You will need to transfer the DNS from your domain name provider and set up ZoneEdit (or whatever DNS service you use) to handle your new domain (it may take a day or two for these changes to register).

Step 4c - Tell you AMIs to register with your DNS service
Once your DNS service is running, you want it to forward requests for your domain ("herdit.org") to the EC2 machines ("ec2-0112358132134.amazon.com", etc.). To do this, you need those EC2 machines to tell the DNS service that they are ready.

The DNS registration works using a program called "ez-ipupdate" that you can install on your (Ubuntu) AMI by typing:

sudo apt-get install ez-ipupdate

Now all you need to do is to get ez-ipupdate to run whenever you start a new instance so that you don't have to log in manually. The Spatten Design blog has a good post on how to do this using Ruby. However, since I don't use Ruby, I wrote an init.d script that you will run when the instance starts. Copy the following and save it on your AMI as '/etc/init.d/update-dynamic-dns'

#!/bin/sh

### BEGIN INIT INFO
# Provides: update-dynamic-dns
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: Update dynamic DNS on startup
# Description: Uses ez-ipupdate to send the current Dynamic IP address
# to ZoneEdit Dynamic DNS provider
### END INIT INFO

# Author: Luke Barrington <lukeinusa@gmail.com>

DYNAMIC_DNS_CONFIG_FILE=/etc/ez-ipupdate/dynamic_dns.yml
AMAZON_INSTANCE_DATA_ADDRESS=http://169.254.169.254
API=latest

# Read current instance URL from Amazon service
IP=`curl $AMAZON_INSTANCE_DATA_ADDRESS/$API/meta-data/public-ipv4/`
echo "Instance Dynamic IP Address = $IP"

SERVICE=`sed -n -e "s/^service:[ ]*/\l/p" $DYNAMIC_DNS_CONFIG_FILE`
USERNAME=`sed -n -e "s/^username:[ ]*/\l/p" $DYNAMIC_DNS_CONFIG_FILE`
PASSWORD=`sed -n -e "s/^password:[ ]*/\l/p" $DYNAMIC_DNS_CONFIG_FILE`
HOST=`sed -n -e "s/^host:[ ]*/\l/p" $DYNAMIC_DNS_CONFIG_FILE`

case "$1" in
start)
echo "Using dynamic DNS service = $SERVICE"
echo "Connecting with username = $USERNAME"
echo "Mapping IP to host = $HOST"

# ZoneEdit server name has changed since ez-ipupdate was last built
if [ "$SERVICE" = 'zoneedit' ]; then
eval "ez-ipupdate --address $IP --service-type $SERVICE --server=dynamic.zoneedit.com --user $USERNAME:$PASSWORD --host $HOST"
else
eval "ez-ipupdate --address $IP --service-type $SERVICE --user $USERNAME:$PASSWORD --host $HOST"
fi
;;
*)
echo "Usage: update-dynamic-dns start"
;;
esac


You will also need to create a file at '/etc/ez-ipupdate/dynamic_dns.yml' (or whatever you call it in the script above) that contains the following:


# service should be one of the services supported by ez-ipupdate.
# Possible values: null ezip pgpow dhs dyndns dyndns-static
# dyndns-custom ods tzo easydns easydns-partner
# gnudip justlinux dyns hn zoneedit heipv6tb
# (The above list is from man ez-ipupdate)
service: zoneedit
username: YOUR DNS SERVICE USERNAME
password: YOUR DNS SERVICE PASSWORD
host: YOUR HOST NAME (e.g.,
herdit.org)


Finally, you can run the update-dynamic-dns script by typing:

./etc/init.d/update-dynamic-dns

To register this init.d script to run automatically at startup, use this command:

update-rc.d update-dynamic-dns defaults

Now, as soon as the EC2 machine boots (well, after a few minutes), it should register itself with your DNS service and tell it to send requests for "herdit.org" to its address (e.g., ec2-123456789.amazon.com). The cool thing about ZoneEdit (or any DNS service that has "round robin" DNS) is that, if multiple machines all register to the same host, the DNS service will send requests to each one in turn. This will spread your millions of users across all the AMIs that you run.

At this stage, you will want to bundle up the AMI again. Now you are ready for Step 5...

Step 5 - Try and take over the world
Run hundreds of instances, pay thousands of dollars to Amazon, get millions of users, sell your site for billions of dollars.



Notes and next steps
Now that I''ve set all this up, we are testing Herd It to see how it can handle the load of many simultaneous users. Herd It users a Java server to coordinate everything (via XML events) and saves all the info in a MySQL database. These are both still running on my local server. I plan to put them on AWS sometime as well and I expect that this tutorial will help with that.

There are apps out there that can monitor your site's traffic to automatically create or kill new instances based on your traffic but, for the moment, I will be monitoring it manually.


Now, after all that work, why not go and play Herd It?!

Thursday, December 11, 2008

Nöjeströtta älskar nya tal

News of my talk at the Math Club last month has been reported in Dagens Nyheter, "the New York Times of Sweden". Check out the article by Caroline Hainer - you can even see a picture of my arm pointing to some nice math!

In case your Swedish isn't as good as mine, here's the Google translation.
Note how I am described as a " long male, redheaded researcher" and Conor Deasy is now Conor PRESIDENT!


My next academic talk will be delivered in the style of the Swedish chef...

Wednesday, November 5, 2008

Math Club

I'll be giving a talk on "Machines that Understand Music" at the LA Math Club on Sunday, November 19, 2008. If you're in Hollywood, come along and meet all the musos and industry types that I hope will show up.

The Math Club is organized by the genial Roni Brunn, aka "the Girl From". Previous speakers have included Futurama's David X. Cohen and heaps of smart profs. I'm hoping to match the former for smarts and the later for humour...

Here's the abstract:

Humans can identify that a radio station is playing country music in less than one second (and switch channels!). Although the amorphous details of music and the emotions that it evokes in us are sometimes subjective, there are many concepts (e.g., instrumentation, genre, tempo, ...) that most listeners agree on. Given these statistical regularities, it should be possible to build a machine that can analyze and understand many aspects of music.

I will talk about and demonstrate a computer audition system that understands music. Using signal processing analysis of audio waveforms and machine learning models to identify patterns in the signal, my "musical search and discovery engine" goes beyond artist and song name search and can find "funky music with a horn section for a party" or "jazz saxophone for romancing". The system can also associate new music with relevant semantic tags, creating automatic record reviews. This musical search and discovery engine has many applications for personalized discovery and distribution of all music online.

Finally, I will explain how the data used to train the computer audition system to understand music is collected using an online music annotation game that is about to be launched on Facebook. Bring your laptops and we can all play together!

iLuke API

In my ongoing quest to:
a) get my Facebook music annotation game "Herd It" running and
b) master all web technologies,
this week, I taught myself how to write AJAX apps.

Despite all the buzz I'd heard about this, AJAX is really just one JavaScript function call: XMLHTTPrequest. Basically:
HTML web page has JavaScript
JavaScript has XMLHttpRequest object
XMLHttpRequest object sends requests to a server script (e.g., PHP)
Server responds with XML info
XMLHttpRequest updates to the DOM as it gets new info.

Easy, right?!

I've used this to integrate the iLike API as the music player for Herd It. Now I can play all the (30-second clips of) music we want and not get sued!

Monday, September 22, 2008

Cool Stuff at ISMIR (contd.)

Tuesday began with an excellent panel discussion on commercial applications of MIR work featuring Markus Cremer (Gracenote), Etienne Handman (Pandora), Elias Pampalk (Last.fm), Anthony Volodkin (Hype Machine) and Brian Whitman (Echonest). Seems like there actually is money to be made out of all this!

Doug Eck and Thierry Bertin-Mahieux presented more great work, this time along with Pierre-Antoine Manzagol. On the Use of Sparse Time-Relative Auditory Codes for Music. Using a greedy gammatone decomosition of music, they were able to represent a spectrum as a sparse, spikey sequence of basis kernels. Then they went further and started trying to learn the kernels for music (ala Lewicki's work on speech and natural audio). Periodic but not sinusoidal, long time kernels seem to be what work best but there's more to come I bet...

Charlie Inskip had a fascinating stories to tell about his experiences of 20 years managing bands that toured the world. One of his tasks was to try to get their music into film, tv and ads. Now he's following an academic path (alas, "everyone gets tired of staying out in bars and clubs til 4am, five nights a week") and is interviewing music supervisors (the people who find the right music for film etc.), film makers and record label people to find out about thier process of using words to describr the type of music they're looking for. Music, Movies and Meaning: Communication in Film-Makers’ Search for Pre-Existing Music, and the Implications for Music Information Retrieval. Right up my street.

Bryan Duggan was the only other Irishman I could find at ISMIR. He had a crowd-pleasing demonstration of his traditional Irish music identification and retrieval system that could listen to his flute playing (realtime, noisy environment), transcribe it, remove ornamentations and match the tune to a database of traditional reels, jigs and hooleys. Nice to see good MIR work happening in Ireland.

The always excellent guys from the Music Technology Group at UPF (give me a job!) showed how to construct structured taxonomies from unordered folksonomies: The Quest for Musical Genres: Do the Experts and the Wisdom of Crowds Agree?

On Wednesday night, there was an excellent concert featuring the Princeton laptop orchestra, led by the crazy Perry Cook and cool Ge Wang. As well as developing a new language for strongly-timed music synthesis and analysis (ChucK), building cool new interfaces for music and composing all this crazy music, these guys have also developed a highly-viral new iPhone app - the Sonic Lighter.

As well as a very well-attended demo of my music annotation game, Herd It, Thursday had cool demos of dancing robots, Oscar Celma's geo-music search engine that lets you create playlists from paths across a globe and Frank and Paul's excellent semantic search engine.

Tuesday, September 16, 2008

Cool Stuff at ISMIR

I'm at the International Conference on Music Information Retrieval (ISMIR) in Philadelphia where I'm presenting 2 papers:
Combining feature kernels for semantic music retrieval,
5 approaches to collecting tags for music (Doug Turnbull is the first author)

Our entry in the MIREX auto-tagging competition came first in a competitive field of eleven, which is pretty cool.

Also, we're going to be giving the first real-world demo of our upcoming music annotation game "Herd It".

However, tons of other people are doing lots of cool stuff here. Some highlights for me so far are:

Paul Lamere and Elias Pampalk's tutorial on collecting tags for music.
This was another awesome overview that included:
cool work on a Sun, in-house semantic search engine with a really nice interface where you could rescale tags in a cloud to change your query (I've been thinking about this for ages but they've actually done it!)
distance between semantic profiles built from last.fm tags powering artist, tag and user similarity and how this can be used to build a structured taxonomy from an unstructure folksonomy.
A survey of 200 users (conducted by Paul and to be published in his upcoming JNMR article) that showed that users prefer music recommendations based on similarity than collaborative filtering.
Paul's even set up a website - SocialMusicResearch.org - where you can find the slides and more.

Magno & Sabel's paper on perceptual similarity using various music models that showed that MFCC+GMM-derived similarity was preferred to recommendations from last.fm or Pandora! (and I think that our system works even better than that)

Masahiro, Takaesu, Demachi, Oono and Saito's work on uses a shoe-sensor to detect "steps per minute" and this communicates with the runner's iPod to play music with the same beats per minute. The presentation included an hilarious video of a determined Japanese researcher testing the system by running on a treadmill but still keeping it formal in shirt and tie! Check out figure 5 in their paper.

Mark Godfrey and Parag Chordia's paper on improving MFCC+GMM modelling by detecting and removing "anti-hubs" (and thereby, also removing hubs) by finding GMM components that are very distant from all other components.

Matt Hoffman, David Blei and Perry Cook's work on hierarchical Dirichlet models of music. I think I finally understand HDPs although I still don't fancy trying to train one...

Saturday, September 13, 2008

Tetrion at the Burn

Among the many, many awesome sights at this year's Burning Man, my favourite has to have been the Tetrion by Jim Abrams - a gigantic, interactive Tetris game.














Imagine the sight of huge tetris blocks glowing from far across the playa. Now you climb a ladder and get on top of one block where each section is 10 feet long - so the 4-block in the centre stands 4-storeys high. And then, the ultimate delight, there is actually a live, playable game being projected onto two sides of the center block! 2 minutes to get as many lines as possible. It was art and fun and overall genius.

And, of course, there was a massive rave there on the night of the burn...

Check out me not doing very well, despite the heckles!


Tetris Installation at Burning Man 2008 from Damien O'Malley on Vimeo.