develooper Front page | perl.perl5.porters | Postings from September 2010

Re: [perl #77854] Memory leak using threads

Thread Previous | Thread Next
Dave Mitchell
September 18, 2010 03:33
Re: [perl #77854] Memory leak using threads
Message ID:
On Tue, Sep 14, 2010 at 08:52:19AM -0700, Jon Combe wrote:
> I have a Perl script using threads and have found that when it has been
> running for a period of time the memory usage gets very high (around
> 1GB). I have managed to find the problem seems to be thread related. To
> help isolate the problem I created the simple Perl script below. This
> simply spawns a fixed number of threads and each thread simply
> increments and then decrements a thread counter. At the end, the code
> checks the thread count is zero (it should be) and then counts down from
> 1 to 30. This gives me 30 seconds to capture the final memory usage
> prior to the script ending. I have observed the following memory usage
> when changing the number of threads in the first "for" loop in terms of
> memory usage when running the script:-
> Thread Count            VIRT MEM        RES MEM
> 50000                   106m            93m
> 100000                  195m            181m
> 150000                  287m            275m
> Note that this output is from a version of Perl I compiled myself. I've
> also tried with the version of Perl that comes packaged with CentOS 5.4
> (5.8.8) and that comes with Ubuntu 10.2 (Perl 5.10.1) with similar
> results. I've also tried removing the shared variable ($thread_count)
> and making the subroutine entirely empty with the same results. I
> suspect therefore it's a memory leak in creating threads.

I can reproduce this on 5.8.8, but not 5.10.0, 5.12.0 nor 5.13.4.

> This email is private and may be confidential and is for the intended
> recipient only. If misdirected, please notify us by telephone and
> confirm that it has been deleted from your system and any copies
> destroyed. If you are not the intended recipient you are strictly
> prohibited from using, printing, copying, distributing or disseminating
> this email or any information contained in it.

Ho ho.

"Strange women lying in ponds distributing swords is no basis for a system
of government. Supreme executive power derives from a mandate from the
masses, not from some farcical aquatic ceremony."
    -- Dennis, "Monty Python and the Holy Grail"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About