Thought it was time I give an update to where my testing 
is.

First off, let me state that the size of the read buffer 
does not matter.  I had thought increasing the buffer 
size to 10240 solved the problem.  I was wrong.  Amazing 
what happens when you rerun test!  ;)  Also let me 
apologize for this narrow email as I am doing this from 
a web based email client which doesn't allow a very wide 
screen :(.

Anyway, I have run the scripts, with Devel::Leak and 
without, using a basic perl 5.6.1, another compiled 
with -DDEBUGGING -g.  I have also done the same with and 
without the perl malloc.  It doesn't matter, the memory 
usage continues to grow.  Devel::Leak did not show any 
memory leaks.

So, what is a good programmer to do?  Well, I took the 
whole thing into a debugger.  What seems to be growing 
is the (a?) perl stack!  I'm not a perl hacker so I 
hesitate to go to far down this path, but I decided to 
have my debugger stop at the sbrk() system calls.  Here 
is a copy of the stack trace:

1.  sbrk(0x1a000, 0x7, 0, 0, 0)
2.  getpages(needed=135168, nblksp=4290700676, 
bucket=17) line 1278 of malloc.c
3.  morecore(bucket = 17) line 1501 of malloc.c
4.  malloc(nbytes=79972U) line 1057 of mallo.c
5.  realloc(mp=5224456, mbytes=84056u) line 1822 of 
malloc.c
6.  Perl_av_extend(av=1828920, key=17533) line 113 of 
av.c
7.  Perl_stack_grow(sp=5294072, p=5294072, n=1) line 60 
in scope.c
8.  Perl_pp_const(), line 31 in pp_hot.c
9.  Perl_runops_debug() line 53 in run.c
10. S_Call_body(myop=4290701904, is_eval=0) line 1824 in 
perl.c
11. perl_call_sv(sv=5158460, flags=128), line 1703 in 
perl.c
12. pe_event_invoke(ev=5169416) line 272 in ev.c.
..... don't worry about the rest of the stack....

I leave it at that.  I realize the args arn't going to 
do much for you but wanted to include them here.

In ev.c, at line 272, Event appears to be making the 
call to the callback perl_call_sv((SV*), ev_callback, 
pcflags).  This in turns goes onto the stack, so on and 
so forth.  I am not sure if this ever comes off the 
stack!  Then again, I could be misreading this whole 
thing and assuming the wrong things.

So to recap, it appears a stack within perl continues to 
grow and grow, thus eating more and more memory.

I am doing this with perl 5.6.1 on Solaris 7.  I'll 
include the two basic scripts here for comparing the 
select() based with the Event.pm based scripts so anyone 
who would like to help can.

I am also going to write another script using an Event-
>timer, rather than Event->io to see if the stack growth 
is there also.

#### begin testselect
#!/usr/bin/perl -w

use strict;
use IO;
use IO::Select;
use IPC::Open2;
use POSIX ":sys_wait_h";
use FileHandle;

my $buffer;
my @fds;
my $readIO = IO::Select->new();
my ($rd, $wt) = (FileHandle->new, Filehandle->new);
my $pid = open2($rd, $wt, "./test2.pl");
$readIO->add($rd);
while (1) {
    @fds = $readIO->can-read(5);
    foreach my $fh (@fds) {
        mylog($fh);
    }
}
sub mylog
{
    my ($fd) = @_;
    $fd->sysread($buffer, 80);
    print $buffer;
}
#### end testselect

#### begin testevent

#!/usr/bin/perl -w
use strict;
use IO;
use Event qw(loop unloop);
use IPC::Open2;
use POSIX ":sys_wait_h";
use FileHandle;

my $buffer;
my ($rd, $wt) = (FileHandle->new, FileHandle->new);
my $pid = open2($rd, $wt, "./test2.pl");
Event->io(fd => $rd, cb => \&mylog);
Event::loop;

sub mylog
{
    my ($e) = @_;
    my $fd = $e->w->fd;
    $fd->sysread($buffer, 80);
    print $buffer;
}

#### end testevent

test2.pl is any script that will print anything forever.

Any suggestions/help would be gladly accepted!

Brad

Reply via email to