Re: How to run Lisp as a server?
- From: Daniel Leidisch <news@xxxxxxxxxxxx>
- Date: Mon, 14 May 2007 00:16:32 +0200
Thus spoke Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>:
In computers anything is possible (as long as you have enough memory
and time). Connecting to a server is hardly a memory or time problem,
is it's definitely possible.
How would you do it? (This has nothing to do with lisp).
Did you read my other posts in this thread? I am neither a
professional programmer nor a CS student. I have no idea how to
implement such a thing in any language and I made no bones about
that. Maybe it's due to my being a non native speaker that you
didn't get that.
My whole problem was, that I didn't know that one should save a core
file in order to avoid the long startup time. Richard M. Kreuter
was so kind as to explain that to me in detail and that solved
my problem.
Since I didn't know about that, I asked for the "emacsclient-like"
solution. If I may quote my first sentence in this thread: "Maybe
this is kind of a stupid question to ask" -- it apparently was,
but PCL and the other tutorials I've read just didn't mention the
saving of core-files (or maybe I've read over it).
I don't think that what I'm doing at the moment could be considered
"serious work". I'm just trying to learn some Lisp, and I am not
a professional.
Yes, if you want to do it in lisp, learning some lisp is a good idea...
If I want to do what in Lisp? If you refer to the "serious work":
No, I don't think that I'll make my living as a programmer in
the future. The reason for me to learn how to program in Lisp is
curiosity and inquisitiveness.
What do you know?
There are several ways to do IPC, (Inter Process Communications). The
most basic one, which is always available and can be implemented even
in the standard Common Lisp (therefore needing only the most basic
knowledge of lisp (or any other programming language)) is to go thru
the file system: the client stores a file somewhere, the server reads
the files, and stores the answer in some other file, which the client
reads and display.
Given that I've read (and for the most part understood) PCL and
Touretzkys "Gentle Introdution" I think that I have what you call
"the most basic knowledge of Lisp". Even if it sounds pretty easy
to implement such a basic form of IPC, and it surely is trivial
for a seasoned Lisper or professional programmer, I just lack the
experience for doing such a thing at the moment.
In order to make the transition from just reading books, trying
examples and solving exercises I'm trying to write some functions
and macros that provide some Awk-like functionality. (Yes, know
there's clawk, but I want to learn something) To you, that may be
just ridiculuous or boring, but for me it's just the perfect degree
of difficulty at the moment.
Maybe I'll try implementing some Interpreters, servers and all
that jazz later on...
So, let's say that you write a little interpreter that takes its
script and put it into a file in a spool directory and waits for some
result file to display. And you write a little server that takes
these files in the spool directory, loads them and writes the result
to a result file in the spool directory.
Note that there is a little trick: we don't want the reader to read
the file before it's been entirely written. We can do it easily by
writing a "job ticket" file.
Let's say you write the script files in
/var/spool/lisp-server/input/XXXXXXX.lisp
once such a file is written, you create a job ticket file:
/var/spool/lisp-server/input/XXXXXXX.job
The server searches for .job files and when it finds one, it deletes
it, and loads the corresponding .lisp file, writting the results to:
/var/spool/lisp-server/output/XXXXXXX.stdout
/var/spool/lisp-server/output/XXXXXXX.stderr
(more output streams could be used, for example, for *trace-output*, etc).
When done, it creates the job ticket file:
/var/spool/lisp-server/output/XXXXXXX.job
When the "interpreter" sees this .job file, it would dump the .stdout
file to standard output and .stderr to standard error.
Since you're a "learning-by-doing" guy, I won't do it for you...
But there is one other difficulty: scripts cannot be interpreters for
other scripts, so for your interpreter, you want a binary executable.
You can generate such an executable with most Common Lisp
implementations, but how it's done is implementation dependant.
I can follow you, but as mentioned earlier I would have problems
putting that into practice.
And finally, if you did all that to launch your scripts faster, compare:
- running a simple script like:
#!/usr/bin/clisp
(print "hello")
involves:
fork, exec(/usr/bin/clisp), read, interpret the script, write
- running a simple script thru a lisp server as:
#!/usr/local/bin/lisp-client
(print "hello")
now involves:
In the client: In the server:
fork, loop: opendir readdir closedir
exec(/usr/local/bin/lisp-client), until found a job ticket
read, unlink
open, write, close, creat open, open, read,
loop: open interpret the script
until found the job ticket write, close, close, creat
unlink
read, write, close, unlink
I wouldn't bet on that to be faster, even if you'd use sockets or
shared memory to communicate between the client and the server...
I get the point. You are surely right; running the script directly
seems to be the better solution.
Last time I benchmarked it, printing "Hello World" from perl scripts,
emacs, sbcl, or clisp scripts, clisp was the fastest. I've heard
some reports that recent perl is slightly faster to start up.
Anyways, it's a difference you cannot notice, if you are a human.
Since I'm using a saved core image I can't feel a difference, but
before I knew about that my scripts took about eight seconds to
start up because they make use of cl-ppcre, osicat and other things.
Notice that I didn't complain about Lisp's speed per se -- I was
aware that /my/ method of doing things was wrong, that's why I
asked for a better solution. Unfortunately, inspired by Emacs,
I seem to have asked for the wrong thing.
Regards,
dhl
.
- Follow-Ups:
- Re: How to run Lisp as a server?
- From: Daniel Jensen
- Re: How to run Lisp as a server?
- From: Pascal Bourguignon
- Re: How to run Lisp as a server?
- References:
- How to run Lisp as a server?
- From: Daniel Leidisch
- Re: How to run Lisp as a server?
- From: Cor Gest
- Re: How to run Lisp as a server?
- From: Daniel Leidisch
- Re: How to run Lisp as a server?
- From: Kent M Pitman
- Re: How to run Lisp as a server?
- From: Daniel Leidisch
- Re: How to run Lisp as a server?
- From: Pascal Bourguignon
- How to run Lisp as a server?
- Prev by Date: Re: [Troll] Language popularity
- Next by Date: Help defining a macro
- Previous by thread: Re: How to run Lisp as a server?
- Next by thread: Re: How to run Lisp as a server?
- Index(es):
Relevant Pages
|