(Fwd) Strange memory leak (?) with DBI ? DBD::Pg
am 21.10.2007 22:48:44 von Tim.Bunce----- Forwarded message from Troy Davis
x-pobox-client-address: 216.37.68.82
x-pobox-client-name: cafeautism.net
Date: Sat, 20 Oct 2007 11:22:42 -0500
From: Troy Davis
To: Tim.Bunce@pobox.com
Subject: Strange memory leak (?) with DBI
Hello Tim,
I've been trying to track down the source of mysteriously missing memory in
my mod_perl2 environment. I've boiled part of the problem down to the
following, and was wondering if you might be able to explain what's going
on. Consider the following:
---snip---
use DBI;
while (1) {
$dbh = DBI->connect('DBI:Pg:', 'db_name', 'db_pass',
{ RaiseError => 1 } );
# Just pick some random ID; I've verified 1-124 are all there.
my $id = int rand(124);
# The database is Postgres and the "blob" column is of type bytea.
# This field in the database is always 901120 bytes long.
my ($contents) = $dbh->selectrow_array('
SELECT blob FROM blobs WHERE id = ?
', undef, $id);
$dbh->disconnect;
}
---snip---
If I run the above script while doing the following in another console:
while [ 1 ]; do free; ps u -C perl; echo; sleep 3; done
Then the following happens. Watch the VSZ counter for the perl process:
---snip---
total used free shared buffers cached
Mem: 516856 317948 198908 0 72056 176496
-/+ buffers/cache: 69396 447460
Swap: 979924 4840 975084
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1165 39.5 1.0 85276 5340 pts/1 S+ 11:15 0:02 perl foo
total used free shared buffers cached
Mem: 516856 321792 195064 0 72068 176504
-/+ buffers/cache: 73220 443636
Swap: 979924 4840 975084
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1165 40.7 1.1 134492 5772 pts/1 S+ 11:15 0:03 perl foo
total used free shared buffers cached
Mem: 516856 321304 195552 0 72072 176504
-/+ buffers/cache: 72728 444128
Swap: 979924 4840 975084
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1165 43.5 1.0 213052 5660 pts/1 S+ 11:15 0:06 perl foo
total used free shared buffers cached
Mem: 516856 318708 198148 0 72080 176500
-/+ buffers/cache: 70128 446728
Swap: 979924 4840 975084
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1165 41.7 1.1 268320 5972 pts/1 S+ 11:15 0:07 perl foo
total used free shared buffers cached
Mem: 516856 318840 198016 0 72084 176504
-/+ buffers/cache: 70252 446604
Swap: 979924 4840 975084
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1165 42.1 1.5 314396 7756 pts/1 S+ 11:15 0:08 perl foo
---snip---
This will continue indefinitely until it runs out of memory (under
Apache/mod_perl2, Apache eventually dies with "Out of memory!", though again
the above is completely independent of Apache). However, I don't understand
why this is, as there's plenty of both physical memory and swap free the
whole time.
This is happening on a Debian etch box. Here are all the relevant package
versions I thought you would want to see:
ii libdbd-pg-perl 1.49-2
ii libdbi-perl 1.53-1
ii perl-base 5.8.8-7
ii postgresql-8.1 8.1.9-0etch1
I checked the changelog for DBI and nothing that was fixed in versions >1.53
jumped out at me as being related to this. I'd have to go through a fair
bit of contorting to get 1.59 working on this box, but if you suspect that
this is already been fixed, then let me know.
Thank you for any help you might be able to offer.
--
Troy Davis
tdavis@tdavis.org
http://www.tdavis.org/
----- End forwarded message -----
----- Forwarded message from Troy Davis
x-pobox-client-address: 216.37.68.82
x-pobox-client-name: cafeautism.net
Date: Sat, 20 Oct 2007 11:36:45 -0500
From: Troy Davis
To: Tim.Bunce@pobox.com
Subject: Re: Strange memory leak (?) with DBI
On Sat, Oct 20, 2007 at 11:22:42AM -0500, Troy Davis wrote:
> I've been trying to track down the source of mysteriously missing memory in
> my mod_perl2 environment. I've boiled part of the problem down to the
> following, and was wondering if you might be able to explain what's going
> on. Consider the following:
>
> ---snip---
Sorry, I should have clarified that the script that followed is being run
from a console with regular old perl, completely independent of
Apache/mod_perl2.
--
Troy Davis
tdavis@tdavis.org
http://www.tdavis.org/
----- End forwarded message -----
----- Forwarded message from Troy Davis
x-pobox-client-address: 216.37.68.82
x-pobox-client-name: cafeautism.net
Date: Sun, 21 Oct 2007 14:08:30 -0500
From: Troy Davis
To: Tim.Bunce@pobox.com
Subject: Re: Strange memory leak (?) with DBI
On Sat, Oct 20, 2007 at 11:22:42AM -0500, Troy Davis wrote:
> I've been trying to track down the source of mysteriously missing memory
> in my mod_perl2 environment. I've boiled part of the problem down to the
> following, and was wondering if you might be able to explain what's going
> on. Consider the following:
I wanted to let you know that I was also able to repeat this problem on
Ubuntu Gutsy. The relevant version numbers in this case were:
ii libdbd-pg-perl 1.49-2build1
ii libdbi-perl 1.57-1
ii perl-base 5.8.8-7ubuntu
ii postgresql 8.2.5-1.1
--
Troy Davis
tdavis@tdavis.org
http://www.tdavis.org/
----- End forwarded message -----