Re: Mongo php process slowness

2013-01-11 Thread AD7six


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 < 100) {
>
> $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
http://php.net/manual/en/class.mongocode.php
http://php.net/manual/en/mongocollection.batchinsert.php

-- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Mongo php process slowness

2013-01-10 Thread mulianto
hi 

have you try insert the record in 1 call like batch/bulk insert. i don't know 
if mongo can do this.



Sent from my iPhone

On 10 Jan 2013, at 16:16, 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 < 100) {
> 
> $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+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  

-- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Mongo php process slowness

2013-01-10 Thread Raju Bishnoi
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 < 100) {

$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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.