Hello.
I have a small test program (below) that behaves in a
way that I can't quite explain. As it is, this program
will run fast and steadily until memory is exhausted. If
the IO::Handle->new() is commented out and lines 3,4 are
uncommented, again, the program speedily runs out of memory.
BUT, if IO::Handle->new() is uncommented and lines 1,2 are
uncommented, this program very quickly gets bogged down.
Some sort of extra overhead must be involved with managing
these IO::Handle references. Furthermore, I plotted the
slowdown vs number of handles and it does not scale linearly, but worse than linearly.
What is going on here? Is there some special interaction
of IO::Handle objects with the GC? Why do IO::Handle objects start to bog down the program even after they are closed? CPU cycles shoot up but the program actually does less (visible) work. Eventually, the CPU pegs at 99% and the program can't get through the loop more than a few times per second. I originally noticed this in a program that was leaking socket handles (but there was plenty of memory to leak into... the slowdown is what we noticed).
use IO::Handle;
@ary = ( );
$j = 0;
for($i=1; $i<8000001; $i++) {
$j += $i;
$z = IO::Handle->new();
#1# $z->fdopen(fileno(STDERR), 'w');
#2# $z->close();
#3# $z = { };
#4# $z->{X} = 1;
push( @ary, $z );
if( $i % 1000 == 0 ) {
$t = time();
STDOUT->autoflush(1);
print "$t $i\n";
}
}
thanks,
matt