MongoDB vs MySQL performance

I’ve been developing a few projects using rails 3 with mongoDB and recently needed to store some session data. I wanted to store the sessions in mongo so I wrote mongoid_session_store. It uses mongoid for persisting to a sessions collection and works pretty closely to how ActiveRecordStore works. After getting the session store working and setup in my app I was curious to see there would be a performance difference between using mongo vs a relational db.

Example App

The example app I used for this benchmark is under the example dir in the mongoid_session_store repo. It contains one controller, the sessions controller. This controller has a method set_session_value which just simply sets the current session to “bar” and then renders a 200 ok response and thats it. I made it to do this so rendering wouldn’t effect any of the benchmark results. I wanted to make the controller do as little as possible in order to simply test the differences between the two session stores.

In order to run the app against mongo or mysql the only change needed is to update the config/initializer/session_store.rb file from


Example::Application.config.session_store :mongoid_store


Example::Application.config.session_store :active_record_store


Test Setup

The example app is running on a macbook pro core i7 with 4gigs of ram. I’m running a single thin instance in production mode using ruby 1.9.2 final and rails 3.0.0.rc.

To benchmark the app I’m running apachebench on another macbook pro core2duo 2.2ghz with 4 gigs of ram. Both machines are running on my home network.



Here are the results for running 1000 requests for writing a session value.



Requests per second:    164.03 [#/sec] (mean)

Time per request:       60.966 [ms] (mean)

Time per request:       6.097 [ms] (mean, across all concurrent requests)

Transfer rate:          37.99 [Kbytes/sec] received



Requests per second:    108.94 [#/sec] (mean)

Time per request:       91.790 [ms] (mean)

Time per request:       9.179 [ms] (mean, across all concurrent requests)

Transfer rate:          25.21 [Kbytes/sec] received




In this initial test you can see that the mongo store is processing requests about 34% quicker than with mysql.

(via Ryanfitz’s Posterous)

Posted in DB

1 thought on “MongoDB vs MySQL performance”

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.