Megatest

Hex Artifact Content
Login

Artifact 62cc97e2a55cfd236cdcdc8bd6de7e91dc7d6a6e:


0000: 3b 3b 20 77 61 74 63 68 20 6e 61 6e 6f 6d 73 67  ;; watch nanomsg
0010: 27 73 20 70 69 70 65 6c 69 6e 65 20 6c 6f 61 64  's pipeline load
0020: 2d 62 61 6c 61 6e 63 65 72 20 69 6e 20 61 63 74  -balancer in act
0030: 69 6f 6e 2e 0a 28 75 73 65 20 6e 61 6e 6f 6d 73  ion..(use nanoms
0040: 67 20 70 6f 73 69 78 20 72 65 67 65 78 29 0a 0a  g posix regex)..
0050: 28 64 65 66 69 6e 65 20 72 65 71 20 20 20 28 6e  (define req   (n
0060: 6e 2d 73 6f 63 6b 65 74 20 27 72 65 71 29 29 0a  n-socket 'req)).
0070: 0a 28 6e 6e 2d 63 6f 6e 6e 65 63 74 20 72 65 71  .(nn-connect req
0080: 20 20 22 74 63 70 3a 2f 2f 6c 6f 63 61 6c 68 6f    "tcp://localho
0090: 73 74 3a 32 32 30 32 32 22 29 0a 0a 3b 3b 20 28  st:22022")..;; (
00a0: 77 69 74 68 2d 6f 75 74 70 75 74 2d 74 6f 2d 73  with-output-to-s
00b0: 74 72 69 6e 67 20 28 6c 61 6d 62 64 61 20 28 29  tring (lambda ()
00c0: 28 73 65 72 69 61 6c 69 7a 65 20 6f 62 6a 29 29  (serialize obj))
00d0: 29 0a 28 64 65 66 69 6e 65 20 28 63 6c 69 65 6e  ).(define (clien
00e0: 74 2d 73 65 6e 64 2d 72 65 63 65 69 76 65 20 73  t-send-receive s
00f0: 6f 63 20 6d 73 67 29 0a 20 20 28 6e 6e 2d 73 65  oc msg).  (nn-se
0100: 6e 64 20 73 6f 63 20 6d 73 67 29 0a 20 20 28 6e  nd soc msg).  (n
0110: 6e 2d 72 65 63 76 20 73 6f 63 29 29 0a 0a 28 64  n-recv soc))..(d
0120: 65 66 69 6e 65 20 28 28 74 61 6c 6b 2d 74 6f 2d  efine ((talk-to-
0130: 73 65 72 76 65 72 20 73 6f 63 29 29 0a 20 20 28  server soc)).  (
0140: 6c 65 74 20 6c 6f 6f 70 20 28 28 63 6e 74 20 32  let loop ((cnt 2
0150: 30 30 30 30 30 29 29 0a 20 20 20 20 28 6c 65 74  00000)).    (let
0160: 20 28 28 6e 61 6d 65 20 28 6c 69 73 74 2d 72 65   ((name (list-re
0170: 66 20 27 28 22 4d 61 74 74 22 20 22 54 6f 6d 22  f '("Matt" "Tom"
0180: 20 22 42 6f 62 22 20 22 4a 69 6c 6c 22 20 22 4a   "Bob" "Jill" "J
0190: 61 6d 65 73 22 20 22 4a 61 6e 65 22 29 28 72 61  ames" "Jane")(ra
01a0: 6e 64 6f 6d 20 36 29 29 29 29 0a 20 20 20 20 20  ndom 6)))).     
01b0: 20 3b 3b 20 28 70 72 69 6e 74 20 22 53 65 6e 64   ;; (print "Send
01c0: 69 6e 67 20 22 20 6e 61 6d 65 29 0a 20 20 20 20  ing " name).    
01d0: 20 20 3b 3b 20 28 70 72 69 6e 74 0a 20 20 20 20    ;; (print.    
01e0: 20 20 28 63 6c 69 65 6e 74 2d 73 65 6e 64 2d 72    (client-send-r
01f0: 65 63 65 69 76 65 20 72 65 71 20 6e 61 6d 65 29  eceive req name)
0200: 20 3b 3b 20 29 0a 20 20 20 20 20 20 28 69 66 20   ;; ).      (if 
0210: 28 3e 20 63 6e 74 20 30 29 28 6c 6f 6f 70 20 28  (> cnt 0)(loop (
0220: 2d 20 63 6e 74 20 31 29 29 29 29 29 0a 20 20 28  - cnt 1))))).  (
0230: 70 72 69 6e 74 20 28 63 6c 69 65 6e 74 2d 73 65  print (client-se
0240: 6e 64 2d 72 65 63 65 69 76 65 20 72 65 71 20 22  nd-receive req "
0250: 71 75 69 74 22 29 29 0a 20 20 28 6e 6e 2d 63 6c  quit")).  (nn-cl
0260: 6f 73 65 20 72 65 71 29 0a 20 20 28 65 78 69 74  ose req).  (exit
0270: 29 29 0a 0a 3b 3b 20 28 74 68 72 65 61 64 2d 73  ))..;; (thread-s
0280: 74 61 72 74 21 20 28 6c 61 6d 62 64 61 20 28 29  tart! (lambda ()
0290: 0a 3b 3b 20 09 09 20 28 74 68 72 65 61 64 2d 73  .;; .. (thread-s
02a0: 6c 65 65 70 21 20 32 30 29 0a 3b 3b 20 09 09 20  leep! 20).;; .. 
02b0: 28 70 72 69 6e 74 20 22 47 69 76 65 20 75 70 20  (print "Give up 
02c0: 6f 6e 20 77 61 69 74 69 6e 67 20 66 6f 72 20 74  on waiting for t
02d0: 68 65 20 73 65 72 76 65 72 22 29 0a 3b 3b 20 09  he server").;; .
02e0: 09 20 28 6e 6e 2d 63 6c 6f 73 65 20 72 65 71 29  . (nn-close req)
02f0: 0a 3b 3b 20 09 09 20 28 65 78 69 74 29 29 29 0a  .;; .. (exit))).
0300: 0a 28 74 68 72 65 61 64 2d 6a 6f 69 6e 21 20 28  .(thread-join! (
0310: 74 68 72 65 61 64 2d 73 74 61 72 74 21 20 28 74  thread-start! (t
0320: 61 6c 6b 2d 74 6f 2d 73 65 72 76 65 72 20 72 65  alk-to-server re
0330: 71 29 29 29 0a 0a                                q)))..