1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
;; pub/sub with envelope address
;; Note that if you don't insert a sleep, the server will crash with SIGPIPE as soon
;; as a client disconnects. Also a remaining client may receive tons of
;; messages afterward.
(use zmq srfi-18 sqlite3)
(define pub (make-socket 'pub))
(define pull (make-socket 'pull))
(define cname "server")
(define total-db-accesses 0)
(bind-socket pub "tcp://*:5563")
(bind-socket pull "tcp://*:5564")
(define (open-db)
(let* ((dbpath "mockup.db")
(dbexists (file-exists? dbpath))
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
;; pub/sub with envelope address
;; Note that if you don't insert a sleep, the server will crash with SIGPIPE as soon
;; as a client disconnects. Also a remaining client may receive tons of
;; messages afterward.
(use zmq srfi-18 sqlite3)
(define pub (make-socket 'pub))
(define pull (make-socket 'pull))
(define cname "server")
(define total-db-accesses 0)
(define start-time (current-seconds))
(bind-socket pub "tcp://*:5563")
(bind-socket pull "tcp://*:5564")
(define (open-db)
(let* ((dbpath "mockup.db")
(dbexists (file-exists? dbpath))
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
(let loop ()
(thread-sleep! 5)
(let ((queuelen (string->number (dbaccess "server" 'sync "nada" #f)))
(last-action-delta #f))
(if (> queuelen 1)(set! last-action-time (current-seconds)))
(set! last-action-delta (- (current-seconds) last-action-time))
(print "Server: Got queuelen=" queuelen ", last-action-delta=" last-action-delta)
(if (< last-action-delta 25)
(loop)
(print "Server exiting, 25 seconds since last access"))))))
"sync thread"))
(thread-start! th1)
(thread-start! th2)
(thread-join! th2)
(print "Server exited! Total db accesses=" total-db-accesses)
|
|
>
>
|
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
(let loop ()
(thread-sleep! 5)
(let ((queuelen (string->number (dbaccess "server" 'sync "nada" #f)))
(last-action-delta #f))
(if (> queuelen 1)(set! last-action-time (current-seconds)))
(set! last-action-delta (- (current-seconds) last-action-time))
(print "Server: Got queuelen=" queuelen ", last-action-delta=" last-action-delta)
(if (< last-action-delta 60)
(loop)
(print "Server exiting, 25 seconds since last access"))))))
"sync thread"))
(thread-start! th1)
(thread-start! th2)
(thread-join! th2)
(let* ((run-time (- (current-seconds) start-time))
(queries/second (/ total-db-accesses run-time)))
(print "Server exited! Total db accesses=" total-db-accesses " in " run-time " seconds for " queries/second " queries/second"))
|