Re: Possible serious memory leak in MDB2
| From: | Bruno Barberi Gnecco | Date: | Wed, 25 Apr 2007 14:10:04 +0000 |
| Subject: | Re: Possible serious memory leak in MDB2 | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-27146@lists.php.net to get a copy of this message | ||
Lorenzo Alberton <l.alberton <at> quipo.it> writes:
> can you try with the latest CVS version and
> tell me if the memory leak is still present,
> and if so, can you send me a reproducing
> script?
>
> Thanks in advance
>
> Best regards,
1234567890123456789012345678901234567890123456789012345678901234567890
I'll try to send you a reproducing script later today or
tomorrow, but I'm inclined to believe, after some tests, that the
problem isn't in MDB2. It's very easy to reproduce it, anyway:
just run a lot of INSERTs and you'll see it. Here's the sketch of
the code:
$query = 'INSERT INTO table (field1, field2, field3, field4, field5)' .
' VALUES (?, ?, ?, ?, ?)';
$prepared = $this->db->prepare($query, null, MDB2_PREPARE_MANIP);
foreach ($data_array as $data) {
echo "Memory before: " . memory_get_usage() . "\n";
$res = $prepared->execute($data);
echo "Memory after: " . memory_get_usage() . "\n";
}
If you run a SELECT instead of a INSERT, the memory decreases and
eventually becomes negative.
I think you should read the thread "Reducing memory consumption"
in comp.lang.php. Google groups isn't carrying most of the posts, who
knows why.
Here's my last post on the subject:
As I mentioned in the other post, I found out that it isn't
DOM eating all the memory, but the SQL queries. Apparently I ran into
two bugs:
1) prepare/Execute has a memory leak. This could be happening in MDB2
or in PHP itself, perhaps in the mysqli extension. This happens
consistently and eventually exhausts memory. [this happens for INSERTs,
I haven't tested SELECTs]
2) there is a problem in mysqli queries that seem to confuse the
allocated memory counting, but it's not a serious bug (i.e., it
doesn't crash. I successfully completed a long run of my script,
which added some 27k entries to the database. Despite the memory
becoming negative, it didn't crash, and apparently there was no
corruption or unexpected results (not that I could see so far).
In this successful #2 run, what I did was get the mysqli connection
from mdb2 (with getConnection()) and run mysqli_query() directly. So
this problem isn't in MDB2: it's either in PHP itself or in the mysqli
extension. My *guess* is that PHP memory system is counting something
wrong when it allocates memory. I watched top(1) while the script ran,
and it didn't consume a lot of memory (10-16 MB), which is a little
more than I'd expect, but I was including MDB2 and other stuff. If I
didn't exhaust the memory first, I'd have never noticed that the memory
count was negative.
I'm still at a loss of whom should I report this bug to. Any
suggestions?