Index: testzmq/mockupserver.scm ================================================================== --- testzmq/mockupserver.scm +++ testzmq/mockupserver.scm @@ -6,10 +6,11 @@ (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) @@ -40,15 +41,18 @@ (lambda (id) (set! cid id)) db "SELECT id FROM clients WHERE name=?;" cname) (hash-table-set! cid-cache cname cid) + (set! total-db-accesses (+ total-db-accesses 2)) cid)))) (define (count-client db cname) (let ((cid (get-client-id db cname))) - (execute db "UPDATE clients SET num_accesses=num_accesses+1 WHERE id=?;" cid))) + (execute db "UPDATE clients SET num_accesses=num_accesses+1 WHERE id=?;" cid) + (set! total-db-accesses (+ total-db-accesses 1)) + )) (define db (open-db)) ;; (define queuelst '()) ;; (define mx1 (make-mutex)) @@ -62,13 +66,15 @@ (send-message pub cname send-more: #t) (send-message pub (case clcmd ((sync) (conc queuelen)) ((set) + (set! total-db-accesses (+ total-db-accesses 1)) (apply execute db "INSERT OR REPLACE INTO vars (var,val) VALUES (?,?);" (string-split cdata)) "ok") ((get) + (set! total-db-accesses (+ total-db-accesses 1)) (let ((res "noval")) (for-each-row (lambda (val) (set! res val)) db @@ -107,18 +113,19 @@ (lambda () (let ((last-action-time (current-seconds))) (let loop () (thread-sleep! 5) (let ((queuelen (string->number (dbaccess "server" 'sync "nada" #f))) - (last-action-delta (- (current-seconds) last-action-time))) - (print "Server: Got queuelen=" queuelen ", last-action-delta=" last-action-delta) + (last-action-delta #f)) (if (> queuelen 1)(set! last-action-time (current-seconds))) - (if (< last-action-delta 15) + (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, 15 seconds since last access")))))) + (print "Server exiting, 25 seconds since last access")))))) "sync thread")) (thread-start! th1) (thread-start! th2) (thread-join! th2) -(print "Server exited!") +(print "Server exited! Total db accesses=" total-db-accesses) Index: testzmq/testmockup.sh ================================================================== --- testzmq/testmockup.sh +++ testzmq/testmockup.sh @@ -17,12 +17,12 @@ do for k in a b; do for j in 0 1 2 3 4 5 6 7 8 9; do - waittime=`random 0 20` - runtime=`random 5 20` + waittime=`random 0 30` + runtime=`random 5 120` echo "Starting client $i$k$j with waittime $waittime and runtime $runtime" (sleep $waittime;./mockupclient $i$k$j $runtime) & done done done