[plt-scheme] Industrial servlets and Apache

From: Don Felgar (dfelgar at rainier-infosys.com)
Date: Wed Aug 6 16:33:30 EDT 2003

This is a long email.  It covers mod_mzscheme, which runs Mzscheme in
Apache; Servlets that run in Apache; Why this doesn't work; Why people
might want to run servlets in Apache; and What Apache servlets should
do; and How to get servlets in Apache to work

I started a project to run a mzscheme applet server inside of Apache,
and got this working but for one flaw.  Because of a deadline I have
to abandon it for the time being.  I am writing my thoughts down here
while they are fresh in the hopes that I'll get some ideas that make
my eventual re-implementation easier.
Mod_mzscheme, which runs Mzscheme in Apache

If anyone is interested in running PLT inside Apache 1.3, let me know
and I'll make the mod_mzscheme code available.  It currently requires
the Apache source, but I think you can get around this by screwing
with the makefile.  The only other thing I know of that ought to be
fixed is I need to change the interface of the scheme procedure that
answers requests.  Currently, mod_mzscheme passes four parameters to
the request handler proc: url, headers, method, body.  I should change
it so that the request handler takes one opaque data type, a pointer
to the apache request data structure.  Then I can define a library of
C functions which are callable from Scheme for fetching request
information.  If anyone knows how to do this I'd appreciate an

Currently you do something like this in the Apache
configuraion file:

   LoadModule mzscheme_module libexec/mod_mzscheme.so
   SchemeInitFile /home/dfelgar/mod_mzscheme/sample.ss
   RequestHandlerProc request-handler
   <Location /scheme>
    SetHandler mzscheme-handler

Which means that Apache will call request-handler in sample.ss to
answer every request for /scheme or a subdirectory of it.

Servlets that run in Apache

I also hacked the PLT servlet code so that it runs under
Apache/mod_mzscheme, without the use of PLT web-server.  There is
however a fatal flaw with this design, but nevertheless the code is
available in a raw form if anyone wants it.

Why this doesn't work

The problem here is due to the fact that Apache forks child processes
as a fundamental apsect of its operation.  Thus every servlet
continuation saved by mod_mzscheme resides in one of several Apache
processes.  In general keepalive connections cause the client to talk
to the same server process throughout a session.  This is not reliable
though; clicking the browser's stop button or making a rapid series of
requests results in a new TCP connection and likely a different Apache

Why people might want to run servlets in Apache

I should point out why I don't wish to use web-server.  For my
purposes, the webserver is very nearly the operating system, so any
increase in functionality, stability, maturity or scalability is
significant.  For me XML nullifies the advantages of a Scheme
webserver implementation.  I often need some of the many Apache

Though I am not proud to say it, I like Apache for the same reason
that IT departments like Windows over Linux: if Apache fails, it is to
a degree Apaches fault.  On the other hand if web-server fails, it's
my fault.  The fact that there exists an application to send me email
in the event that web-server quits responding is a cold comfort.

What Apache servlets should do

I am a huge fan of the Apache multi-process idea.  It contributes
hugely to reliability with application code that changes constantly
and is always imperfect.  Apache 2.0 implements several threading
models, but each of these normally uses multiple processes as well.  I
want the ability to start and monitor a number of servlet processes in
a similar fashion.

I assume there is no easy way to persist continuations or share them
between processes.  Please let me know if I am wrong about this.

Another requirement is that servlets should be able to output
arbitrary XML.  This facilitates communication with other web apps and
other Apache modules.

Incidentally, I prefer Oleg Kiselyov's scheme XML implementation.  It
is easy to run this from within servlets by having SRV:send-reply
write to a string, and then calling make-response/full from within the

How to get this to work

I now think that the best solution is to have Apache redirect requests
to multiple web-server instances with mod_rewrite.  The problem here
is, how to get multiple Apache processes to share information about
which invoke-id's go to which web-server process?  Mod_rewrite can
consult an executable in its routing decision.  This approach requires
a process for starting and stopping web-server processes, detecting
when a web-server has quit responding, and reaping timed-out servlet
invocation id's.  Does PLT implement a file-based, multi-process hash
table?  I wish not to have a dependency on a database process.

In case you are wondering, Apache 2.0 does not solve the problem.  It
has a "research" MPM which is a hybrid process/thread model and can
run only threads.  I reject this idea but it is a research product and
an awkward use of it.

Posted on the users mailing list.