Redis and MongoDB insertion performance analysis
Tuesday, March 16th, 2010 | Computer Science
Recently we had to study a software where reads can be slow, but writes need to be as fast as possible. Starting from this requirement we thought about which one between redis and mongodb would better fit the problem. Redis should be the obvious choice as its simpler data structure should make it light-speed fast, and actually that is true, but we found a we interesting things that we would like to share.
This first graph is about MongoDB Insertion vs Redis RPUSH.
Up to 2000 entries the two are quite equivalent, then redis starts to get faster, usually twice as fast as mongodb. I expected this, and I have to say that antirez did a good job in thinking the redis paradigm, in some situations it is the perfect match solution.
Anyway I would expect mongodb to be even slower relating to the features that a mongodb collection has over a simple list.
This second graph is about Redis RPUSH vs Mongo $PUSH vs Mongo insert, and I find this graph to be really interesting.
Up to 5000 entries mongodb $push is faster even when compared to Redis RPUSH, then it becames incredibly slow, probably the mongodb array type has linear insertion time and so it becomes slower and slower. mongodb might gain a bit of performances by exposing a constant time insertion list type, but even with the linear time array type (which can guarantee constant time look-up) it has its applications for small sets of data.
I would like to say that this benchmarks have no real value, as usual, and have been performed just for curiosity
You can find here the three benchmarks snippets
import redis, time MAX_NUMS = 1000 r = redis.Redis(host='localhost', port=6379, db=0) del r['list'] nums = range(0, MAX_NUMS) clock_start = time.clock() time_start = time.time() for i in nums: r.rpush('list', i) time_end = time.time() clock_end = time.clock() print 'TOTAL CLOCK', clock_end-clock_start print 'TOTAL TIME', time_end-time_start
import pymongo, time MAX_NUMS = 1000 con = pymongo.Connection() db = con.test_db db.testcol.remove({}) db.testlist.remove({}) nums = range(0, MAX_NUMS) clock_start = time.clock() time_start = time.time() for i in nums: db.testlist.insert({'v':i}) time_end = time.time() clock_end = time.clock() print 'TOTAL CLOCK', clock_end-clock_start print 'TOTAL TIME', time_end-time_start
import pymongo, time MAX_NUMS = 1000 con = pymongo.Connection() db = con.test_db db.testcol.remove({}) db.testlist.remove({}) oid = db.testcol.insert({'name':'list'}) nums = range(0, MAX_NUMS) clock_start = time.clock() time_start = time.time() for i in nums: db.testcol.update({'_id':oid}, {'$push':{'values':i}}) time_end = time.time() clock_end = time.clock() print 'TOTAL CLOCK', clock_end-clock_start print 'TOTAL TIME', time_end-time_start
-
Pawel K
-
antirez
-
Pawel K
-
Pawel K
-
RJ Ryan
-
amol
-
antirez
-
amol
-
Didier Spezia
-
Ralf
Search
Archives
- September 2012
- August 2012
- March 2012
- January 2012
- November 2011
- October 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- September 2010
- August 2010
- July 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- October 2008
- August 2008