Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

You already have some worthy replies to your question, but I thought I'd take a run at a more visual presentation. I create a bunch of threads that each create a large-ish array of random numbers and return after a short delay.

After about 30 minutes on my 64-bit linux system it was clear the memory was not increasing; it hit its maximum within the first several seconds of the test while the threads were spooling up:

Memory leak test. Ctrl-C to stop. 20 threads (17831 lifetime), 845.99 MiB RSS [================ ] / ^C

Code below. Certainly not my most elegant work. :-)

use warnings; use strict; use threads; use threads::shared; use Time::HiRes qw/sleep/; my $DELAY = 2.5; # Delay for returning from threads my $NUM = 20; # Number of active threads to spawn my $total :shared = 0; # Total threads that we have created my @whirly = qw(| / - \\); printf "Memory leak test. Ctrl-C to stop.\n\n"; # Consume a lot of memory for a few seconds sub highmem { my @a = rand() x 1000000; { lock $total; $total++; } sleep($DELAY); } # Return total perl memory usage in bytes, with a progress # bar and maximum memory usage { my $max_len = 1; # Maximum bar length we've seen so far my $max_mem = 1; # Maximum memory we've seen so far sub print_mem { my $rss = `ps -p $$ -o rss=`; chomp($rss); $rss /= 2**10; # MiB my $bar = "=" x int($rss/50); $max_len = length($bar) if (length($bar) > $max_len); my $pad = " " x ($max_len - length($bar)); my $whirly = shift @whirly; push @whirly, $whirly; printf "\r%2d threads (%4d lifetime), " ."%7.2f MiB RSS [%s%s] %s ", scalar threads->list(), $total, $rss, $bar, $pad, $whirly; } } # Main loop; join() threads when we can, and create new # threads once every time through the loop if we (still) # have less than $NUM threads running. Print total Perl # memory usage. do { $_->join for (threads->list(threads::joinable)); threads->create(\&highmem) if (threads->list() < $NUM); print_mem(); } while(sleep(0.1));

In reply to Re: Do threads do global destruction? by rjt
in thread Do threads do global destruction? by DrWhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (6)
    As of 2015-07-31 00:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (274 votes), past polls