PHP Driver findOne Memory Leak

78 views
Skip to first unread message

Benjamin Neu

unread,
Apr 16, 2014, 11:27:45 AM4/16/14
to mongod...@googlegroups.com

I have found some old posts on stackoverflow regarding the problem of a memory leak with the php mongodb driver. But none gave a final solution or explenation for older versions of the php mongodb driver or for the version I am using.

Also the driver changelog does not show any recent updates regarding a memory leak.

My Version of the Driver is 1.4.5 (stable) with PHP 5.3.10

Code with Debug echos:

     echo memory_get_usage()." in MB : "; 
        echo memory_get_usage()/1024/1024;
        echo "<br>";
        unset($cursor);
        $dt = new DateTime($day." 00:00:00", new DateTimeZone($this->timezone));
        $mongodate = new MongoDate($dt->getTimestamp());
       // print_r($mongodate);
        $cursor = $dc->findOne(array('keyword' => $keyword, 'date' => $mongodate));


        echo "Cursor loaded Doc (".$cursor['_id'].") : ";
        echo memory_get_usage()." in MB : "; 
        echo memory_get_usage()/1024/1024;
        echo "<br>";

** Echos True Memory Usage**

3932160 in MB : 3.75
Cursor geladen Doc (534cdee3c30fd1b8ee0bb641) : 218305980 in MB : 208.1928062439

Code with Debug echos True Memory Usage:

        echo memory_get_usage(true)." in MB : "; 
        echo memory_get_peak_usage(true)/1024/1024;
        echo "<br>";
        unset($cursor);
        $dt = new DateTime($day." 00:00:00", new DateTimeZone($this->timezone));
        $mongodate = new MongoDate($dt->getTimestamp());
       // print_r($mongodate);
        $cursor = $dc->findOne(array('keyword' => $keyword, 'date' => $mongodate));
        /*
        echo "<pre>";
        print_r($cursor);
        echo "</pre>";
        */

        echo "Cursor loaded Doc (".$cursor['_id'].") : ";
        echo memory_get_usage(true)." in MB : "; 
        echo memory_get_peak_usage(true)/1024/1024;
        echo "<br>";

** Echos True Memory Usage**

3932160 in MB : 3.75
Cursor loaded Doc (534cdee3c30fd1b8ee0bb641) : 218628096 in MB : 224.5

So only one Documents causes an encrease by over 200 MB of memory.

bitrs3:PRIMARY> var doc = db.dailies.findOne({"_id" : ObjectId("534cdee3c30fd1b8ee0bb641")})
bitrs3:PRIMARY> Object.bsonsize(doc)
16754823

The document loaded is truely not small, it has 16754823 Bytes so reaches the maximum Bson Size of 16 MB

Still I am wondering if it is normal that the findOne + cursor operation which creates an array out of the results needs so much memory.

Hannes Magnusson

unread,
Apr 16, 2014, 9:27:45 PM4/16/14
to mongod...@googlegroups.com
Hi Benjamin

This does indeed look like a problem in our driver.

If you have a JIRA account (on https://jira.mongodb.org/) could you send me your username (or the email address you used to sign up)? (and if you don't have an account, would you mind creating one?) :)

I'd like to create a private ticket in our jira so I can ask you some followup questions (e.g. the actual document in question for example).

Also, do you have the link to the StackOverflow question you mentioned?

-Hannes

Sam Millman

unread,
Apr 17, 2014, 2:53:21 AM4/17/14
to mongod...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/17f35f49-e487-474d-9f22-59c18d13439a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages