Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Threaded script eating memory

by suaveant (Parson)
on Jun 22, 2009 at 21:00 UTC ( [id://773764]=note: print w/replies, xml ) Need Help??


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

Not the simplest of options... I'm on a shared system managed by other people... I can try on another system of mine.. maybe I can convince people to upgrade... or maybe I'll just have to re-write it in a less clever fashion.

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

Replies are listed 'Best First'.
Re^3: Threaded script eating memory
by BrowserUk (Patriarch) on Jun 22, 2009 at 21:11 UTC

    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.
      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)

Re^3: Threaded script eating memory
by ikegami (Patriarch) on Jun 22, 2009 at 22:48 UTC
    Different versions of Perl can happily co-habit one machine.
      True, though I don't know if the Admins would be big fans of maintaining two... I have often considered maintaining my own Perl in our product releases though... I already handle my own Perl modules this way.

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

        You don't need any special permissions to install Perl on a machine, so yeah, you could maintain your own Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://773764]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-23 17:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found