FastCGI with and/or I/O Multiplexing?

David Crane (
Fri, 26 Jul 96 09:44:39 EDT

Date: Fri, 26 Jul 96 09:44:39 EDT
From: (David Crane)
Message-Id: <>
Subject: FastCGI with and/or I/O Multiplexing?

I wrote a web application with session affinity, without using fastcgi.
The functionality is fairly complicated, and it is in perl, so with the
multiple hits, it is very noticeably slow.  I want to speed it up, and
fastcgi looks perfect.  But before I begin, I'd like to hear from anyone
about any pitfalls I am likely to encounter.
[1] Can I mix fastcgi and in one perl script?
[2] Can I mix fastcgi and I/O multiplexing with the select perl (system)
    call in another perl script?
The existing application is really a framework -- the web server invokes
the "dispatch" cgi script, which in turn executes an app cgi script.
The stdout from that app script is a multipart/related mime stream.
I.e., it prints all of the frameset and body html documents that comprise
its response, separated by mime separators.  The app scripts are easy to
develop and debug, since they use the CGI module and their code logic is
sequential -- they don't hold state across several connections.
Instead, the dispatch cgi script (the parent process) does the session
affinity state-holding thang.  It becomes a TCP/IP server in the usual
way, using the perl functions socket, bind and listen to set up a port.
Then it modifies the framesets so the SRC urls cause connections back to
this port.  It prints the top-level frameset back to the web server, and
closes stdout.  Then it uses the accept perl function to establish the
full duplex connections from the web browser for the SRC requests.  It
even sends server-push "working..." documents if the content documents
haven't come from the app script yet.  (But enough details.)
Obviously, the dispatch script is event-driven.  It uses the select
system call to multiplex all the I/O and timers.  Also, it does I/O
using the sysread and syswrite system calls, instead of buffered I/O.
I'd like to use fastcgi in the dispatch script, too, even though it only
takes 1.5 seconds to compile on a sparc 10.
Will I encounter any known problems wrapping either of these two scripts
in a fastcgi main loop?  I can send an e-mail about the exact behavior
that is expected from the system calls if anyone is curious.
David Crane
Salomon Brothers, Inc.