Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
Rails Optimization Example | 161

3.64 0.40 0.39 0.00 0.01 133960 Hash#[]=
3.55 0.70 0.38 0.00 0.32 1040 GeoRuby::SimpleFeatures::
HexEWKBParser#decode_hex

Benchmarking


Now that we have made optimizations, we should see how they affect the actual per-
formance of our application. We saved this section for later so that we could com-
pare the two optimizations to each other; in reality, you should benchmark after
each optimization to be sure that each change has the desired effect.


We will be comparing the performance of the three versions of the application:



  • No optimization (the control)

  • TheListing#location optimization

  • The rewrite of the clustering algorithm


Source Control and Optimization
Source control is our friend during the optimization process. The application uses Mer-
curial, a distributed version-control system, which makes it very easy to test large,
complicated changes and then pull all, some, or no changes back into the main code-
base, depending on their performance improvement. In this case, we used source con-
trol to run benchmarks on several different optimizations after the fact, to see how
much of an improvement each one made.
We followed the following (simplified) process with Mercurial:


  1. Clone the main trunk repository to a new repository and copy over any neces-
    sary nonversioned configuration files (such asconfig/database.yml).
    $ hg clone trunk performance-testing
    $ cp trunk/config/database.yml performance-testing/config/

  2. In the new repository, repeat the profile-optimize-test cycle and check in each
    change.
    $ cd performance-testing
    (make changes, test)
    $ hg ci

  3. If the performance improvements were successful, pull the changes back into the
    main repository.a
    $ cd ../trunk
    $ hg pull -u ../performance-testing
    $ hg up
    We examine the distributed version-control paradigm in more detail in Chapter 10.


aThe Mercurial Queues extension (also called MQ; its use is detailed athttp://www.selenic.com/mercurial/
wiki/index.cgi/MqExtension) makes this process much more straightforward, and makes it easier to cherry-
pick or throw away individual changes (even while working in the main repository). However, it is far
beyond this book’s scope.

Free download pdf