Rails 1.1 Release

Posted about 8 years back at RailsExpress.blog

As you probably know already, Rails 1.1 was released a few days ago.

We have worked hard to ensure that 1.1 performs on the same level as 1.0. For some cases, it performs significantly better than 1.0 (explanation will follow in a future post).

The following performance data table shows the speed difference for the fastest available configuration for my application.

page c1 totalc2 total c1 r/sc2 r/s c1 ms/rc2 ms/r c1/c2
/empty/index 7.861397.10545 636.0703.7 1.571.42 1.11
/welcome/index 8.387438.32744 596.1600.4 1.681.67 1.01
/rezept/index 8.870388.75717 563.7571.0 1.771.75 1.01
/rezept/myknzlpzl 8.861728.76325 564.2570.6 1.771.75 1.01
/rezept/show/713 22.2253020.12046 225.0248.5 4.454.02 1.10
/rezept/cat/Hauptspeise 25.2905124.70123 197.7202.4 5.064.94 1.02
/rezept/cat/Hauptspeise?page=5 25.9252825.40904 192.9196.8 5.195.08 1.02
/rezept/letter/G 25.0624224.96315 199.5200.3 5.014.99 1.00

You can find additional information and lots of performance data in the full report .

Presenting at RailsConf 2006

Posted about 8 years back at RailsExpress.blog

I’m proud to announce that I will be giving a talk at RailsConf2006 on Rails Application Optimization.

If you have specific topics or questions you’d like to have addressed besides the ones mentioned in the talk proposal, or some general suggestion, I invite you to add an entry to the comment section of this post.

Looking forward to meet you in Chicago!

Rails Plugin to Help Debug Views

Posted about 8 years back at

The debug_view_helper plugin was developed to make it easy to add debug information into your views. It was derived from techniques described in HowtoDebugViews and it makes it possible to expose the followng following debug data;

  • Request Parameters
  • Session Variables
  • Flash Variables
  • Assigned Template Variables

Typically you add code such as the following to the bottom of your layout that exposes the debug button in development mode.

<% if RAILS_ENV == 'development' %>
  <button onclick="show_debug_popup(); return false;">
    Show debug popup
<%= debug_popup %>
<% end %>

You can grab the plugin from subversion at;


Update: Added the ability to add inline debug information via the following. Suggestion by John Dell.

<% if RAILS_ENV == 'development' %>
<%= debug_inline %>
<% end %>

Rails Plugin to Validate (X)HTML and CSS

Posted about 8 years back at

Here is an enahnced version of Scott Raymond’s assert_valid_markup plugin that I use in my projects. Below are the directions for use;

HowTo Validate (X)HTML

# Calling the assertion with no parameters validates 
# whatever is in @request.body, which is automatically 
# set by the existing get/post/etc helpers. For example:

class FooControllerTest < Test::Unit::TestCase
  def test_bar_markup
    get :bar

# Add a string parameter to the assertion to validate 
# any random fragment. For example:

class FooControllerTest < Test::Unit::TestCase
  def test_bar_markup
    assert_valid_markup "<div>Hello, world.</div>"

# For the ultimate in convenience, use the class-level
# method to validate a number of actions in one line. 

class FooControllerTest < Test::Unit::TestCase
  assert_valid_markup :bar, :baz, :qux

HowTo Validate CSS

# Pass a string parameter to the assertion to validate 
# a css fragment. For example:

class FooControllerTest < Test::Unit::TestCase
  def test_bar_css
    filename = "#{RAILS_ROOT}/public/stylesheets/bar.css"
    assert_valid_css(File.open(filename ,'rb').read)

# For the ultimate in convenience, use the class-level
# method to validate a bunch of css files in one line.
# Assumes that the CSS files are relative to 
# $RAILS_ROOT/public/stylesheets/ and end with '.css'. 
# The following example validates 
#  $RAILS_ROOT/public/stylesheets/layout.css, 
#  $RAILS_ROOT/public/stylesheets/standard.css and 
#  $RAILS_ROOT/public/stylesheets/theme.css

