URIS
http://codeforpeople.com/lib/ruby/acgi/
SYNOPSIS
as·sid·u·ous (adj.)
1. constant in application or attention; diligent: an assiduous worker who
strove for perfection.
2. unceasing; persistent: assiduous research.
acgi : assiduous or ara's cgi (emphasis on the 'ass' in assiduous) a drop-in
replacement for ruby's built-in cgi that provides copious features such as
- persistence
- speed
- simplicity
- familiarity
- no apache modules
- browser neutrality
- could easily be made platform independent
- ability to install via ftp
- no special webserver setup or privledges required
- session affinity (no process pool) so mem caching is simple
- 91 lines of ruby code
ARCHITECHTURE
the design of acgi is similar to that of fastcgi (http://www.fastcgi.com) but
requires no external modules, configuration of apache, etc.
a acgi application consists of a cgi server backend which loops, handling all
incoming requests; the requests are delegated to this backend server via a
simple, fast to start up, 'index.cgi' program written in c. communication
between 'index.cgi' and it's backend server is via named pipes (fifos):
···
-------------
> index.cgi | <- transient (compiled c code)
-------------
> > >
> fifos for stderr, stdout, stdin, env
> > >
/ | \
------------------------------
> >
> cgi server | <- persistent (looping ruby code)
> >
------------------------------
note that the architechture is similar in spirit to fastcgi - it provides
speed by avoiding startup overhead and redundant work like database connection
setup. in this case, contrasted with fastcgi, the whole thing takes place
outside of the webserver in the application domain.
REQUEST CYCLE
- request comes in to web server
- request is passed to index.cgi, a very simple compiled c program which in
turn does the following
- make sure the ruby server is running, spawn it in the background iff
required. this is a non-blocking operation that functions as a simple
process manager to ensure a server is running at all times.
- aqurire a lock to prevent other invocations of index.cgi from
overlapping - all invocations procede one at a time in the order of
receipt. there are never concurrent requests to the server.
- serialize the environment and send it down a fifo
- read any stderr/stdout from the ruby server via fifos and write them to
stderr/stdout respectively
- release lock
- the ruby server, for it's part, does the following
- aquire a lock which prevent multiple copies from running simoultaneously.
this is the same lock the c program checks.
- loops
- loading the environment
- handling request with stderr/stdout/stdin redirected
the cycle is mostly transparent to the cgi progam. to convert an existing cgi
program to an acgi program one would simply change
require 'cgi
cgi = CGI::new
establish_database_connection
generate_content
to
require 'acgi
establish_database_connection
ACGI::each_cgi do |cgi|
generate_content
end
IMPLEMENTATION
shoddy.
this version is proof of concept only!!! it's likely to run only on linux,
though it may run on many *nix platforms. or maybe not. there is little to
no error checking, the sun could explode if you run the example program.
security is not considered.
RUNNING THE EXAMPLE
- unpack tarball in webroot
- make
- point browser at http:://your.host.com/path/where/you/unpacked/index.cgi
obviously you'll need cgi setup for you web server, ruby installed, etc.
- try changing server.rb and running 'make restart'
BUGS
> 42
WHY?
i think the idea is neat enough to pursue. i'd like to get a minimal package
going that supported windows and *nix. if you are interested in participating
please contact me. mostly i'm in need of windows c/ipc knowledge.
ara [dot] t [dot] howard [at] noaa [dot] gov
-a
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================