Re: Socket Programming
From: David Steuber (david_at_david-steuber.com)
Date: 05/27/04
- Next message: Jeff Dalton: "Re: Is Lisp more than another language?"
- Previous message: Michael Livshin: "Re: GNU CLISP 2.33.1 (2004-05-22) bug fix release"
- In reply to: Eric Marsden: "Re: Socket Programming"
- Next in thread: Peter Seibel: "Re: Socket Programming"
- Reply: Peter Seibel: "Re: Socket Programming"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 May 2004 12:22:24 -0400
Eric Marsden <emarsden@laas.fr> writes:
> [reacting a bit late to this interesting thread]
I've actually been thinking about this recently. Inside the last hour
in fact. Just to recap, there are two basic models I would consider
using for a TCP service:
* Single threaded application that multiplexes concurrent connections
and uses non-blocking io.
* Multi threaded application that uses one thread per connection
request and blocking io.
Some requests may be served within millisecond time scale. Others may
take a few seconds. Hopefully no requests take longer than that
because people on the other end of the line get impatient for an
answer very quickly.
If the host machine is a multi-cpu box and you have native threads,
then you can take advantage of the hardware with the second approach.
On a single cpu system, preemptive thread switching introduces some
overhead. In either case, I would expect the application logic to
have similar complexity. However, I personally am more familiar with
mult-threaded programming techniques from other languages than I am
with the multiplexing approach (select in Perl & C).
I would tend to favor the multi-threaded approach for that reason even
on a single cpu system (in the hope that I can upgrade to a multi cpu
system in the future). Is there a noticable performance downside to
this in terms of maximum requests per second I can handle on a given
piece of hardware?
Just to keep this on topic, I would be using SBCL. It only supports
native threads on x86 at present. I haven't measured it's thread
creation overhead yet, but I plan to Real Soon Now(tm).
One thing that would be nice to do with a multi threaded approach is
in the main thread that accepts socket connections and spawns new
threads to handle them is have a mechanism for sleeping for some
fractions of a second to act as a throttle in the event of the
slashdot effect or a plain old DoS attack.
In C, sleep takes an int in seconds of time. The best I can think to
do is keep some rolling counter of number of connections accepted in
the past second and sleep for a second or two if the number exceeds
some threshold value. The counter would have to be checked and
adjusted with each accept.
A DoS attack would still work, but the system won't fall down.
-- An ideal world is left as an excercise to the reader. --- Paul Graham, On Lisp 8.1
- Next message: Jeff Dalton: "Re: Is Lisp more than another language?"
- Previous message: Michael Livshin: "Re: GNU CLISP 2.33.1 (2004-05-22) bug fix release"
- In reply to: Eric Marsden: "Re: Socket Programming"
- Next in thread: Peter Seibel: "Re: Socket Programming"
- Reply: Peter Seibel: "Re: Socket Programming"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|