On Tue, 09 Sep 2003 03:19:46 GMT,
Stefan Weiss <spaceman-a299c-20030925ausgehaucht.sensenmann.at> wrote:[snip]> Hi,
> I am trying to write a multiuser server (for games, chat, etc) in Perl.
> In time, this program might have to service >500 users simultaneously,
> who would be connected for some time. So I thought about using threads
> instead of forking a new process for every user, in order to keep my
> process table healthy and minimize inter-process communication overhead.Threads can show up as different processes. Check you ps doentation or>
> First problem - threads seem to be working fine, but when I look at the
> output of ps, there are still seperate processes for each connection.
> Shouldn't the threads all be contained in one large process? I'm using
> an ithreads-enabled current version of Perl with Linux 2.4.19.
you kernel doentation for details on how to identify threads (and
I guess the perl docs too?)
[snip second problem of memory usage which I can't help with]
That's probably something along of the lines of a SIGPIPE terminating> Third problem - I have absolutely no idea why, but when I run the
> client script in another terminal (or on another host even), and hit
> Ctrl-C while the client is still receiving data from the server, the
> server(!) will quit (and the client too, of course).
your process. Catch the signal you are getting when writing to the broken
socket, clean up, and continue.
I know very little about perl threads so I'm not going to try and comment> Can anybody explain to me what is happening? Is there a better approach
> than using threads? Should I just fork away for each new client?
on the threading stuff.
A third solution, to forking and threading, is to do the multiplexing
yourself using something like select (perldoc -f select). Doing
that can often be simpler for things like chat servers where the
connections are not independant (data read from one will be sent to
others, common data will be updated, etc) since all the data is
shared and there are no race conditions or locking issues (since there's
only one 'thread' executing).