Subject: Re: Lisp Application Server
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 11 Jul 2008 04:38:35 -0500
Newsgroups: comp.lang.lisp
Message-ID: <4oOdnTLiq6GGt-rVnZ2dnUVZ_sednZ2d@speakeasy.net>
Matthew D Swank  <akopa.gmane.poster@gmail.com> wrote:
+---------------
| While I appreciate image based environments like Squeak or the Lisp 
| Machines (what I have gleaned of them from CLIM and demos), most of my 
| work with lisp involves smallish-looking scripts playing nicely with an 
| OS.  This can be difficult at times even with "small" common lisp 
| implementations.  
+---------------

Don't despair: Modern VM systems [Unix/Linux/etc.] do a *great* job
of sharing mmap'd file segments, so much so that even with, say,
CMUCL's largish core file of ~25 MB [more, if you save out a core
image with your most popular libraries in it], because it mmap's its
core into memory and the O/S caches that across invocations, CMUCL's
startup time for the 2nd & subsequent executions can actually be *faster*
than smaller systems [e.g., the much-smaller CLISP], to wit:

    $ cat test_cmucl                 # [Note 1]
    #!/usr/local/bin/cmucl -script
    (format t "Hello, world!~%")
    $ /usr/bin/time ./test_cmucl
    Hello, world!
        0.01 real         0.00 user         0.00 sys
    $ time-hist ./test_cmucl
    Timing 100 runs of: ./test_cmucl
       4 0.011
      89 0.012
       7 0.013
    1.285u 1.255s 0:02.57 98.4%     224+1763k 0+0io 0pf+0w
    $ 

Yes, that's only 11-13 milliseconds. *Plenty* fast for human-scale
response times. As a result, I use CMUCL for all *kinds* of small
"shell scripting" stuff":

    $ file ~/bin/* | grep 'cmucl.*script' | wc -l
        47
    $ 

Specifically, "csq" is a small (40-line) script to convert
broadband cell modem AT+CSQ responses to dBm and vice-versa:

    $ wc bin/csq
          40     178    1429 bin/csq
    $ csq
    usage: /u/rpw3/bin/csq { +csq | -dBm | :CSQ | :DBM }
    $ csq 18
    AT+CSQ 18 =  -77 dBm ==> 3 bars, "satisfactory (17-21)"
    $ csq -63
    AT+CSQ 25 =  -63 dBm ==> 4 bars, "quite good (22-26)"
    $  csq :dbm
    AT+CSQ  4 = -105 dBm ==> 0 bars, "no signal (0-6)"
    AT+CSQ  6 = -100 dBm ==> 1 bar, "borderline unusable (7-11)"
    AT+CSQ  9 =  -95 dBm ==> 1 bar, "borderline unusable (7-11)"
    AT+CSQ 12 =  -90 dBm ==> 2 bars, "weak, reduced throughput (12-16)"
    AT+CSQ 14 =  -85 dBm ==> 2 bars, "weak, reduced throughput (12-16)"
    AT+CSQ 16 =  -80 dBm ==> 3 bars, "satisfactory (17-21)"
    AT+CSQ 19 =  -75 dBm ==> 3 bars, "satisfactory (17-21)"
    AT+CSQ 22 =  -70 dBm ==> 4 bars, "quite good (22-26)"
    AT+CSQ 24 =  -65 dBm ==> 4 bars, "quite good (22-26)"
    AT+CSQ 26 =  -60 dBm ==> 5 bars, "exceptionally strong (27+)"
    $ 

Or a stub/idiot version of an HTTP client:

    $ wc bin/http-get
         189     886    7283 bin/http-get
    $ http-get -q http://rpw3.org/~rpw3/sample.txt  # "-q" quiets headers
    Nothing to see here, move along, move along...
    $ http-get -H www.google.com           # "-H" says do "HEAD", not "GET".
    HEAD / HTTP/1.0
    Host: www.google.com

    HTTP/1.0 200 OK
    Cache-Control: private, max-age=0
    Date: Fri, 11 Jul 2008 09:06:08 GMT
    Expires: -1
    Content-Type: text/html; charset=ISO-8859-1
    Set-Cookie: PREF=ID=72c19595acd948db:TM=1215767168:LM=1215767168:S=LKcYtKTH_bqJo_zt; expires=Sun, 11-Jul-2010 09:06:08 GMT; path=/; domain=.google.com
    Server: gws
    Content-Length: 0
    Connection: Close
    $ 

Or a script that, hard-linked to different names, converts temperatures
depending on its name?

    $ ls -il bin/?2?
    1507459 -rwxr-xr-x  1 rpw3  rpw3  819 Jul  7  2005 bin/c2f
    1507459 -rwxr-xr-x  1 rpw3  rpw3  819 Jul  7  2005 bin/f2c
    1507459 -rwxr-xr-x  1 rpw3  rpw3  819 Jul  7  2005 bin/k2c
    $ c2f 25
    77.0
    $ f2c 95
    35.0
    $ k2c 77
    -196.16
    $ 

Is that the sort of "smallish-looking scripts playing nicely with an O/S"
you meant?!?  ;-}

+---------------
| Hosted environments like Java and .NET can have a in memory, running vm 
| waiting to run applications.  A lisp could provide a running image-- 
| effectively a runtime environment, to do the same thing.  However, there 
| is no separation between the data provided by the runtime and the data 
| used by the program.  After the program is "done" The lisp image is in a 
| modified state.
+---------------

That's up to how you write your apps. If you write them to *not* mutate
global state, then the persistent Lisp image will (eventually) GC whatever
allocated data got left behind and you'll be good as new again.

Also, Common Lisp gets used a *LOT* as either a web server proper
[CL-HTTP, AllegroServe, Araneida, etc.] or as a persistent web
applications daemon behind some web server such as Apache [UCW,
Hunchentoot, cl-weblocks, etc., using mod_lisp or FastCGI or
equiv. as a connector], see <http://www.cliki.net/web> for *lots*
of that kind of stuff. Such web servers & applications servers
tend to run nicely for many months without having problems with
"accumulating state".


-Rob

[1] This uses my "-script" add-on to CMUCL to support "#!" scripts:

      http://rpw3.org/hacks/lisp/site-switch-script.lisp

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