Article Userscript.org and Amazon S3

Published

Sun, 19 Nov 2006

Tags

s3 userscripts

5 comments


subscribe

While I've been playing with S3 for many months now, I've yet to rack up more than a few penny's in costs. After reading how smugmug saved hundreds of thousands using S3, I decided to fix a problem I had.

Due to lack of sleep for both myself and Britt, we had been serving static content via mongrel. (gasp!) In the past 2 months mongrel has fielded over 24 million requests (serving 307GB). Having mongrel serve static content (the site's media/css/javascript) meant a slowdown in serving up the dynamic pages. Luckily the transition to S3 serving all of that content was quick and painless.

If you use zoneedit, choose edit zone, then the domain, aliases (CNAME), then add static as an alias for userscripts.s3.amazonaws.com

Step 1: setup a cname: a quick check of Virtual Hosting of Buckets showed that all one has to do is setup static.userscripts.org to be a cname/alias to static.s3.amazonaws.com

Step 2: setup s3: create a bucket on S3 with the name of the domain you just setup as an alias

Using S3Fox Organizer for Amazon, you click the new folder button and type the domain name, while you can use s3sync.rb, bitbucket (python), or ... I prefer using this extension so I can see what is happening. S3Fox's UI treats a bucket as a directory and treats buckets and keys as if you only access them via s3.amazonaws.com/bucketname/key not bucketname.s3.amazonaws.com/key or using the cname trick we setup in step 1 - don't let this confuse you as all the methods of getting to the data will still work.

Step 3: put your content on s3: pushing your data to S3 and make it world readable.

Since userscripts is a rails app I copied the public directory, deleted a few files (dispatch.*, robots.txt, ...), removed all the .svn directories, then used S3Fox to copy the files up. By default the files are private, so clicking properties on each folder (images, stylesheets, javascripts) and setting it to be readable by the public (recursively -- apply to subfolders)

Step 4: use your new domain, by now all of your javascript, css, and images should be accessible by prepending existing urls with static. After testing that everything is working, you have only to change your stylesheet links, javascript sources, and image tags.

Updating application.rhtml to point to the right css/javascript is easy, then a quick grep through the views for image tags completed the transistion.

Results: The above took about 15 minutes to complete. After committing the changes I asked a few friends to kick the tires. I would have a friend browse userscripts for a few minutes with the latest changes (using S3) or the previous svn revision (not using S3), then after a few minutes change back. The results were unanimous with S3 providing a noticeable speed up. Ahh success!

Sure we could have setup apache/lighttpd to serve static content, probably in a roughly equivalent amount of time. I'm currently planing to copy the userscripts themselves to S3. My reason - peace of mind - if something were to happen to our server, having the content still available while the backups are restored would be beneficial. Also doing a HEAD request against a script to see if it has changed within greasemonkey (and recommend updating) might be possible. S3 means flexibility - at a cost - and right now that cost is cheaper than buying more hardware as the site grows.

BTW, it took longer to write this post than it did to do the conversion.


 

Comments

Good job Jesse, userscripts.org definitely feels faster to me.


The only small problem is that the userscripts all seem to have new dates (either November 19th or 20th).


Also on an (presumably) unrelated note - unrated scripts seem to be ranked highest when it comes to "popularity" so the popular page, and the popular block in the sidebar are completely fubared.

Mon, 20 Nov 2006

Have you seen config.action_controller.asset_host? I used it to do the same thing, except you don't have to go around changing all your links, and you can then turn off using S3 with a one-line change:


http://casey0.com/archive/2006/October/How_to_serve_the_rails_public_directory_out_of_S3.html

Tue, 21 Nov 2006

prozeco

Hi,


good to see more and more people using S3 for things like that. For now I was just able to see images on userscripts.org that you host on static.userscripts.org, or did I miss something?


~proz

Wed, 22 Nov 2006

Joe

Just to let you know, your previous amazon music helper script is out of date. It would be great if you could get it working. I think they just switched around the url paths, but I'm not good with javascript to change it myself.

Sat, 02 Dec 2006

Steve

hi, you used s3 for images and css only, right?

Sun, 03 Dec 2006

Add your comment