Hello Everyone,
Im trying to write a client server application under cmucl. I am using
Linux 2.4.xx on x86 (also FreeBSD 4.9 under x86). The server side of the
application listens on a particular port. when a connection is made it
spawns off another listener and continues with the processing of the
incomming data. Im getting stuck with the multiprocessing part which
doesnt seem to work right at this point.
First here is a list from the *features* in my system
* *features*
(:PCL-STRUCTURES :PORTABLE-COMMONLOOPS :PCL :PYTHON :PENTIUM :I486
:LINKAGE-TABLE :MP :GENCGC :GLIBC2.1 :CMU18 :CMU18E
:RELATIVE-PACKAGE-NAMES :CONSERVATIVE-FLOAT-TYPE :RANDOM-MT19937 :HASH-NEW
:X86 :LINUX :GLIBC2 :UNIX :COMMON :CMU :NEW-COMPILER :COMMON-LISP
:ANSI-CL :IEEE-FLOATING-POINT)
Basically my server side of the program program is
(defun run-a-server-mp (&optional (port 1111))
(declare (special *max-threads*))
(let ((server (extensions:create-inet-listener port)) (*gc-verbose*
nil))
(labels (
;; listener
(listener ()
(let ((socket (extensions:accept-tcp-connection
server)) socket-stream)
(if (< (length (mp:all-processes)) (1+
*max-threads*))
(progn
(mp:make-process #'listener :name "Server
Listener")
(format t "> Connected :: ")
(format t "Active Processes : ~A~%" (length
(mp:all-processes)))
(setf socket-stream (system:make-fd-stream
socket :input 1 :output 1))
(analyze-i socket-stream)
(extensions:close-socket socket))
(progn
(extensions:close-socket socket)
(format t "> Too many connections (not
allowing connection) :: ")
(format t "Active Processes : ~A~%" (length
(mp:all-processes)))
(if (< (length (mp:all-processes)) (+ 2
*max-threads*))
(mp:make-process #'listener :name "Server
Listener")))))))
(mp:make-process #'listener :name "Server Listener 1"))))
(defun analyze-i (socket-fd)
(....................
use the socket stream read and save the data))
The good thing here is that spawning multiple listeners works real well.
everytime a connection is made another listener is sucessfully spawned and
another client can connect to that ...
The problem here is that if one connection starts writing data (and
analyze-i is started since the stream has data)...i.e., analyze-i is
reading the data and writing to disk..other processes has to wait till
this one is complete why is that??
what I mean here is that if two listeners are open and one starts
processing the data (i.e., one client uploaded a bunch of data onto that
port ...then the other listener cant run till the first one is complete
why is that??
(In other words why is the second listener process or the first listener
process have lower priority than the (analyze-i) process..is there
something i can do to fix this...
also how can one pass functional arguments to a function that is spawned
by (mp:make-process )??
i.e, lets say we have a function (test a b) how can we use
(mp:make-process #'test) to take a and b)
Thanks,
Murali