| For a good example of single-process, single-thread multiplexing,
| check out thttpd:
|
| http://www.acme.com/software/thttpd/thttpd.html
|
| With such a model, sharing state between clients is trivial, and
| thttpd shows that you can go pretty derned fast dispite (because of?)
| the simplicity of the approach.
From the notes link:
The second generation of web servers addressed this problem by forking
off a child process for each request. This is very straightforward to
do under Unix, only a few extra lines of code. CERN and NCSA 1.3 are
examples of type of server. Unfortunately, forking a process is a
fairly expensive operation, so performance of this type of server is
still pretty poor. The long random pauses are gone, but instead every
request has a short constant pause at startup. Because of this, the
server can't handle a high rate of connections.
Modern Unix and clones seem to not have this problem. I've not seen it
in FreeBSD, Linux, or Solaris. Tests in Linux show on 800 MHz P-III,
a fork() is under 100 nanoseconds. I can get thousands of fork()'s per
second. Maybe back in the days of slower CPUs on older OSes this might
have been an issue.
Calling an exec() function might involve more because of the fact that
it involves a whole new program and library mapping and linking, and
in some cases, a lot more initialization to load and compile (either
all at once or just in time) or interpret a script. But if the server
is not going to call exec(), you're dealing with the cost of fork()
and any subsequent VM copy on write.
For simple static pages, thttpd should be great. If any kind of logic
needs to be integrated, such as a dynamically generated site, thttpd
does not seem right if the logic can be integrated directly in the
server (e.g. avoiding exec() calls).
Also, I found that when thttpd forks a process for CGI, it does not
close all the descriptors for all the existing connections. If one
of the CGI scripts has to run for a long time, it could end up holding
thise descriptors (and hence the HTTP connections) open well after
they should have been closed elsewhere.
At the moment I don't have the time to run a serious benchmark test of
this vs. other servers. If anyone does, I'd also like to see included
in that the figures for khttpd in the Linux kernel.
--
-----------------------------------------------------------------
| Phil Howard - KA9WGN | Dallas | http://linuxhomepage.com/ |
-----------------------------------------------------------------