Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL vs MongoDB 1000 reads
    primarykey
    data
    text
    <p>I have been very excited about MongoDb and have been testing it lately. I had a table called posts in MySQL with about 20 million records indexed only on a field called 'id'.</p> <p>I wanted to compare speed with MongoDB and I ran a test which would get and print 15 records randomly from our huge databases. I ran the query about 1,000 times each for mysql and MongoDB and I am suprised that I do not notice a lot of difference in speed. Maybe MongoDB is 1.1 times faster. That's very disappointing. Is there something I am doing wrong? I know that my tests are not perfect but is MySQL on par with MongoDb when it comes to read intensive chores. </p> <p><br> Note:</p> <ul> <li>I have dual core + ( 2 threads ) i7 cpu and 4GB ram</li> <li>I have 20 partitions on MySQL each of 1 million records</li> </ul> <p><strong>Sample Code Used For Testing MongoDB</strong></p> <pre class="lang-php prettyprint-override"><code>&lt;?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_taken = 0; $tries = 100; // connect $time_start = microtime_float(); for($i=1;$i&lt;=$tries;$i++) { $m = new Mongo(); $db = $m-&gt;swalif; $cursor = $db-&gt;posts-&gt;find(array('id' =&gt; array('$in' =&gt; get_15_random_numbers()))); foreach ($cursor as $obj) { //echo $obj["thread_title"] . "&lt;br&gt;&lt;Br&gt;"; } } $time_end = microtime_float(); $time_taken = $time_taken + ($time_end - $time_start); echo $time_taken; function get_15_random_numbers() { $numbers = array(); for($i=1;$i&lt;=15;$i++) { $numbers[] = mt_rand(1, 20000000) ; } return $numbers; } ?&gt; </code></pre> <p><br> <strong>Sample Code For Testing MySQL</strong></p> <pre class="lang-php prettyprint-override"><code>&lt;?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $BASE_PATH = "../src/"; include_once($BASE_PATH . "classes/forumdb.php"); $time_taken = 0; $tries = 100; $time_start = microtime_float(); for($i=1;$i&lt;=$tries;$i++) { $db = new AQLDatabase(); $sql = "select * from posts_really_big where id in (".implode(',',get_15_random_numbers()).")"; $result = $db-&gt;executeSQL($sql); while ($row = mysql_fetch_array($result) ) { //echo $row["thread_title"] . "&lt;br&gt;&lt;Br&gt;"; } } $time_end = microtime_float(); $time_taken = $time_taken + ($time_end - $time_start); echo $time_taken; function get_15_random_numbers() { $numbers = array(); for($i=1;$i&lt;=15;$i++) { $numbers[] = mt_rand(1, 20000000); } return $numbers; } ?&gt; </code></pre>
    singulars
    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.
 

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