[MUD-Dev] Sockets
Jon A. Lambert
jlsysinc at ix.netcom.com
Tue May 11 22:49:38 CEST 1999
On 6 May 99,, Chris Gray wrote:
> [Jon A. Lambert:]
>
> >I think the performance boost
> >from threading has been understated or misunderstood on single-processor
> >machines probably due to early thread implementations.
>
> Is this deliberate flamebait, or just accidental?
<giggle> Flamebait? Moi?
> Please explain to me how adding the overhead of thread switches, locks
> and extra memory usage can increase performance. Or, perhaps you meant
> to say "multi-processor machines"?
Ok. I really meant a single-processor machine, like say one Pentium, as
opposed to dual or quad Pentiums.
The common select/poll loop for non-blocking sockets that processes
incoming, exceptions, reads, writes, and other mud processes is not
very efficient. Firstly setting up the parameters to select and checking
the FD_SETs involved alone is probably higher overhead than threading.
Secondly if the poll time is too short you end up burning processor
cycles in the poll loop for no good reason. And if the time is to long
you end up sleeping while your mud could be processing ripe events that
are issued from other functions in the mud (assuming that not all your
events are initiated immediately for user input). Yes, some good
implementations attempt to dynamically adjust the polling time depending
on how active the server is/was. Still there is enough overhead here
to more than compensate for the overhead incurred through thread locks.
> One could perhaps imagine how a good
> threaded implementation of something could perform better a poor
> non-threaded implementation, but I don't think that's what you mean.
Yes, though I'm imagining a good threaded implementation could well
outperform a good non-threaded implementation. :)
A threaded implementation will wake up "exactly" when data is ready on
the I/O ports and "exactly" when data is ready for sending. There will
be nothing waiting on I/O period. I/O of all types whether sockets,
disk, or console output is much too slow and is the ideal use for
threading on single-processor machines.
Thread switching is less intensive than process switching. Besides, if
multi-processing OSs weren't efficient we'd all be running DOS instead of
Linux.
--
--* Jon A. Lambert - TychoMUD Email:jlsysinc at ix.netcom.com *--
--* Mud Server Developer's Page <http://pw1.netcom.com/~jlsysinc> *--
--* To fight the empire is to be infected by its derangement. Whosoever *--
--* defeats part of the empire becomes the empire; it proliferates like a *--
--* a virus... thereby it becomes its enemies." -- P.K. Dick *--
_______________________________________________
MUD-Dev maillist - MUD-Dev at kanga.nu
http://www.kanga.nu/lists/listinfo/mud-dev
More information about the mud-dev-archive
mailing list