Saturday, May 19th, 2007

RailsConf 2007 – Day 1

Category: Conferences, Rails, Ruby

RailsConf is underway in Portland, Oregon, and day one (Friday) is in the bag. The keynote by DHH covered what to expect from Rails 2.0. Front and center was an emphasis on RESTful development, which should come as no surprise to anyone who has followed Rails lately. The big takeaway for ajax developers is that Rails will let you return javascript seamlessly for any request, right along side the same code you use for a standard HTTP requests, or XML requests, or whatever. This ultimately means more cohesive, cleaner code in your controllers, and that adding ajax is as easy as adding a format.js to serve XHR requests:

  1. class PeopleController < ApplicationController
  2.   ...
  3.   def create
  4.     @person = Person.create(...)
  5.     respond_to do |format|
  6.       format.html { redirect_to person_url(@person) }
  7.       format.xml  { render :status => :created, :location => person_url(@person), ... }
  8.       format.js   {
  9.         render :update do |js|
  10.           ... # RJS code here to update the page with js with your created person
  11.         end
  12.       }
  13.     end
  14.   end
  15. end

Rails 2.0 also has some great optimizations coming for HTTP performance. If you’ve ever looked at the size of prototype+scriptaculous (or dojo, or yui, or…), plus your own custom scripts, PLUS the overhead of the HTTP connections for each seperate javascript file, you know that page load time can get horrendous really quick. The upcoming version will allow easy batching of your js and css, and automatic gzipp’ing when in production, using the standard javascript/stylesheet include tags:

  1. < %= javascript_include_tag :all, :cache => true %>
  2. < %= stylesheet_link_tag :all, :cache => true %>

One other quick win Rails 2.0 will give you is multiple hosts for assets. Browsers will only have two concurrent connections open for any single host, but an easy way around that is to use multiple subdomains that resolve to the same domain. So if you set:

  1. config.action_controller.asset_host = ''

Your rails app will randomly choose static01, static02, etc…to get more parallel connections for static assets. This assumes you use the built in img, js, and css helpers, of course.

For more full coverage of the keynote in core-Rails areas, see Nick’s notes.

The other ajax-centered session for the day was on full web stack testing with Selenium Remote Control, by Alex Chaffee and Brian Takita (PDF here). The ajax testing story is still a mixed bag, with a lot of different tools and approaches and not one clear best path. Selenium RC lets you test at the function level of your JS, all the way to a functional level of forms and events, all in the language your app is written in (hence the “remote control” part). For more details see the Selenium link above or the detailed pdf for all the code.

Posted by Rob Sanheim at 5:03 pm

4 rating from 25 votes


Comments feed TrackBack URI

as my mothertongue is not English, could anybody please explain, what “day one (Friday) is in the bad” means?
thank you!

Comment by frank guiterrez — May 20, 2007

I think it was supposed to be ‘in the bag’ as in finished.

Comment by Steve Upton — May 20, 2007

Yep, it was a typo. Sorry about that – fixed.

Comment by Rob Sanheim — May 20, 2007

> Your rails app will randomly choose static01, static02, etc…to get
> more parallel connections for static assets.

Wow … that’s amazingly short-sighted. The exact same asset will be known by different names from page to page? So, instead of caching the static asset for use on future pages, my browser will have to download lots of copies of the same thing. I am not sure how this is supposed to improve performance.

Comment by Trav — May 20, 2007

and it will make the page slightly different and uncachable (how many unique versions of the current page are there when its randomizing the asset URIs?)

and what if you cache GET responses like any sane REST setup does – do you cache the copy pointing asset02 and then your other asset servers go unused?

rails has painted itself into a cult/corner with a lot of things – im sure this feature makes perfect sense if you are always generating the page on demand from a live ruby interp (even if 90% of its content is memcached) and your asset hosts arent loadbalanced, just like im sure RJS makes sense if you like to use slow ass ruby to dynamically generate javascript from another language then shuttle it over to the browser to execute, for every request, or you know, you have a fetish for splitting different parts of your model definition amongst 2 places, or really like Prototype in the face of Moo/Mochi/JQ, or really like programatically generating your SQL and JS from ruby but never your HTML or CSS..or modifying the actual request URI and therefore changing the identify of the resource, _outside_ of the query string, _or_ anchor hash to do something with content-type/accept headers already do..

Comment by carmen — May 21, 2007

I have to agree with Trav and carmen, that this kind of asset_host configuration will lead to uncachable pages.

But I think there could be easy fix for that which combines the best of both worlds:

2 subdomains per asset per page _and_ a fix subdomain per asset in the page.
How to do that? Instead of randomly choosing the asset hosts we calculate the hostname from an hash of the asset name. This gives plenty of options to distribute assets over any number of asset hosts _and_ keep any given asset always beeing loaded (and cached) from the same host.

Comment by Alexis — May 21, 2007

They could probably just store the asset subdomains for each session to maintain caching.

Comment by Andy Kant — May 21, 2007

@Andy: I was thinking most of AJAX driven web application, so the most assets needs to be loaded just once per session, anyway. So a session based fixed subdomain would lower the data transfer just for images nearly. (I also don’t enjoy to purchase an identical copy of prototype.js from a lot of hosts, for example.)
AJAX web applications mostly have their biggest pageload in the very beginning of an user session. That’s why i guess a ‘hashed subdomain’, a proper use of HTTP status 304 (Not Modified) and the same ‘domain’ for each unchanged file a good solution – best combined with compression, too.

Comment by Alexis — May 21, 2007

Carmen: This is an _option_ after all, you can always just use a single static host or a plain old directory for assets. Rails is opinionated, but there is always room to work within and outside of those opinions.

btw – all the assets host would normally point to a single server, or a single cluster fronted by a load balancer (for a huge site anyways). So all the asset copies are used, as they are all the same thing in the end. The multiple hosts is only to hack around the 2 concurrent browser connection limit.

Comment by Rob Sanheim — May 23, 2007

“I’ve just read about TIBET and am trying to make anything with it. Unfortunately its page seems to be almost dead, all links go to their home page from which you can get much ”
Gee can you tell me more about it?
My dog is eating my computer book! about a friendly dog!

Comment by My Dog Friend — October 2, 2007

Leave a comment

You must be logged in to post a comment.