Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Very slow query
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
marcandre  
View profile  
 More options Sep 10 2012, 11:48 am
From: marcandre <malegr...@gmail.com>
Date: Mon, 10 Sep 2012 08:48:11 -0700 (PDT)
Local: Mon, Sep 10 2012 11:48 am
Subject: Re: Very slow query

I get this reponse when I call var_dump($cursor->explain());  :

array(15) { ["cursor"]=> string(11) "BasicCursor" ["isMultiKey"]=>
bool(false) ["n"]=> int(30) ["nscannedObjects"]=> int(1148) ["nscanned"]=>
int(1148) ["nscannedObjectsAllPlans"]=> int(1148) ["nscannedAllPlans"]=>
int(1148) ["scanAndOrder"]=> bool(false) ["indexOnly"]=> bool(false)
["nYields"]=> int(0) ["nChunkSkips"]=> int(0) ["millis"]=> int(2)
["indexBounds"]=> array(0) { } ["allPlans"]=> array(1) { [0]=> array(5) {
["cursor"]=> string(11) "BasicCursor" ["n"]=> int(30) ["nscannedObjects"]=>
int(1148) ["nscanned"]=> int(1148) ["indexBounds"]=> array(0) { } } }
["server"]=> string(12) "host:27017" }

I am limiting the find to avoid display every documents in the same page  .

Le lundi 10 septembre 2012 17:31:40 UTC+2, Gianfranco a écrit :

> If you run explain() on the cursor you can see why is taking that long.

> var_dump($cursor->explain());

> Do that on one and see if it's using an index (BtreeCursor)

> Another problem could be that you are limiting the find() results to 30
> and then doing a skip.
> This is not every efficient, and I don't understand from your code exactly
> why are you doing that.

> You can also try to increase the timeout of the cursor and try if that
> helps

> On Monday, September 10, 2012 4:07:30 PM UTC+1, marcandre wrote:

>> I don't think that Postgres causes the bach being slow, because when I
>> use MongoDB as a  reseach engin  to research documents by keywords ,

>> my reseach engin is very slow or ends with an error of timeout : *Fatal
>> error: Uncaught exception 'MongoCursorTimeoutException' with message
>> 'cursor timed out (timeout: 30000, time left: 0:0, status: 0)'*  .

>> This my code for research douments :

>> $cnx_mongo = new Mongo("127.0.0.1", array("persist" => "x"));
>> $db = $cnx_mongo->my_database;
>> $ma_collection = $db->my_collection;

>> $who = array();
>>  if(count($ArrayWord) > 1) {
>>   $tmp = array();
>>   foreach ($ArrayWord as $q) {
>>    $tmp[] = new MongoRegex( "/". strtolower($q) ."/" );
>>   }
>>   $who['tags'] = array('$all' => $tmp);
>>  }else{
>>   $who['tags'] = new MongoRegex( "/". strtolower($mot) ."/" );
>>  }

>> $cursor = $ma_collection->find($who)->limit(30)->skip(($off_set - 1)*30);

>> $cursor->timeout(1000);

>> print($cursor->count());

>> foreach($cursor as $obj){

>> $id_prod = $obj["id_prod"];
>> $ref_constr = $obj["ref_constr"];
>> $img_prod = $obj["img_prod_petit"];
>> $zoom = $obj["img_prod_zoom"];
>> $titre = utf8_decode($obj["titre_prod"]);

>> $prix_max = $obj["prix_max"];
>> $prix_min = $obj["prix_min"];
>> $nb_offres = $obj["nb_offres"];
>> $max_dispo = $obj["max_dispo"];
>> $min_dispo = $obj["min_dispo"];
>> $id_assoc = $obj["id_assoc"];
>> }

>> Le lundi 10 septembre 2012 16:42:35 UTC+2, Gianfranco a écrit :

>>> As you did correctly, if this is not a live production database, you
>>> can ensureIndex() after you finish the batch.
>>> Because if there's an index, the database needs to update the index
>>> every time there is new document inserted.

>>> Is it possible, and i'm just wondering here, that PostgreSQL is one of
>>> the causes of the batch being slow?
>>> If not do you have any more information on why is not?

>>> On Monday, September 10, 2012 1:50:17 PM UTC+1, marcandre wrote:

>>>> Good afternoon,

>>>> I'am using MongoDB with 350 000 documents and php. The problem is the
>>>> php reads documents very slowly .

>>>> When I'm updating documents I drop the database and I insert the
>>>> documents : during this processus the inserts are very long .

>>>> I don't understand, I putted indexes .

>>>> I show you a piece of my php code when I updating documents :

>>>> $cnx_mongo = new Mongo("127.0.0.1", array("persist" => "x"));

>>>>  $db = $cnx_mongo->my_database;
>>>>  $ma_collection = $db->my_collection;

>>>>  $response = $ma_collection->drop();
>>>>  $response = $db->drop();

>>>>  $db = $cnx_mongo->my_database;
>>>>  $ma_collection = $db->my_collection;

>>>>  ///I Import data from a database Postgres

>>>>  ///I put index in a fiel named tags
>>>>  $ma_collection->ensureIndex("tags");

>>>> This is the code when php reads documents :

>>>> ///Research of documents who containts key words
>>>> $cnx_mongo = new Mongo("127.0.0.1", array("persist" => "x"));
>>>> $db = $cnx_mongo->my_database;
>>>> $ma_collection = $db->my_collection;

>>>>  //Get back keywords researching by tags fields
>>>>  $who = array();
>>>>  if(count($ArrayWord) > 1) {
>>>>   $tmp = array();
>>>>   foreach ($ArrayWord as $q) {
>>>>    $tmp[] = new MongoRegex( "/". strtolower($q) ."/" );
>>>>   }

>>>>   $who['tags'] = array('$all' => $tmp);

>>>>  }else{
>>>>   $who['tags'] = new MongoRegex( "/". strtolower($mot) ."/" );
>>>>  }

>>>>  $cursor = $ma_collection->find($who)->limit(30)->skip(60);

>>>>  $cursor->timeout(1000);

>>>>  print($cursor->count()); // I display the number of documents

>>>>  foreach($cursor as $obj){
>>>>   ///I display the results of document  
>>>>  }

>>>> The tags field containts array keywords .

>>>> What should I do to resolve this problem ?

>>>> I checked the RAM (6 Go of physical RAM and 4 Go of available memory) .

>>>> How can I check the cause of this slow reads and inserts ?

>>>> I there is something to configure in mongodb ?

>>>> Best regards .


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.