Slightly adapted program, different linux box (Linux domain.nl 2.4.18 #8
SMP Mon Mar 25 22:28:36 CET 2002 i686 unknown)
===========================================================================
use threads ();
use threads::shared ();
our $vara : unique = 'a' x 100000;
our $varb : unique = 'b' x 100000;
our $varc : unique = 'c' x 100000;
our $vard : unique = 'd' x 100000;
our $vare : unique = 'e' x 100000;
our $varf : unique = 'f' x 100000;
our $varg : unique = 'g' x 100000;
our $varh : unique = 'h' x 100000;
our $vari : unique = 'i' x 100000;
our $varj : unique = 'j' x 100000;
our $vara : unique = 'a' x 100000;
our $varb : unique = 'b' x 100000;
our $varc : unique = 'c' x 100000;
our $vard : unique = 'd' x 100000;
our $vare : unique = 'e' x 100000;
our $varf : unique = 'f' x 100000;
our $varg : unique = 'g' x 100000;
our $varh : unique = 'h' x 100000;
our $vari : unique = 'i' x 100000;
our $varj : unique = 'j' x 100000;
our $vara : unique = 'a' x 100000;
our $varb : unique = 'b' x 100000;
our $varc : unique = 'c' x 100000;
our $vard : unique = 'd' x 100000;
our $vare : unique = 'e' x 100000;
our $varf : unique = 'f' x 100000;
our $varg : unique = 'g' x 100000;
our $varh : unique = 'h' x 100000;
our $vari : unique = 'i' x 100000;
our $varj : unique = 'j' x 100000;
our $vark : unique = 'k' x 100000;
our $varl : unique = 'l' x 100000;
our $varm : unique = 'm' x 100000;
our $varn : unique = 'n' x 100000;
our $varo : unique = 'o' x 100000;
our $varp : unique = 'p' x 100000;
our $varq : unique = 'q' x 100000;
our $varr : unique = 'r' x 100000;
our $vars : unique = 's' x 100000;
our $vart : unique = 't' x 100000;
our $varu : unique = 'u' x 100000;
our $varv : unique = 'v' x 100000;
our $varw : unique = 'w' x 100000;
our $varx : unique = 'x' x 100000;
our $vary : unique = 'y' x 100000;
our $varz : unique = 'z' x 100000;
for ( my $i=1; $i < 10; $i++ ) {
threads->new( sub { 1 while 1 } );
}
warn "threads started\n";
<>
===========================================================================
Again, the concept was simple: wait until "threads started" shows up on the
screen and then look at what "top" is telling me. And of course, I used
different permutations of "", "my", "our", ": shared" and ": unique". I'll
list them in order of memory usage (in ascending order). I've skipped the
RSS and SHARE fields this time, because they did not provide any extra
information.
permutation SIZE
----------------------------------------------------
our $vara : unique 33972
my $vara 56796
$vara 56836
our $vara 56860
my $vara : unique 57012
my $vara : shared 59568
our $vara : shared 59584
After this, I took the ones with the lowest memory footprint, the "our
$vara : unique" case, and ran it without any extra threads, with one, two
and three extra threads. And for extra reference, ran the same without any
of the 26 variables:
no threads 1 2 3 extra threads
no vars 2296 2792 3188 3584
with vars 7384 10428 13376 16316
What conclusions can we draw from this for perl 5.8.0 ?
- using the ": shared" attribute is _not_ a way to save memory, quite the
contrary. It uses even _more_ memory than unshared. This seems
counter-intuitive to me and may be a bug.
- using the " : unique" attribute _only_ makes sense on "our" variables,
_not_ on "my" variables. This also seems counter-intuitive to me. This
may be a bug, possibly the same that is causing : shared not to save any
memory.
- the overhead for starting a new thread is somehow related to the size of
data. This makes sense for non : unique cases where the data is copied to
the threads. But even in the our : unique case, data seems to be copied to
the threads, albeit it not the entire amount. At least, memory usage is
directly related to the amount of : unique data.
I have no idea whether this conforms to what the p5p ithreads developers
think it should do. Or whether this may be influenced by the
STRANGE_MALLOC issue that Chip Salzenberg found.
Hope this helps anybody. Comments welcome. Patches too... ;-)
Liz