This site is dedicated to further knowledge about creating Ruby on Rails applications professionaly. We discuss Ruby on Rails features from a performance angle, discuss Ruby on Rails performance analysis methods, provide information on Ruby on Rails scaling and benchmark Ruby on Rails performance for each release. We discuss best practices for selecting Ruby on Rails session containers, fragment and page caching and optimizing database queries.

SqlSessionStore gains support for SQLite

Posted 09 Nov 2006

Ted X Toth has submitted the code for a SQLite session class implementation for SqlSessionStore. I have checked it into the subversion repository.

Thank you very much Ted!

View Comments

Make ruby-mysql create less garbage

Posted 05 Oct 2006

During the preparation of my RailsConf2006 talk I did some comparative benchmarks with Mysql and Postgresql. To my astonishment, I observed that Rails with Mysql created many more objects. After digging into the C part of ruby bindings of Mysql, I discovered that the Mysql bindings create a copy of the columns name string for each record retrieved from the database. This obviously leads to quadratic memory use and calls for correction.

I’ve written a small patch for the ruby-mysql bindings and submitted it to the author, but never got a response, although a tried several times.

You can get the patch here.

The patch actually goes a little farther than just correcting the n*m problem. I have added a Mysql::Result.all_hashes method, so that the entire array of hashes creation runs in C.

For pages that retrieve small datasets, you will probably see only a small increase. I measured around 5% increase for pages that load 25 objects. Which is neat. But the patch really shines when you retrieve large data sets. For example, for loading 1000 objects, I got this perf data:

page c1 totalc2 total c1 r/sc2 r/s c1 ms/rc2 ms/r c1/c2
/alphabetic 6.861265.20610 14.619.2 68.6152.06 1.32
GC statistics c1 totalc2 total c1 #gcc2 #gc c1 gc%c2 #gc% c1/c2
2.142501.18728 24.012.0 31.2322.81 2.00

30% faster!

But more important, a lot less gargabe gets created (in the example GC runs twice as often with the unpatched bindings).

You can take advantage of this by creating your own garbage ;-)

View Comments

Oracle support for sql_session_store

Posted 05 Oct 2006

Due to a contribution from Tiago Macedo, sql_session_store has gained Oracle support.

If you’re on Oracle and want improved session handling performance, you should give it a try.

If you find any problems, please submit bug reports/patches here.

And if you now how to and have time to implement support for other database adapters, please send an email or better, create a ticket and attach the patch.

View Comments

New plugin: query_builder

Posted 23 Sep 2006

I’ve added another plugin for you to check out: query_builder.

This plugin enables you to define finder methods that bypass the overhead of construct_finder_sql.

Inside an ActiveRecord model definition,
  define_finder query_name, query_type, options_hash
will create a SQL query method called query_name from a given options_hash. query_type can be :first or :all. The plugin supports all options except :include, but ignores with_scope options. Example:
class Recipe
  define_finder :find_all_of_user, :all,
     :conditions => 'user = :user AND priv < :priv'
  end
This defines a query method which can be called like so:
Recipe.find_all_of_user :user => 'martin', :priv => 1
This call is equivalent to
Recipe.find :all, :conditions =&gt;
            [ 'user = :user AND priv < :priv',
              {:user => 'martin', :priv => 1} ]
If options[:positional] is not nil or false, the created query method will use positional paramaters instead of a hash. In this case, arguments are created in the order of appearance on the parameters passed to define_finder. Therefore
define_finder :find_all_of_user, :all,
      :conditions => 'user = :user AND priv < :priv',
      :positional => true
will create a query method with parameters user and priv, which can be called like so:
Recipes.find_all_of_user('martin', 1)

I converted one of my pages to use this style and it gained 10% more performance.

If you like this plugin, drop me a line. If you find a bug, please submit a bug report to Trac

Enjoy.

View Comments

Piggy back plugin updated

Posted 16 Sep 2006

Timo Hentschel, one of my coworkers at the company for which I’m doing contract work at the moment (AutoScout24), has added a nifty little extension to my piggy_back plugin.

It’s now possible to piggy back from has_many :through associations, provided the association will return at most one record from the underlying SQL query.

This type of association currently needs to be used as a replacement for the non existent has_one :through.

There have been rumours that has_one :through will find it’s way into rails core. If it does, I’ll probably remove the has_many :through support from piggy back plugin again, or at least raise a deprecation warning.

View Comments

Older posts: 1 2 3 4 5 6 7 8 9