class FooControllerTest < Test::Unit::TestCase
  assert_valid_css_files 'layout', 'standard', 'theme'

Most of the credit for this plugin goes to Scott for the initial idea! The modifications that I made include;

  • Validation of CSS files.
  • Caching of fragments occurs in $RAILS_ROOT/tmp according to the name of the test class + test method. This avoids filling up the system temp folder with expired cache files.
  • Ability to turn off validation by setting the “NONET” environment variable to “true”.

You can grab it from subversion at;


Update 12th of May, 2008

Steve Sloan has also added a Git repo for the code which you can grab from:


SXSWi Why the Lucky Stiff - Ruby on Rails Podcast

Posted about 8 years back at Ruby on Rails Podcast

A bootleg of the Why the Lucky Stiff concert at the South by Southwest Interactive Festival.

SXSWi Shaun Inman - Ruby on Rails Podcast

Posted about 8 years back at Ruby on Rails Podcast

Popular designer and PHP developer Shaun Inman tries Ruby and talks about developing Mint.
See him in Boston next month at a Carson Workshops seminar on developing extensible PHP web apps.

Bruce Tate - Ruby on Rails Podcast

Posted about 8 years back at Ruby on Rails Podcast

Bruce Tate has created a stir in the Java community by promoting Ruby.
His books include Beyond Java and the upcoming Ruby on Rails, Up and Running.

Meta-Programming in Java

Posted about 8 years back at

I have been looking over my old code repository and I came across GEL. GEL was a toolkit that allowed me to define entities and events for HLA using an XML data definition language.

The HLA is a family of specifications developed to promote intereoperability and reuse of simulation assets. Unfortunately there is a significant development effort associated with construction of a HLA-compliant federation. Less than 2% of the 2500+ lines of code in the “Hello World” sample HLA application relates to simulation logic. The integration code is a significant cost and there is often a high-level of coupling between the simulation code and the integration code.

GEL was created to simplify HLA developers task by generating all the integration code from a simulation model defined in an XML document. The HLA developer had the sole responsibility of writing the simulation/logic code. Think of GEL as a a poor-mans MDA (I even planned to have a set of separate generators that would allow the simulation objects to be hosted in a Quake3 game). This approach rocks as you only need to fix and update the code in one place (the generator) and you are far more productive at the higher level of abstraction.

Each simulation object in the GEL XML document resulted in the generation of several Java classes by velocity.

  • a Model class for holding data of a specific instance.
  • a ModelListener class that receives events relating to a Model instance.
  • a HLAPeer class that reflects the data in a Model instance into the HLA runtime.
  • a PersistPeer class that persists the data in a Model instance.
  • a number of Value Object classes to represent various events
  • etc…

I had long believed in having a single high-level model of the domain objects and generating. Prior to XML I had used SGML, INI and custom formats to represent the model. On a number of occasions I have attempted to move the model data into the code to make it easier to keep up to date. I have used C/C++’s macro expansions, XDoclet-like processors and Java 1.5 Annotations at various times.

Six months using Ruby On Rails’ has changed my world view. The model classes are very close to the level at which I would create my domain model. The good thing about ruby is that you can always add more language constructs to make sure the code matches your domain model. (I know Lisp-ers have always raved about this but I have never been able to use lisp in a commercial environment). Things like acts_as_list to order your domain objects, acts_as_versioned to version your domain objects or acts_as_threaded to have a threaded tree representation radically simplify the representation of domain objects.

I have been thinking about how I would do this in Java but most of the neat stuff just does not seem possible without the introduction of a Meta-object Protocol or some sort of load-time class file modification.

Consider a simple simulation object. In ruby I would represent it via

class Kettle < Model::Base
  shared_attr :temperature, :float, :resolution => 1.0, :accuracy => 1.0 

