in reply to Re^2: Threaded script eating memory
in thread Threaded script eating memory

There really is no better way to work around fixed core bugs than upgrade.

However, if memory serves, the main problems with threads in 5.8.5 was leaking closures. It is possible that my rearranging your code (physically within the source file) to avoid unnecessary closures you might be able to avoid the leaks you are seeing.

The first step is to move all your subroutines to the top of the source file after the use lines, but before you declare any package level variables. Eg: for your demo code, you might do something like this:

use threads; use threads::shared qw(share); use Thread::Queue; use Thread::Semaphore; sub load_queue { my $q = shift; my $loading = shift; my $i = 1; my $ary = &share( [] ); while ( my $v = ["this is a test" x 250] ) { # print "$v->[0]\n"; push @$ary, $v->[0]; unless ( $i++ % 10000 ) { print "$i\n"; $q->enqueue($ary); $ary = &share( [] ); while ( $q->pending() > 20 ) { # try not to eat tooo mu +ch memory select(undef,undef,undef,.1); } } } $q->enqueue($ary) if @$ary; $$loading = 0; } sub type_issues { my ( $q, $loading ) = @_; #my $DB = IDC::Data->new( bes => 'webdev' ); print "Type issues\n"; my $issues; while ( ( $issues = $q->dequeue() ) ) { print "Got ".@$issues." - ".$q->pending()."\n"; select(undef,undef,undef,.1); } } my $q = Thread::Queue->new(); my $loading : shared = 1; my $threads : shared = 0; my $thr = threads->create( \&load_queue, $q, \$loading ); $thr->detach(); $|++; my @threads; for ( 1 .. 6 ) { my $thr = threads->create( \&{type_issues}, $q, \$loading, $thread +s ); push @threads, $thr; } $_->join() for @threads;

Note:That makes no attempt to address any of the other issues I mention in my update to my first reply above.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW

Replies are listed 'Best First'.
Re^4: Threaded script eating memory
by suaveant (Parson) on Jun 23, 2009 at 14:13 UTC
    It didn't help, but that's probably just as well... hocus-pokery like that is a maintenance accident waiting to happen. Thanks for the help, though.

                    - Ant
                    - Some of my best work - (1 2 3)