[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]

   Date: Thu, 24 Oct 91 18:01:58 GMT
   From: smith@icat.larc.nasa.gov (Steven L. Smith)

     The communication time required to send the form to host B, evaluate
   it, and return the result back to A is the most time consuming. One possible
   way to speed things up is to keep the stream  open during the session and
   close it upon exiting the program (although not to sure how to do this).

   Anyway, if you have any ideas or know of a faster way to implement this,
   please let me know. Thanks in advance.

Reusing the stream is probably the best way, if you expect to be sending
forms between the same hosts quite a bit.  To do this, change the protocol
so that it just returns the open stream rather than actually performing the

(NET:DEFINE-PROTOCOL :simple-eval (:simple-eval :BYTE-STREAM)

Then maintain a table of connections:

(defvar *eval-connections* nil)

(defun get-eval-connection (host)
  (setq host (net:parse-host host))
  (let ((conn (cdr (assoc host *eval-connections*))))
    (unless conn
      (setq conn (net:invoke-service-on-host :simple-eval host))
      (push (cons host conn) *eval-connections*))

(defun close-eval-connection (host &key abort)
  (setq host (net:parse-host host))
  (let ((conn (cdr (assoc host *eval-connections*))))
    (when conn
      (close conn :abort abort)
      (setq *eval-connections*
	    (delete host *eval-connections* :key #'car)))))

Now move all the transaction implementation into NET-EVAL:

(defun net-eval (form &optional (host *remote-host))
  (let ((stream (get-eval-connection host)))
    ;Send form and read result in known environment.
      (PRINT form stream)
      (FORCE-OUTPUT stream)
      (APPLY 'values (PROG1 (READ stream)
                            (LOOP WHILE (SCL::SEND stream :TYI)))))))

The change to the server is even simpler.  It just sits in a loop until it
reads EOF:

                                  (stream :ACCEPT-P t :ASCII-TRANSLATION t
                                     :CHARACTERS t))
  (condition-case ()
          (PRINT (MULTIPLE-VALUE-LIST (EVAL (READ stream))) stream))
        (FORCE-OUTPUT stream))

I haven't actually tried any of this code, so there could be bugs.