pjnet has asked for the wisdom of the Perl Monks concerning the following question:

I just completed 2 servers based upon Net::Daemon and found that under initial testing, they both had memory leaks. Under the opinion that my code was correct (and it appears that it is), I started having a bit of a play with the Net::Daemon code (you know, putting in "I'm here" everywhere to see how it worked).

I then decided to output the thread list at an appropriate point in the program.

What I've discovered is that threads get created, and never get destroyed. You can test this by using the default Calculator.pm from the perldoc. If you put this into the Daemon.pm module (immediately after 'my $self = shift;'), you'll see what I mean:

print "::::::::::::: threads\n"; require Data::Dumper; my $d = Data::Dumper->new([threads->list()]); $d->Indent(1); print $d->Dump; print "::::::::::::: /threads\n";


Am I missing something here or not? Is it just me, or is it that Net::Daemon doesn't close threads?

VERY frustrated, so any help would be appreciated. Also, if you could suggest an alternative I'd be grateful.

Paul

Replies are listed 'Best First'.
Re: Net::Daemon memory leak problem
by zentara (Cardinal) on Aug 04, 2006 at 15:57 UTC
    You need to show more code. Threads won't destroy themselves automagically, they either need to be joined or detached, and they must finish ( or return ) from their code block for them to end.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Right - showing more code would be rather pointless. You can literally take the code from the Net::Daemon perldoc (as I mentioned in the previous link) for the Calculator server and run that.

      The fault is within Net::Daemon - and if you replace the lines I mentioned previously in the Net/Daemon.pm module file then you'll see what I mean.

      Needs no more code.

      Paul
Re: Net::Daemon memory leak problem
by andyford (Curate) on Aug 04, 2006 at 16:07 UTC
    Have you tried to use the the "--mode=fork" option? Might be an easy way to see if you need to work on your threading.
      Yup - tried a few things, but nothing really seemed to work...

      except... reworking both servers in Net::Server::Fork. Took me 30 minutes, and works like a dream.

      Thing is, it's not my threading as I was relying entirely on Net::Daemon to do that for me.

      Is there a way to say on CPAN "use Net::Server instead of Net::Daemon"?

      The 2 servers now run fantastically well and fast. Glad I coded it so well in the first place!

      Paul