Skip to content

Instantly share code, notes, and snippets.

@coffeemug
Created September 5, 2013 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coffeemug/6444786 to your computer and use it in GitHub Desktop.
Save coffeemug/6444786 to your computer and use it in GitHub Desktop.
RethinkDB vs. Mongo insert test
"""Compares rethinkdb with mongo. Copied from http://pastebin.com/3PqdFTjc. Example output:
mongodb: 0.110867023468
rethink: 2.25043606758
"""
import copy
import pymongo
import rethinkdb as r
import time
mc = pymongo.Connection()
rc = r.connect()
mc.drop_database('test')
r.db_drop('test').run(rc, noreply = True)
r.db_create('test').run(rc)
r.db('test').table_create('test').run(rc)
mcol = mc['test']['test']
rcol = r.db('test').table('test')
_docs = [ { 'val': i, 'count': 8, 'data': [ 1, 2, 3, 4, 5 ] * 20 }
for i in range(1000) ]
mdocs = copy.deepcopy(_docs)
rdocs = copy.deepcopy(_docs)
def timeit(c, l):
a = time.time()
l()
print("{}: {}".format(c, time.time() - a))
timeit("mongodb", lambda: mcol.insert(mdocs, safe = True))
timeit("rethink", lambda: rcol.insert(rdocs).run(rc))
@coffeemug
Copy link
Author

MongoDB's safe option is deprecated, so I'm not completely sure what it does. To make the tests be compatible, run mcol.insert(mdocs, w = 1, j=True) (see http://api.mongodb.org/python/current/api/pymongo/collection.html).

The numbers still aren't equivalent, but this is a Python driver performance issue rather than RethinkDB server performance issue. Unfortunately the Python protobuf library without the C++ extension is slower than BSON which MongoDB uses. To get the fastest Python driver performance for Rethink, you'd have to install the C++ extension (see http://rethinkdb.com/docs/driver-performance/)

@coffeemug
Copy link
Author

Ok, ran more tests. Please track the following issue for progress -- rethinkdb/rethinkdb#1403

@wwoods
Copy link

wwoods commented Sep 5, 2013

Ah, that makes sense. Hopefully it's primarily that and not the protobuf implementation. Installing the C++ version isn't going so well...

In file included from ./rethinkdb/ql2.pb.cc:4:0:
./rethinkdb/ql2.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
#error This file was generated by an older version of protoc which is
^
./rethinkdb/ql2.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
^
./rethinkdb/ql2.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment