Lisp and Web Programming

138 views
Skip to first unread message

Emre Sevinc

unread,
Jun 3, 2005, 9:39:08 AM6/3/05
to

A friend asks:

"Hi,

I am trying to write a simple web application in Common Lisp. The first
problem was to interact with a database server. Thanks to Haldun
Bayhantopcu's help, it is OK using CMUCL + CommonSQL.

The second problem is that CommonSQL has support for only few Common
Lisp interpreters and compilers. And those supported free ones does
interestingly not support Shebang Characters for CGI execution. Thus I
tried using modlisp for apache but that does not work as smooth as I
expected.

Does anyone has an opinion to cope with these problems? Once I get a
simple "Hello World" web page through (format t "Hello World~%"), then
everything will be simpler.

vst"

Any suggestions?

--
Emre Sevinc

eMBA Software Developer Actively engaged in:
http:www.bilgi.edu.tr http://ileriseviye.org
http://www.bilgi.edu.tr http://fazlamesai.net
Cognitive Science Student http://cazci.com
http://www.cogsci.boun.edu.tr

Fred Gilham

unread,
Jun 3, 2005, 11:54:32 AM6/3/05
to

> The second problem is that CommonSQL has support for only few Common
> Lisp interpreters and compilers. And those supported free ones does
> interestingly not support Shebang Characters for CGI execution. Thus
> I tried using modlisp for apache but that does not work as smooth as
> I expected.

If you google for Rob Warnock's postings to comp.lang.lisp you'll see
that he has a method for dealing with this with CMU Lisp. I suspect
and hope that he will chime in shortly anyway. :-)

--
Fred Gilham gil...@csl.sri.com
Central bankers don't trust each other. They know how easy it is to
create money out of nothing. They hold dollar-denominated assets, such
as U.S. Treasury-bills, because they can earn interest --- not much
these days --- but they settle their final accounts with each other in
gold. --- Gary North

Edi Weitz

unread,
Jun 3, 2005, 12:02:07 PM6/3/05
to
On Fri, 03 Jun 2005 16:39:08 +0300, Emre Sevinc <em...@bilgi.edu.tr> wrote:

> A friend asks:
>
> "Hi,
>
> I am trying to write a simple web application in Common Lisp. The
> first problem was to interact with a database server. Thanks to
> Haldun Bayhantopcu's help, it is OK using CMUCL + CommonSQL.

CommonSQL is only available for LispWorks. Maybe he's using
UncommonSQL but if that's the case he should switch to CLSQL. (CLSQL
is a superset of UncommonSQL and the latter isn't maintained anymore.)

> The second problem is that CommonSQL has support for only few Common
> Lisp interpreters and compilers.

Only a few? Which one are you missing?

<http://clsql.b9.com/platforms.html>

Jörg Höhle has just announced preliminary support for the CLSQL/CLISP
combo.

> And those supported free ones does interestingly not support Shebang
> Characters for CGI execution.

See Fred Gilham's reply. You could also use FastCGI with CMUCL:

<http://www.cliki.net/FastCGI>

> Thus I tried using modlisp for apache but that does not work as
> smooth as I expected.
>
> Does anyone has an opinion to cope with these problems? Once I get a
> simple "Hello World" web page through (format t "Hello World~%"),
> then everything will be simpler.

Try (shameless self-plug) TBNL - maybe it's easier to use than "raw"
mod_lisp. (In fact, you don't have to use Apache/mod_lisp at all.)

<http://weitz.de/tbnl/>

Cheers,
Edi.

--

Lisp is not dead, it just smells funny.

Real email: (replace (subseq "spam...@agharta.de" 5) "edi")

david....@gmail.com

unread,
Jun 3, 2005, 2:02:02 PM6/3/05
to
> Does anyone has an opinion to cope with these problems? Once I get a
> simple "Hello World" web page through (format t "Hello World~%"), then
> everything will be simpler.
>

Common Lisp is such a great language that it does not need standard
libraries. Everyone can write anything easily. I needed simple CGI too,
so here is the one I cooked over the last weekend. Uses rfc2388,
slightly hacked and fixed, and port (see README.txt) inside. Supports
GET, POST/urlencode, POST/multipart. Runs with and includes examples
for CLISP, CMUCL, Lispworks, OpenMCL.

http://ftp.davidashen.net/misc/cgi.zip

David

drewc

unread,
Jun 3, 2005, 2:34:40 PM6/3/05
to
Emre Sevinc wrote:
> A friend asks:
>

> Does anyone has an opinion to cope with these problems? Once I get a
> simple "Hello World" web page through (format t "Hello World~%"), then
> everything will be simpler.

You don't want to use CGI at .. trust me : .. CGI is a hack at best.

http://lisp.tech.coop/Web%20Programming lists some resources for web
programming in CL .. i strongly suggest using UCW or TBNL with either
mod_lisp or aranieda ... you'll never even thing about CGI and hash-bang
again :


drewc


>
> vst"
>
> Any suggestions?
>


--
Drew Crampsie
drewc at tech dot coop
"Never mind the bollocks -- here's the sexp's tools."
-- Karl A. Krueger on comp.lang.lisp

Pascal Bourguignon

unread,
Jun 3, 2005, 2:54:12 PM6/3/05
to
Emre Sevinc <em...@bilgi.edu.tr> writes:
> I am trying to write a simple web application in Common Lisp. The first
> problem was to interact with a database server. Thanks to Haldun
> Bayhantopcu's help, it is OK using CMUCL + CommonSQL.
>
> The second problem is that CommonSQL has support for only few Common
> Lisp interpreters and compilers. And those supported free ones does
> interestingly not support Shebang Characters for CGI execution. Thus I
> tried using modlisp for apache but that does not work as smooth as I
> expected.

With clisp, pg (Postgresql) works very nicely, and you can use clisp
as a CGI (faster load times than perl!)

Pg is a socket-level interface to the PostgreSQL object-relational Database.
http://www.cliki.net/pg


Note that you can as easily save your own image, and therefore load
your CGI at the same time you load the lisp image, with no need for a
#! script.

> Does anyone has an opinion to cope with these problems? Once I get a
> simple "Hello World" web page through (format t "Hello World~%"), then
> everything will be simpler.
>
> vst"
>
> Any suggestions?

If you're serrious about web programming, consider UCW.

UnCommon Web is a Common Lisp web application development framework.
http://www.cliki.net/ucw

--
__Pascal Bourguignon__ http://www.informatimago.com/
Litter box not here.
You must have moved it again.
I'll poop in the sink.

theo doukas

unread,
Jun 3, 2005, 9:12:46 PM6/3/05
to
Edi Weitz wrote:
> On Fri, 03 Jun 2005 16:39:08 +0300, Emre Sevinc <em...@bilgi.edu.tr> wrote:
>
>
>>A friend asks:
>>
>>"Hi,
>>
>>I am trying to write a simple web application in Common Lisp. The
>>first problem was to interact with a database server. Thanks to
>>Haldun Bayhantopcu's help, it is OK using CMUCL + CommonSQL.
>
>
> CommonSQL is only available for LispWorks. Maybe he's using
> UncommonSQL but if that's the case he should switch to CLSQL. (CLSQL
> is a superset of UncommonSQL and the latter isn't maintained anymore.)
>
>
>>The second problem is that CommonSQL has support for only few Common
>>Lisp interpreters and compilers.
>
>
> Only a few? Which one are you missing?
>
> <http://clsql.b9.com/platforms.html>
>
> Jörg Höhle has just announced preliminary support for the CLSQL/CLISP
> combo.
>
>

If it is a viable way for you to go, implementing some FFI bindings for
libmysqlclient.so is not a big deal. The library is laid out well enough
that the you can practically port the C functions 1:1 to lisp functions.
I'm using CLISP myself along with a few handmade MySQL FFI bindings
and it works allright.

david....@gmail.com

unread,
Jun 4, 2005, 6:14:17 AM6/4/05
to

> You don't want to use CGI at .. trust me : .. CGI is a hack at best.
>

CGI is de facto standard bridge between a web server and an
application. mod_lisp is a hack -- it is a C program grafted into one
particular implementation. FastCGI is slightly better than mod_lisp but
only exists because writing a fast cGI bridge requires C programming
anyway; unless the bridge is written in LISP.

CGI implemented in Common Lisp is an excellent solution: it eliminates
to patch a fix the web server, is written in good language, and runs
faster than a C program doing the same job. And then, when you need
state, you can connect to a persistent program from within the bridge.

David Tolpin

Marco Baringer

unread,
Jun 4, 2005, 6:22:57 AM6/4/05
to
"david....@gmail.com" <david....@gmail.com> writes:

> CGI is de facto standard bridge between a web server and an
> application. mod_lisp is a hack -- it is a C program grafted into one
> particular implementation. FastCGI is slightly better than mod_lisp but
> only exists because writing a fast cGI bridge requires C programming
> anyway; unless the bridge is written in LISP.

apache modules are de facto standards: mod_php, mod_perl, mod_gzip,
etc.

> CGI implemented in Common Lisp is an excellent solution: it eliminates
> to patch a fix the web server, is written in good language, and runs
> faster than a C program doing the same job. And then, when you need
> state, you can connect to a persistent program from within the bridge.

if you really really must use CGI and want it to be fast you could
write a mod_lisp.cgi program, this would be a trivial C program which
reads from **env and translates this into the mod_lisp wire protocol.

--
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
-Leonard Cohen

david....@gmail.com

unread,
Jun 4, 2005, 7:45:50 AM6/4/05
to
> > only exists because writing a fast cGI bridge requires C programming
> > anyway; unless the bridge is written in LISP.
>
> apache modules are de facto standards: mod_php, mod_perl, mod_gzip,
> etc.
>

Apache is just one particular web server implemented in C for posix
systems. There are many others supporting CGI. I don't want to
recompile Apache just to write a web application in Common Lisp.


> if you really really must use CGI and want it to be fast you could
> write a mod_lisp.cgi program, this would be a trivial C program which
> reads from **env and translates this into the mod_lisp wire protocol.
>

CGI in common lisp is faster than CGI in C: C cannot load memory image,
Lisp can. And more powerful, of course, I can do with data whatever I
want before sending it to the stateful long-running application (if
needed). Besides, I don't want to program in C just to write a web
application in Common Lisp.

My CGIs in Common Lisp are fast and poweful, when they need, they
connect to a stateful framework. No C, Python, Perl, Java involved.
Works with any web server. What's wrong with that?

And yes, I wrote some half million lines in C in my life, rolled out a
few Python and Perl web applications, and am behind at least one big
commercial successful product in Java. But I don't see any reason to
add anything of it to the mix when I program my web applications in
lisp (which I do for 10 years now, in various lisp dialects, albeit
only for a few months in Common Lisp).

David

Brandon J. Van Every

unread,
Jun 4, 2005, 12:23:05 PM6/4/05
to
david....@gmail.com wrote:

>>>only exists because writing a fast cGI bridge requires C programming
>>>anyway; unless the bridge is written in LISP.
>>>
>>>
>>apache modules are de facto standards: mod_php, mod_perl, mod_gzip,
>>etc.
>>
>>
>>
>
>Apache is just one particular web server implemented in C for posix
>systems. There are many others supporting CGI. I don't want to
>recompile Apache just to write a web application in Common Lisp.
>
>

Is Apache difficult to recompile? Do recompilations consume untoward
amounts of time in the development cycle? If you just have to recompile
it once and it's easy, I don't see what the problem is. Maybe I have an
idea that I'm going to be in charge of the webserver too, and you don't?

>>if you really really must use CGI and want it to be fast you could
>>write a mod_lisp.cgi program, this would be a trivial C program which
>>reads from **env and translates this into the mod_lisp wire protocol.
>>
>>
>>
>
>CGI in common lisp is faster than CGI in C: C cannot load memory image,
>Lisp can. And more powerful, of course, I can do with data whatever I
>want before sending it to the stateful long-running application (if
>needed). Besides, I don't want to program in C just to write a web
>application in Common Lisp.
>
>

Is the C program not in fact trivial?

>My CGIs in Common Lisp are fast and poweful, when they need, they
>connect to a stateful framework. No C, Python, Perl, Java involved.
>Works with any web server. What's wrong with that?
>
>

Is there a significant performance impact? That's what people seem to
be debating. I must say, I find 2..4 seconds to generate a webpage
downright piggish. I'm not sure from the discussion what solves what.

--
Cheers, www.indiegamedesign.com
Brandon Van Every Seattle, WA

"We live in a world of very bright people building
crappy software with total shit for tools and process."
- Ed McKenzie

Edi Weitz

unread,
Jun 4, 2005, 12:29:09 PM6/4/05
to
On 4 Jun 2005 04:45:50 -0700, "david....@gmail.com" <david....@gmail.com> wrote:

> I don't want to recompile Apache just to write a web application in
> Common Lisp.

To add a module like mod_lisp you don't have to recompile Apache.

<http://httpd.apache.org/docs/dso.html>

david....@gmail.com

unread,
Jun 4, 2005, 1:35:48 PM6/4/05
to
> >CGI in common lisp is faster than CGI in C: C cannot load memory image,
> >Lisp can. And more powerful, of course, I can do with data whatever I
> >want before sending it to the stateful long-running application (if
> >needed). Besides, I don't want to program in C just to write a web
> >application in Common Lisp.
> >
> >
> Is the C program not in fact trivial?

It is trivial because it is in C. While when it is in Common Lisp, it
can do more.

>
> >My CGIs in Common Lisp are fast and poweful, when they need, they
> >connect to a stateful framework. No C, Python, Perl, Java involved.
> >Works with any web server. What's wrong with that?
> >
> >
> Is there a significant performance impact? That's what people seem to
> be debating. I must say, I find 2..4 seconds to generate a webpage
> downright piggish. I'm not sure from the discussion what solves what.
>
>

A Common Lisp CGI launchs within 40 milliseconds with CMUCL, and about
90 milliseconds with
CLISP. This is on my G4 powerbook, but in any case, where do 2..4
seconds come from?

david....@gmail.com

unread,
Jun 4, 2005, 1:41:05 PM6/4/05
to

> To add a module like mod_lisp you don't have to recompile Apache.
>
> <http://httpd.apache.org/docs/dso.html>
>


I knew someone would say it the moment I pressed the 'post' button. If
you have Apache properly installed with DSO compiled in, you don't have
to recompile it, but still need access to its configuration, and need
to restart it. It is not always the case. In particular, many of my
programs run on servers where I cannot add a dso module to Apache.

But I don't need them. Common Lisp based CGIs are fast and smart, they
are faster than C programs and smarter than Python and Perl scripts. I
just do with CGIs only most of the time, and when I need state (and I
rarely do), I let them connect to a long running applications. It is
functional programming, after all.

David

Stefan Scholl

unread,
Jun 4, 2005, 6:10:49 PM6/4/05
to
On 2005-06-04 13:45:50, david....@gmail.com wrote:

> And yes, I wrote some half million lines in C in my life, rolled out a
> few Python and Perl web applications, and am behind at least one big
> commercial successful product in Java.

And yet you don't know that you don't have to recompile Apache just
to add a new module?

Stefan Scholl

unread,
Jun 4, 2005, 6:13:13 PM6/4/05
to
On 2005-06-04 18:23:05, Brandon J. Van Every wrote:

> david....@gmail.com wrote:
>>>apache modules are de facto standards: mod_php, mod_perl, mod_gzip,
>>>etc.
>>Apache is just one particular web server implemented in C for posix
>>systems. There are many others supporting CGI. I don't want to
>>recompile Apache just to write a web application in Common Lisp.
>>
> Is Apache difficult to recompile? Do recompilations consume untoward

You don't need to recompile Apache. Just compile the module and add
it to the config. Here's the line you have to enter when you want to
compile and add mod_lisp to your Apache:

apxs -c -i -a mod_lisp.c

david....@gmail.com

unread,
Jun 4, 2005, 6:41:42 PM6/4/05
to

And I know that I don't have to recompile Apache just to add a new
module if Apache is built with DSO support and I can modify Apache's
installation. And if it is built without or is installed in a location
where I can't tweak its configuration file, I have to recompile a copy
of Apache for myself and install it on a non-privileged port to be able
to tweak its configuration files, add modules via apxs and such.

I am not the system administrator on every computer I run my CGI
scripts on.

David

david....@gmail.com

unread,
Jun 4, 2005, 6:46:58 PM6/4/05
to
> >>Apache is just one particular web server implemented in C for posix
> >>systems. There are many others supporting CGI. I don't want to
> >>recompile Apache just to write a web application in Common Lisp.
> >>
> > Is Apache difficult to recompile? Do recompilations consume untoward
>
> You don't need to recompile Apache. Just compile the module and add
> it to the config. Here's the line you have to enter when you want to
> compile and add mod_lisp to your Apache:
>
> apxs -c -i -a mod_lisp.c

The key word is 'your'. Most apaches I deal with I not mine. I have my
public_html with +ExecCGI, and that's it. Some Apaches I deal with are
built without DSO support. Some servers I deal with do not even run
Apache.

mod_(perl|python|php|lisp) is a hack. With Python, Perl and PHP there
is an excuse for the hack: those programs are deadly slow to start.
With Lisp and memory images, when the startup time is hundredths of
seconds, there is no need for mod_lisp.

David

david....@gmail.com

unread,
Jun 4, 2005, 6:51:04 PM6/4/05
to

> With Lisp and memory images, when the startup time is hundredths of
> seconds,

a fraction of a second, I meant.

Vehbi Sinan Tunalioglu

unread,
Jun 5, 2005, 11:47:27 AM6/5/05
to
Edi Weitz wrote:
>>A friend asks:

It was me who asked for it...

> CommonSQL is only available for LispWorks. Maybe he's using
> UncommonSQL but if that's the case he should switch to CLSQL. (CLSQL
> is a superset of UncommonSQL and the latter isn't maintained anymore.)

You are right, I was using CLSQL, not CommonSQL.

>
>>The second problem is that CommonSQL has support for only few Common
>>Lisp interpreters and compilers.
>
>
> Only a few? Which one are you missing?

Actully, CLISP is the one I was seeking for. Because, using CLISP, I
could use Shebang and start easily to program.

>
>
> See Fred Gilham's reply. You could also use FastCGI with CMUCL:
>
> <http://www.cliki.net/FastCGI>

> ...


> Try (shameless self-plug) TBNL - maybe it's easier to use than "raw"
> mod_lisp. (In fact, you don't have to use Apache/mod_lisp at all.)
>
> <http://weitz.de/tbnl/>

I checked TBNL and UCW... The reason that I hesitate to select one of
the proposed ways of web programming in Common Lisp is that everything
might become messy one day, when I work on a big web site. I want to
switch to Common Lisp. And as far as I understand, I won't feel alone if
I will use TBNL or UCW. Am I right?

--vst

Stefan Scholl

unread,
Jun 5, 2005, 2:22:33 PM6/5/05
to
On 2005-06-05 17:47:27, Vehbi Sinan Tunalioglu wrote:

> Actully, CLISP is the one I was seeking for. Because, using CLISP, I
> could use Shebang and start easily to program.

See http://www.cliki.net/CMUCL%20Hints on how to do this with CMUCL.

--
Web: http://www.no-spoon.de/ -*- IRC: stesch @ freenode

Emre Sevinc

unread,
Jun 5, 2005, 2:26:43 PM6/5/05
to
Vehbi Sinan Tunalioglu <v...@vsthost.com> writes:

> Edi Weitz wrote:
>>>A friend asks:
>
> It was me who asked for it...

Welcom to comp.lang.lisp! :)


>> CommonSQL is only available for LispWorks. Maybe he's using
>> UncommonSQL but if that's the case he should switch to CLSQL. (CLSQL
>> is a superset of UncommonSQL and the latter isn't maintained anymore.)
>
> You are right, I was using CLSQL, not CommonSQL.
>
>>

>> See Fred Gilham's reply. You could also use FastCGI with CMUCL:
>>
>> <http://www.cliki.net/FastCGI>
>> ...
>> Try (shameless self-plug) TBNL - maybe it's easier to use than "raw"
>> mod_lisp. (In fact, you don't have to use Apache/mod_lisp at all.)
>>
>> <http://weitz.de/tbnl/>
>
> I checked TBNL and UCW... The reason that I hesitate to select one of
> the proposed ways of web programming in Common Lisp is that everything
> might become messy one day, when I work on a big web site. I want to
> switch to Common Lisp. And as far as I understand, I won't feel alone if
> I will use TBNL or UCW. Am I right?

I share similar concerns. I believe the one with better docs., faster
and wider community support, the one which is more extensible, the one
which includes more bells and whistles should be chosen. The only
problem is, how to find out which one is so ;-)

Alexander Schreiber

unread,
Jun 5, 2005, 3:01:18 PM6/5/05
to
Emre Sevinc <em...@bilgi.edu.tr> wrote:
>
> A friend asks:
>
> "Hi,
>
> I am trying to write a simple web application in Common Lisp. The first
> problem was to interact with a database server. Thanks to Haldun
> Bayhantopcu's help, it is OK using CMUCL + CommonSQL.
>
> The second problem is that CommonSQL has support for only few Common
> Lisp interpreters and compilers. And those supported free ones does
> interestingly not support Shebang Characters for CGI execution.

Funny, I was able to use CLISP, CMUCL and SBCL for CGI programming.
With CLISP you can directluse CLISP as in the interpreter for the #!
statement and for SBCL/CMUCL write a trivial wrapper script that
execs the Lisp interpreter:

#!/bin/sh
exec sbcl --noinform --end-runtime-options --noprogrammer --load cgi.lisp

Works like a charm, if a bit slow because SBCL always compiles before
execution. But for production use you'd be loading a precompiled image
anyway, right?

Regards,
Alex.
--
"Opportunity is missed by most people because it is dressed in overalls and
looks like work." -- Thomas A. Edison

Rob Warnock

unread,
Jun 17, 2005, 1:38:43 AM6/17/05
to
Fred Gilham <gil...@fury.csl.sri.com> wrote:
+---------------
| Emre Sevinc <em...@bilgi.edu.tr> wrote [or forwarded for a friend]:

| > The second problem is that CommonSQL has support for only few Common
| > Lisp interpreters and compilers. And those supported free ones does
| > interestingly not support Shebang Characters for CGI execution. Thus
| > I tried using modlisp for apache but that does not work as smooth as
| > I expected.
|
| If you google for Rob Warnock's postings to comp.lang.lisp you'll see
| that he has a method for dealing with this with CMU Lisp. I suspect
| and hope that he will chime in shortly anyway. :-)
+---------------

There have been many other useful answers in the past two weeks,
so I'll try not to duplicate their excellent advice, but here are
a few comments anyway specifically for the CMUCL environment:

1. If you're running on an operating system that supports more
than one additional argument on a "#!" (e.g., FreeBSD), one
of the ways to use CMUCL for CGI is to build an application-
specific core image containing all of your CGI support & query-
parsing & HTML-generation tools [whichever of the many excellent
libraries you use]. You do this by loading all the stuff into
a fresh CMUCL image and then use the function EXTENSIONS:SAVE-LISP
to write out the image, specifying in the call a CGI application
start-up function you've written (which just loads the CGI script,
basically) that replaces the normal LISP::%TOP-LEVEL function, e.g.:

;; Build the core & exit
(save-lisp "cgi.core"
:init-function #'cgi-init-function
:load-init-file nil ; same as "-noinit"
:print-herald nil ; same as CLISP's "-q"
)

Then you can start your CGI script with:

#!/usr/local/bin/cmucl -core /usr/local/lib/cmucl/lib/cgi.core

Look at the "config.lisp" file in the CMUCL distribution for an
example of saving a core, then tweak away. For a live example of
CGI scripting with it, see <http://rpw3.org/hacks/lisp/cmucl-demo.cgi>.

[Also see <http://rpw3.org/hacks/lisp/clisp-demo.cgi> for the
same thing done with CLISP.]

NOTE: Despite the above, I no longer recommend this method. [See #2.]

2. Some of the objections to useing "mod_lisp" seemed to be along
the lines of "But I don't control [the configuration of] my web
server!" or "But what if the locally-available web server isn't
Apache?". Well, besides FastCGI and selective HTTP-proxying (which
Araneida can use behind Apache, for example) which others have
already mentioned, you can write a *tiny* little C-based CGI program
that just opens a socket [preferably a local Unix-domain socket,
for security] to your persistent Lisp-based server [CMUCL or other]
and passes it *EXACTLY* the same information that "mod_lisp" would
pass it. That way, you can run your Lisp app behind *any* web server
that supports CGI, but get (most of) the performance benefit of
using "mod_lisp"... *and* be all set for the day the web server
admin decides to allow you to install "mod_lisp" itself!

I did that [mainly because of that web server admin issue], and
called it "cgi_sock.c"; the executable is "sock.cgi" [so it doesn't
have to be in /cgi-bin/, if the server has "*.cgi" enabled]. It's
about 200 lines of C, but is that big only because it handles both
GET & POST requests, and also contains a nice little compiled-in
HTML error message that it serves up if there's any problem in
connecting to the Lisp server socket.

On a 1.4 Gz Athlon running FreeBSD, with Apache 1.3.26 executing
it and with CMUCL-19a on the other end of the socket, "ab -n100"
reports ~70 requests/sec for a simple "env.lhp" (Lisp-Handled Pages)
that dumps the environment. [See <http://rpw3.org/env.lhp>, but
please don't run perf tests; you'll eat my poor DSL line alive!]

For comparison, a simple Perl-based "printenv" gets ~125 req/sec,
and a /bin/sh script that just calls "env" gets ~175 req/sec.

With "mod_lisp" you could probably get >200 such trivial reqs/sec,
but for the apps I use "sock.cgi" for, even *1* req/sec is overkill.
So it's quite "good enough" for my needs.

[Compare the LHP version of <http://rpw3.org/hacks/lisp/appsrv-demo.lhp>
to the above CGI examples. Note that ".lhp" pages can be just source,
or compiled (this one is), and in either case are cached by the server
for speed.]

To either method #1 or #2, add Tim Bradshaw's HTOUT or Edi Weitz's
CL-WHO for HTML generation, Eric Marsden's PG to talk to PostgreSQL,
and maybe Kevin Rosenberg's CL-MODLISP for the Lisp server front-end
(I had already written mine when CL-MODLISP appeared), and you have
a very nice web application environment.

3. Not for web/CGI per se, but just for basic "CL scripting", I hacked
up "/usr/local/lib/cmucl/lib/site-init.lisp" [which gets run *before*
the command-line switches are parsed!] to look for a new "-script"
option, so you can say stuff like this:

% cat ./test
#!/usr/local/bin/cmucl -script
(format t "hello world!~%")
(loop for i from 1
and arg in *script-args*
do (format t "arg#~d = ~s~%" i arg))

% ./test foo bar
hello world!
arg#1 = "foo"
arg#2 = "bar"
%

On that same 1.4 Gz Athlon under FreeBSD, that takes ~20 ms. to run,
using an *unmodified* CMUCL-19a "lisp.core". [Though note that
to get the speed that low, I had to compile the "site-init.lisp"!
And that time also assumes some other process on the system is
also using (or has recently used) "lisp.core".]

The same hack also supports concatenating "#!/usr/local/bin/cmucl -fasl"
onto the front of a CMUCL ".x86f" file, for when the "script" starts
getting too large to run fast enough when interpreted.

[Yes, this *can* also be used for CGI scripting, but it's not as
efficient as a CGI-specific core image (and *definitely* much
less efficient than a persistent Lisp server daemon!), since with
the "-script" approach you have to keep reloading your CGI/HTML/SQL
libraries each time. Ugh.]


-Rob

p.s. By the way, my apologies to the community for not having yet
made "cgi_sock.c" [and the "cl-modlisp"-like code that it talks to]
and the "site-init.lisp" "-script/-fasl" hacks generally available.
There seems to be a shortage of those round "tuit"s lately...

-----
Rob Warnock <rp...@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

Reply all
Reply to author
Forward
0 new messages