Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB not that faster than MySQL?
    primarykey
    data
    text
    <p>I discovered mongodb some months ago,and after reading this <a href="http://www.vedana.it/it/component/content/article/9-linux/62-testing-mongodb-vs-mysql-with-python-scripting-under-linux">post</a>, I thought mongodb was really faster than mysql, so I decided to build my own bench, the problem is that I do not have the same result than the above post's author, especially for quering the database : mongodb seems to be slower than MyISAM tables. Could you have a look to my python code, may be there is something wrong in it :</p> <pre><code>from datetime import datetime import random import MySQLdb import pymongo mysql_db=MySQLdb.connect(user="me",passwd="mypasswd",db="test_kv") c=mysql_db.cursor() connection = pymongo.Connection() mongo_db = connection.test kvtab = mongo_db.kvtab nb=1000000 thelist=[] for i in xrange(nb): thelist.append((str(random.random()),str(random.random()))) t1=datetime.now() for k,v in thelist: c.execute("INSERT INTO key_val_tab (k,v) VALUES ('" + k + "','" + v + "')") dt=datetime.now() - t1 print 'MySQL insert elapse :',dt t1=datetime.now() for i in xrange(nb): c.execute("select * FROM key_val_tab WHERE k='" + random.choice(thelist)[0] + "'") result=c.fetchone() dt=datetime.now() - t1 print 'MySQL select elapse :',dt t1=datetime.now() for k,v in thelist: kvtab.insert({"key":k,"value":v}) dt=datetime.now() - t1 print 'Mongodb insert elapse :',dt kvtab.ensure_index('key') t1=datetime.now() for i in xrange(nb): result=kvtab.find_one({"key":random.choice(thelist)[0]}) dt=datetime.now() - t1 print 'Mongodb select elapse :',dt </code></pre> <p>Notes:</p> <ul> <li>both MySQL and mongodb are on locahost.</li> <li>both MySQL and mongodb has the 'key' column indexed</li> </ul> <p>MySQL Table:</p> <pre><code>CREATE TABLE IF NOT EXISTS `key_val_tab` ( `k` varchar(24) NOT NULL, `v` varchar(24) NOT NULL, KEY `kindex` (`k`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; </code></pre> <p>Versions are:</p> <ul> <li>MySQL: 5.1.41</li> <li>mongodb : 1.8.3</li> <li>python : 2.6.5</li> <li>pymongo : 2.0.1</li> <li>Linux : Ubuntu 2.6.32 32Bits with PAE</li> <li>Hardware : Desktop core i7 2.93 Ghz</li> </ul> <p>Results (for 1 million inserts/selects) :</p> <pre><code>MySQL insert elapse : 0:02:52.143803 MySQL select elapse : 0:04:43.675914 Mongodb insert elapse : 0:00:49.038416 -&gt; mongodb much faster for insert Mongodb select elapse : 0:05:10.409025 -&gt; ...but slower for quering (thought was the opposite) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload