Thursday, January 10, 2013

Mongo php process slowness

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.

Thanks
Raju

--
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: