Friday, January 11, 2013

Re: Mongo php process slowness



On Thursday, 10 January 2013 09:16:13 UTC+1, Raju Bishnoi wrote:
Hi,

I run the below php code with Mongo & MongoClient to insert 100k records.
Mongo took 70-75 second to complete and MongoClient took 440-450 second.

$start = microtime(true);

$objBaseMongoRecord = new BaseMongoRecord();

$objBaseMongoRecord->
setCollectionName("mongotest");

$i = 0;
while ($i < 1000000) {

    $data = array(
        "name" => array(
            "firstname" => "raju" . $i,
            "lastname" => "bishnoi" . $i),
        "address" => array(
            "street" => "raju" . $i,
            "city" => "city" . $i,
            "state" => "state" . $i,
            "country" => "country" . $i,
            "zipcode" => "1" . $i),
        "officephone" => "25412541",
        "homephone" => "625412541",
        "status" => "A",
        "date" => date('Y-m-d:H-i-s'),
        "time" => time());

    $objBaseMongoRecord->ensureIndex(array("time" => 1));
    $objBaseMongoRecord->insert($data);
    $i++;
}

$duration = microtime(true) - $start;
// print in the format 1.2345 for better reading
printf("took %0.4d seconds", $duration);

Can anyone tell me why MongoClient tooks more time and how to make it fast.

Don't do via php, what you can do directly on the database.

if you run code like this directly on the server there is 0 network traffic. if you do it with any other client, you have constant traffic as your php code sends each bit of data to the database. 

First optimize your code - you're dong a bulk insert - so do exactly that, one insert call. In this example send MongoCode to the db, it'll execute in the shortest execution time and come back.

AD

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: