Yeah. I wish I understood, or one of the guys that know would tell us, where the memory growth actually arises.

If you run this (having substituted a suitable mem routine for your platform), and then play with the various values, it's really difficult to devine where the growth occurs and what controls how much?

#! perl -slw use strict; use Data::Dumper; use threads; use threads::shared; no warnings 'misc'; our $N ||= 100; our $D ||= 1.e5; our $SHARED; sub mem { my @filler = 1 .. $D unless @_; my @filler : shared = 1 .. $D if @_; my( $usage ) = `tasklist /NH /FI \"pid eq $$\" ` =~ m[ (\S+) \s+ +K \s* $ ]x; $usage =~ tr[,][]d; return 1024 * $usage; } my @data = 1 .. $D unless $SHARED; my @data:shared = 1 .. $D if $SHARED; printf "start : %6d\n", my $start = mem; for ( 1 .. $N ) { my $thread = threads->create( \&mem ); printf "%3d : %6d\n", $_, $thread->join; } printf "end : %6d\n", my $end = mem; printf "Growth: %6d\n", $end - $start;

Here are some typical results on my system:

c:\test\fork>..\534254 -N=10 -D=1 start : 3141632 1 : 3993600 2 : 4018176 3 : 4018176 4 : 4022272 5 : 4038656 6 : 4038656 7 : 4022272 8 : 4018176 9 : 4055040 10 : 4055040 end : 4034560 Growth: 892928 c:\test\fork>..\534254 -N=10 -D=1 -SHARED start : 3145728 1 : 3997696 2 : 4022272 3 : 4022272 4 : 4030464 5 : 4026368 6 : 4022272 7 : 4059136 8 : 4059136 9 : 4059136 10 : 4059136 end : 4042752 Growth: 897024 c:\test\fork>..\534254 -N=10 -D=1e3 start : 3211264 1 : 4128768 2 : 4149248 3 : 4149248 4 : 4157440 5 : 4149248 6 : 4153344 7 : 4157440 8 : 4161536 9 : 4157440 10 : 4198400 end : 4132864 Growth: 921600 c:\test\fork>..\534254 -N=10 -D=1e3 -SHARED start : 3555328 1 : 4345856 2 : 4378624 3 : 4382720 4 : 4386816 5 : 4395008 6 : 4390912 7 : 4390912 8 : 4390912 9 : 4386816 10 : 4395008 end : 4374528 Growth: 819200 c:\test\fork>..\534254 -N=10 -D=1e5 start : 9723904 1 : 17874944 2 : 17907712 3 : 17920000 4 : 17940480 5 : 17924096 6 : 17940480 7 : 17936384 8 : 17944576 9 : 17936384 10 : 17952768 end : 11743232 Growth: 2019328 c:\test\fork>..\534254 -N=10 -D=1e5 -SHARED start : 43819008 1 : 48697344 2 : 48721920 3 : 48726016 4 : 48726016 5 : 48730112 6 : 48730112 7 : 48730112 8 : 48734208 9 : 48738304 10 : 48738304 end : 44195840 Growth: 376832

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^2: threads: spawn early to avoid the crush. by BrowserUk
in thread threads: spawn early to avoid the crush. by BrowserUk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.