In java there is no simple equivalent. I could just define the model in a class like below. However this would probably need to be instrumented during loading so that the runtime could monitor changes to the shared attribute.

public class Kettle extends BaseModel
  @SharedAttribute(resolution = 1.0, accuracy = 1.0 )
  private float m_temperature;

  public float getTemperature()
    return m_temperature;

  public void setTemperature(final float temperature)
    m_temperature = temperature;

Instrumentation in whatever form it takes is fairly complex even if you use something like AspectJ that is perfect for this scenario. Much more complex than writing the equivalent acts_as_* plugin.

The above only works when the instrumentation code does not need to add any methods. However if you want a simulation object to support shared events you need to be able to subscribe, unsubscribe and generate these events which means you need the same boilerplate code repeated over and over.

I can not think of anyway to do this in java so I guess it is back to generating the Java classes from a central model file. Pity I think I liked the ruby way better.

Distributed Case-Based Reasoning using Java

Posted about 8 years back at

Over the next few months I will be investing some time into a research project focusing on distributed case-base reasoning. The idea is to establish an ad-hoc network of nodes that each have a separate case-base. When a node attempts to find a solution to a problem it will query both it’s local case-base and case-bases of connected nodes to determine the solution.

The exact algorithms that the solver uses to select nodes to query will have a significant impact on the speed and accuracy with which a solution can be found. The maintainece of the distributed cases-bases via case addition or removal will also need to be addressed in our research.

I will be working on an existing codebase but I have been looking around to see if I can find any free or opensource java case-base reasoning software. Something that I can tack a distribution layer on top of but I have been unable to find any products that are not commercial software and/or under highly restrictive licenses. I wonder if this is an area that just does not appeal to FOSS developers?

Jim Weirich - Ruby on Rails Podcast

Posted about 8 years back at Ruby on Rails Podcast

The Ruby pioneer on rake task automation and good code design.

First Video PodCast

Posted about 8 years back at Free Ruby and Rails Screencasts

This is a first attempt at creating a video podcast.

Glenn Vanderburg - Ruby on Rails Podcast

Posted about 8 years back at Ruby on Rails Podcast

Glenn Vanderburg on metaprogramming. Formatted as MP3 this time…enhanced MPEG-4 versions will be available in a separate feed starting next episode.

Sean Chittenden - Ruby on Rails Podcast

Posted about 8 years back at Ruby on Rails Podcast

Sean Chittenden talks about his Rails re-design work with Penny-Arcade.com, server scalability, and the open source business model.

Using memcached for Ruby on Rails session storage

Posted about 8 years back at RailsExpress.blog

A few days ago Eric Hodel announced the availability of a new pure Ruby memcached client implementation (memcache-client-1.0.3) with performance improvements over the older Ruby-Memcache-0.4 implementation.

I had measured the old version previously, for use as a Ruby on Rails fragment cache storage container, but found its performance to be abysmal and completely unusable for my purposes.

memcache-client-1.0.3 provides much better performance: much faster than either the old implementation, pstore or ActiveRecordStore, but also faster than my optimized SQLSessionStore using MysqlSession (see Roll your own SQL session store).
In order to determine the relative performance I ran my usual benchmarks using railsbench against memcache-client-1.0.3 and SQLSessionStore using MyslSession.

All components resided on a single machine. Before running the tests, both DB tables and memcached were populated with 10000 sessions.

The first test was run with Mysql query caching disabled:

page c1 totalc2 total c1 r/sc2 r/s c1 ms/rc2 ms/r c1/c2
/empty/index 1.233180.96322 810.91038.2 1.230.96 1.28
/welcome/index 1.443141.15051 692.9869.2 1.441.15 1.25
/rezept/index 1.528691.19616 654.2836.0 1.531.20 1.28
/rezept/myknzlpzl 1.521591.19022 657.2840.2 1.521.19 1.28
/rezept/show/713 4.149063.95939 241.0252.6 4.153.96 1.05
/rezept/cat/Hauptspeise 9.481019.29202 105.5107.6 9.489.29 1.02
/rezept/cat/Hauptspeise?page=5 9.844049.65393 101.6103.6 9.849.65 1.02
/rezept/letter/G 5.423705.20227 184.4192.2 5.425.20 1.04
 c1: DB sessions, c2: memcached sessions, r/s: requests per second, ms/r: milliseconds per request

On the second run, Mysql query caching was enabled:

page c1 totalc2 total c1 r/sc2 r/s c1 ms/rc2 ms/r c1/c2
/empty/index 1.268040.95403 788.61048.2 1.270.95 1.33
/welcome/index 1.470701.13807 679.9878.7 1.471.14 1.29
/rezept/index 1.559761.18066 641.1847.0 1.561.18 1.32
/rezept/myknzlpzl 1.554021.17650 643.5850.0 1.551.18 1.32
/rezept/show/713 3.508763.20310 285.0312.2 3.513.20 1.10
/rezept/cat/Hauptspeise 4.317204.00799 231.6249.5 4.324.01 1.08
/rezept/cat/Hauptspeise?page=5 4.411504.11811 226.7242.8 4.414.12 1.07
/rezept/letter/G 4.311904.02345 231.9248.5 4.314.02 1.07
 c1: DB sessions, c2: memcached sessions, r/s: requests per second, ms/r: milliseconds per request

What can we learn from this data?

  • Pages which force the creation of new sessions (empty, welcome) and action cached pages (rezept/index and rezept/knzlpzl) experience a speedup between 25% and 33%.
  • Pages involving DB queries other than session retrieval don’t see as much speedup.
  • If query caching is disabled and the query is really DB expensive (/rezept/cat issues a LIKE %Hauptspeise%), the speed improvement is negligible.
  • Enabling the Mysql query cache will result in slightly slower creation of new sessions, but can speed up complex queries tremendously (table below).
page c1 totalc2 total c1 r/sc2 r/s c1 ms/rc2 ms/r c1/c2
/empty/index 1.233181.26804 810.9788.6 1.231.27 0.97
/welcome/index 1.443141.47070 692.9679.9 1.441.47 0.98
/rezept/index 1.528691.55976 654.2641.1 1.531.56 0.98
/rezept/myknzlpzl 1.521591.55402 657.2643.5 1.521.55 0.98
/rezept/show/713 4.149063.50876 241.0285.0 4.153.51 1.18
/rezept/cat/Hauptspeise 9.481014.31720 105.5231.6 9.484.32 2.20
/rezept/cat/Hauptspeise?page=5 9.844044.41150 101.6226.7 9.844.41 2.23
/rezept/letter/G 5.423704.31190 184.4231.9 5.424.31 1.26
 c1: DB sessions without query cache, c2: DB sessions with query cache

Like all benchmarks, these results have to be taken with a grain of salt. Choice of either option involves more than just looking at the above numbers.

Database and memcached have quite different scaling properties: adding more memcached daemons is easy, whereas DB based session storage scales mostly by buying a bigger DB machine or running the session DB on a separate machine using a session database.

On the other hand, DB session storage makes it easy to get application usage statistics using SQL queries, e.g. displaying the number of active sessions or checking whether a particular user is currently logged in. I don’t know an easy way to do this using the memcachd API.

It seems to me that using memcached for session storage is a good choice if your DB server experiences a very high load and your scaling options are already exhausted. I wouldn’t recommend to use it per default.

Using memcachd for Ruby on Rails fragment cache storage is a completely different story, on which I hope to report in the future.

Scott Raymond - Ruby on Rails Podcast

Posted over 8 years back at Ruby on Rails Podcast

Scott Raymond, developer of Blinksale, Icon Buffet, and other wonderful Rails apps.