1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
;; watch nanomsg's pipeline load-balancer in action.
(use nanomsg)
;; (use trace)
;; (trace nn-bind nn-socket nn-assert nn-recv nn-send thread-terminate! nn-close )
(define port 22022)
(define host "127.0.0.1")
(define rep (nn-socket 'rep))
(print "connecting, got: " (nn-bind rep (conc "tcp://" "*" ":" port)))
(define (server soc)
(print "server starting")
(let loop ((msg-in (nn-recv soc)))
(print "server received: " msg-in)
(cond
((equal? msg-in "quit")
(nn-send soc "Ok, quitting"))
((and (>= (string-length msg-in) 4)
(equal? (substring msg-in 0 4) "ping"))
(nn-send soc (conc (current-process-id)))
(loop (nn-recv soc)))
;;((and (>= (string-length msg-in)
(else
(let ((this-task (random 10)))
(thread-sleep! (/ this-task 10.0))
(nn-send soc (conc "hello " msg-in " this task took " this-task " seconds to complete"))
(loop (nn-recv soc)))))))
(define (ping-self host port #!key (return-socket #t))
;; send a random number along with pid and check that we get it back
(let* ((req (nn-socket 'req))
(key "ping")
(success #f)
(keepwaiting #t)
|
|
|
>
>
|
|
|
>
|
>
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
;; watch nanomsg's pipeline load-balancer in action.
(use nanomsg posix regex)
;; (use trace)
;; (trace nn-bind nn-socket nn-assert nn-recv nn-send thread-terminate! nn-close )
(define port 22022)
(define host "127.0.0.1")
(define rep (nn-socket 'rep))
(print "connecting, got: " (nn-bind rep (conc "tcp://" "*" ":" port)))
(define (server soc)
(print "server starting")
(let loop ((msg-in (nn-recv soc))
(count 0))
(if (eq? 0 (modulo count 1000))
(print "server received: " msg-in ", count=" count))
(cond
((equal? msg-in "quit")
(nn-send soc "Ok, quitting"))
((and (>= (string-length msg-in) 4)
(equal? (substring msg-in 0 4) "ping"))
(nn-send soc (conc (current-process-id)))
(loop (nn-recv soc)(+ count 1)))
;;((and (>= (string-length msg-in)
(else
(let ((this-task (/ (random 10) 200.0))
(start-time (current-milliseconds)))
;; (thread-sleep! this-task)
(nn-send soc (conc "hello " msg-in " this task took " this-task " seconds to complete"))
;; (print "Actual send-receive time: " (- (current-milliseconds) start-time));
(loop (nn-recv soc)(+ count 1)))))))
(define (ping-self host port #!key (return-socket #t))
;; send a random number along with pid and check that we get it back
(let* ((req (nn-socket 'req))
(key "ping")
(success #f)
(keepwaiting #t)
|