in reply to multithreaded tcp listener with IO::Socket
As written, your server is going to leak memory. The rate of leakage will depend upon the number of clients you are monitoring.
This means you are never recycling filenos within your server, which will become a problem over time.
Although the threads will become dormant once the client disconnects, the threads memory will never be recycled which will become a problem over time.
#ignore child processes to prevent zombies $SIG{CHLD} = 'IGNORE';
It will have no useful affect on a threaded process under Win32, but that may not be true for other OSs.
Both of these are fairly easy to correct.
Detach your client threads (I've ditched the my $client as you never do anything with it):
threads->create ("read_data", $queue, $connection)->detach;
and close the client socket once your done with it
sub read_data { # accept data from the socket and put it on the queue my ($queue, $socket) = @_; while (<$socket>) { print "listener got: $_"; $queue -> enqueue(time." $_"); } close $socket; }
In my quick test with 100 clients, fileno 4 was re-used for all inbound connections which fixes that problem.
With these measures in place, the server process shows a miniscule growth. After 5 cycles of reconnections from 100 clients, it showed ~ 16k extra memory used. This may well be just the normal process of memory acquisition required by Perl's memory manager. This was true for both AS811(5.8.6) and AS817(5.8.8) on my system (XP).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: multithreaded tcp listener with IO::Socket
by Random_Walk (Prior) on May 15, 2006 at 12:22 UTC | |
by BrowserUk (Patriarch) on May 15, 2006 at 12:51 UTC | |
by Random_Walk (Prior) on May 15, 2006 at 13:36 UTC | |
by BrowserUk (Patriarch) on May 15, 2006 at 16:59 UTC | |
by Random_Walk (Prior) on May 18, 2006 at 12:59 UTC | |
|