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つ。

他のサイトでも、Rails2.0系と1.2系のパフォーマンスに関する結果が公開されていたので紹介します。

パフォーマンスに関して

Performance comparison: Rails 1.2.6 vs 2.0.2
http://izumi.plan99.net/blog/index.php/2008/03/18/performance-comparison-rails-126-vs-202/

上記リンク先を見てもらえばわかるのですが、超シンプルなダミーアプリに対して、ベンチマークした結果が以下。

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

Mongrelのproductionモードでの比較で、Rails2.0の方が1.2と比較して、50%アップ、つまり単純に1.5倍ものパフォーマンスが出ているとのこと。
やっぱり、速くなっていますね。物凄く!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

なわけで、セッションをオフにした状態でも比較されていますが、それでも30%も向上している模様。こりゃすごい。

メモリ使用量に関して

さらに同じサイトの別記事ですが。

Memory usage comparison: Rails 1.2.6 vs 2.0.2
http://izumi.plan99.net/blog/index.php/2008/03/19/memory-usage-comparison-rails-126-vs-202/

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

Mongrelを単純に起動させた時点で、既に6MBも使用量に差があって、Rails2.0の方が減っている模様。

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"
    GC.start
    render :text => ObjectSpace.statistics
end

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

3000リクエストの後、GCを走らせた結果、やはりメモリの使用量はRails2.0の方が少ない模様。良いですね!