Daemonize It
The best way to get CGI-like behavior, with far greater performance and scalability, is a common Unix technique I call daemonization, after the Unix daemons lurking in the background of every Unix machine waiting for events to handle. The basic idea is this: instead of having a CGI start in response to a query and then die, start up a persistent CGI-like process (a daemon) along with the web server. The daemon can even be on a different machine than the web server. When the web server gets a request pointing at the daemon, it simply connects to the daemon, hands over the request, and waits for the results (while still able to handle other requests).
Daemonization is a feature of servlets in Java. You can start servlets running and connect to them as often as you like, avoiding the overhead of startup, exactly as described previously. The fact that Java is interpreted is less significant than the performance gain derived from leaving the servlet running. Servlets are multithreaded, isolating clients from each other. See Chapter 15 of Java Network Programming, by Elliotte Rusty Harold (O’Reilly & Associates).
A standard method of daemonizing CGIs has been defined by Open Market, called FastCGI (seehttp:// www.fastcgi.com). FastCGI programs are persistent, and they are also extremely scalable, because they can be run on machines other than the originating web server. FastCGI uses a single TCP socket to connect the web server and FastCGI application, unlike the standard ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access