Re: perl garbage collector

From: Jean-Max Reymond <jmreymond(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: perl garbage collector
Date: 2005-06-28 18:47:27
Message-ID: 4b09a0c0506281147bc4b27f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

2005/6/28, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Jean-Max Reymond <jmreymond(at)gmail(dot)com> writes:
> > I have a stored procedure written in perl and I doubt that perl's
> > garbage collector is working :-(
> > after a lot of work, postmaster has a size of 1100 Mb and I think
> > that the keyword "undef" has no effects.
>
> Check the PG list archives --- there's been previous discussion of
> similar issues. I think we concluded that when Perl is built to use
> its own private memory allocator, the results of that competing with
> malloc are not very pretty :-(. You end up with a fragmented memory
> map and no chance to give anything back to the OS.

thanks Tom for your advice. I have read the discussion but a small
test is very confusing for me.
Consider this function:

CREATE FUNCTION jmax() RETURNS integer
AS $_$use strict;

my $i=0;
for ($i=0; $i<10000;$i++) {
my $ch = "0123456789"x100000;
my $res = spi_exec_query("select * from xdb_child where
doc_id=100 and ele_id=3 ");
}
my $j=1;$_$
LANGUAGE plperlu SECURITY DEFINER;

ALTER FUNCTION public.jmax() OWNER TO postgres;

the line my $ch = "0123456789"x100000; is used to allocate 1Mb.
the line my $res = spi_exec_query("select * from xdb_child where
doc_id=100 and ele_id=3 limit 5"); simulates a query.

without spi_exec_quer, the used memory in postmaster is a constant.
So, I think that pl/perl manages correctly memory in this case.
with spi_exec_query, postmaster grows and grows until the end of the loop.
Si, it seems that spi_exec_query does not release all the memory after
each call.
For my application (in real life) afer millions of spi_exec_query, it
grows up to 1Gb :-(

--
Jean-Max Reymond
CKR Solutions Open Source
Nice France
http://www.ckr-solutions.com

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Bruno Wolff III 2005-06-28 19:31:23 Re: tricky query
Previous Message Tom Lane 2005-06-28 18:14:42 Re: Too slow querying a table of 15 million records