Rails 1.2.6 と 2.0.2 のパフォーマンス比較

by Christopher Chan

先日のエントリ「RedmineでのRailsパフォーマンス比較(1.2.6 vs 2.0.2)」(d:id:rx7:20080221:p1)に続いて、Ruby on Railsのパフォーマンスに関する話題を1つ。



Performance comparison: Rails 1.2.6 vs 2.0.2


I ran both applications in Mongrel (with the ‘production’ environment). The results of ‘ab -n 5000 http://localhost:3000/’ are as follows:

  • Rails 1.2.6: 141.19 requests/sec
  • Rails 2.0.2: 214.76 requests/sec

Wow, what a difference! Rails 2.0 is 50% faster in a dummy application!

Performance comparison: Rails 1.2.6 vs 2.0.2

やっぱり、速くなっていますね。物凄く!cookie storeであるアドバンテージもあるのでしょうか。

In Rails 1.2, a lot of time is spent in the session store. Let's see what happens if we specify “session :off” in both applications:

  • Rails 1.2.6: 189.51 requests/sec
  • Rails 2.0.2: 246.69 requests/sec

Wow! Even with sessions off, Rails 2.0 is still 30% faster! So the cookie session store isn't the only thing responsible for the performance improvement!

Performance comparison: Rails 1.2.6 vs 2.0.2




Memory usage comparison: Rails 1.2.6 vs 2.0.2

After a cold start with Mongrel 1.1.3, the private dirty memories were as follows:

  • Rails 1.2.6: 25.5 MB
  • Rails 2.0.2: 19.7 MB

Nice! A 6 MB memory reduction after a cold boot!

Memory usage comparison: Rails 1.2.6 vs 2.0.2


So let’s find out what happens after 3000 requests and a garbage collection run. I added these actions to PostsController:

def gc
    headers["Content-Type"] = "text/plain"
    render :text => ObjectSpace.statistics

And this route:

map.connect '/gc', :controller => "posts", :action => 'gc'

Then I ran, for both apps:

ab -n 3000 http://localhost:3000/
links http://localhost:3000/gc

The memory usages were:

Rails 1.2.6
    Private dirty memory:28.1 MB
    Total heap size: 14,702 KB
    Free heap space: 7,789 KB

Rails 2.0.2
    Private dirty memory: 20.9 MB
    Total heap size: 8,059 KB
    Free heap space: 2,098 KB

Nice! I didn’t expect this, but apparently Rails 2.0 uses a lot less memory!

Memory usage comparison: Rails 1.2.6 vs 2.0.2