This project is archived and is in readonly mode.

#3759 ✓duplicate
Sam Saffron

Rails 3 AR performance has regressed since Rails 2

Reported by Sam Saffron | January 20th, 2010 @ 10:14 PM

Using a trivial model on both Rails 2 and 3:

script/generate scaffold post title:string body:text

I'm noticing both insert and create performance are much slower. This is for both dev and production environments.

Rails 2 results:

ree-1.8.7-2009.10 >  puts Benchmark.measure{1000.times{Post.create(:title => "bla", :body => "x" * 1000)}}
  0.970000   0.480000   1.450000 (  2.923408)
 => nil
ree-1.8.7-2009.10 >  puts Benchmark.measure{1000.times{Post.find((rand * 1000 + 1).to_i)}}
  0.280000   0.320000   0.600000 (  0.593748)

Rails 3 results:

ree-1.8.7-2009.10 > puts Benchmark.measure{1000.times{Post.create(:title => "bla", :body => "x" * 1000)}}
  1.940000   0.590000   2.530000 (  3.883329)
ree-1.8.7-2009.10 > puts Benchmark.measure{1000.times{Post.find((rand * 1000 + 1).to_i)}}
  0.450000   0.710000   1.160000 (  1.162713)

Comments and changes to this ticket

  • Sam Saffron

    Sam Saffron January 21st, 2010 @ 12:01 AM

    • Tag set to active_record, performance, rails3
  • drjoke

    drjoke July 12th, 2010 @ 04:59 PM

    Has there been any update to your issue? I am using Rails 3.0 Beta 4 and am finding it is much slower than Rails 2.3.5

    I am using Ruby Enterprise 1.8.7 and Passenger 2.2.15

    I go from 5.31 trans/sec to 3.05 trans/sec per AWS EC2 instance.

    $ siege -c 5 -t 1M http://localhost
    
    RAILS 2.3.5 RESULTS
    Transactions:             320 hits
    Availability:          100.00 %
    Elapsed time:           60.26 secs
    Data transferred:          6.76 MB
    Response time:            0.45 secs
    Transaction rate:          5.31 trans/sec
    Throughput:            0.11 MB/sec
    Concurrency:            2.41
    Successful transactions:         320
    Failed transactions:             0
    Longest transaction:          1.05
    Shortest transaction:          0.25
    
    RAILS 3
    Transactions:             169 hits
    Availability:          100.00 %
    Elapsed time:           55.38 secs
    Data transferred:          3.72 MB
    Response time:            1.06 secs
    Transaction rate:          3.05 trans/sec
    Throughput:            0.07 MB/sec
    Concurrency:            3.23
    Successful transactions:         169
    Failed transactions:             0
    Longest transaction:          1.74
    Shortest transaction:          0.58
    
  • Miles Egan

    Miles Egan July 13th, 2010 @ 05:32 AM

    Tried this on a slightly more formal benchmark, with a test script like this:

    10.times do
      1000.times{ Post.create(:title => "bla", :body => "x" * 1000) }
      max = Post.maximum(:id)
      1000.times{ Post.find(rand(max) + 1) }
    end
    

    Invoked like this:

    
    [21:14:57] miles slopper ~/c/perftest2
    $ rake db:drop; rake db:create; rake db:migrate; time ./script/runner -e production ~/tmp/posttest 
    ...
    real    2m12.275s
    user    0m41.200s
    sys 0m1.640s
    

    and this:

    
    $ rake db:drop; rake db:create; rake db:migrate; time ~/c/rails/bin/rails runner -e production ~/tmp/posttest 
    ...
    real    3m21.563s
    user    1m8.380s
    sys 0m1.920s
    

    This is with a postgres database on a Ubuntu 10.04 machine. So I'm seeing a similar slowdown. Of course, benchmarking is a notoriously tricky business so it's hard to be sure to what extent this reflects a real-world workload.

  • Aaron Patterson

    Aaron Patterson July 15th, 2010 @ 04:12 PM

    • Assigned user set to “Aaron Patterson”
    • Importance changed from “” to “Low”

    I'll take a look in to this.

  • drjoke

    drjoke July 15th, 2010 @ 04:41 PM

    This ticket should be merged into this:

    https://rails.lighthouseapp.com/projects/8994/tickets/5098-rails-3-...

    I don't know how to do it, but the same problem is better identified there.

  • Aaron Patterson

    Aaron Patterson August 29th, 2010 @ 08:49 AM

    • State changed from “new” to “duplicate”

    Marking as a duplicate of #5098.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages