Index: testzmq/mockupclient.scm ================================================================== --- testzmq/mockupclient.scm +++ testzmq/mockupclient.scm @@ -1,32 +1,32 @@ (use zmq posix) (define cname "Bob") +(define runtime 10) (let ((args (argv))) - (if (< (length args) 2) + (if (< (length args) 3) (begin - (print "Usage: mockupclient clientname") + (print "Usage: mockupclient clientname runtime") (exit)) - (set! cname (cadr args)))) - -(randomize) -(define start-delay (/ (random 100) 9)) -(define runtime (+ 1 (/ (random 200) 2))) - -(print "client " cname " with start delay " start-delay " and runtime " runtime) -(thread-sleep! start-delay) -(print "client " cname " started") + (begin + (set! cname (cadr args)) + (set! runtime (string->number (caddr args)))))) + +;; (define start-delay (/ (random 100) 9)) +;; (define runtime (+ 1 (/ (random 200) 2))) + +(print "Starting client " cname " with runtime " runtime) (include "mockupclientlib.scm") (set! endtime (+ (current-seconds) runtime)) (let loop () (let ((x (random 15)) (varname (list-ref (list "hello" "goodbye" "saluton" "kiaorana")(random 4)))) (case x - ((1)(dbaccess cname 'sync "nodat" #f)) + ;; ((1)(dbaccess cname 'sync "nodat" #f)) ((2 3 4 5)(dbaccess cname 'set varname (random 999))) ((6 7 8 9 10)(print cname ": Get \"" varname "\" " (dbaccess cname 'get varname #f))) (else (thread-sleep! 0.1))) (if (< (current-seconds) endtime) Index: testzmq/mockupserver.scm ================================================================== --- testzmq/mockupserver.scm +++ testzmq/mockupserver.scm @@ -51,32 +51,33 @@ (define db (open-db)) ;; (define queuelst '()) ;; (define mx1 (make-mutex)) (define (process-queue queuelst) - (for-each - (lambda (item) - (let ((cname (vector-ref item 1)) - (clcmd (vector-ref item 2)) - (cdata (vector-ref item 3))) - (send-message pub cname send-more: #t) - (send-message pub (case clcmd - ((sync) - "ok") - ((set) - (apply execute db "INSERT OR REPLACE INTO vars (var,val) VALUES (?,?);" (string-split cdata)) - "ok") - ((get) - (let ((res "noval")) - (for-each-row - (lambda (val) - (set! res val)) - db - "SELECT val FROM vars WHERE var=?;" cdata) - res)) - (else (conc "unk cmd: " clcmd)))))) - queuelst)) + (let ((queuelen (length queuelst))) + (for-each + (lambda (item) + (let ((cname (vector-ref item 1)) + (clcmd (vector-ref item 2)) + (cdata (vector-ref item 3))) + (send-message pub cname send-more: #t) + (send-message pub (case clcmd + ((sync) + (conc queuelen)) + ((set) + (apply execute db "INSERT OR REPLACE INTO vars (var,val) VALUES (?,?);" (string-split cdata)) + "ok") + ((get) + (let ((res "noval")) + (for-each-row + (lambda (val) + (set! res val)) + db + "SELECT val FROM vars WHERE var=?;" cdata) + res)) + (else (conc "unk cmd: " clcmd)))))) + queuelst))) (define th1 (make-thread (lambda () (let ((last-run 0)) ;; current-seconds when run last (let loop ((queuelst '())) @@ -102,15 +103,22 @@ (include "mockupclientlib.scm") ;; send a sync to the pull port (define th2 (make-thread (lambda () - (let loop () - (thread-sleep! 5) - ;; (print "Sending sync from server") - (dbaccess "server" 'sync "nada" #f) - (loop))) + (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) + (if (> queuelen 1)(set! last-action-time (current-seconds))) + (if (< last-action-delta 15) + (loop) + (print "Server exiting, 15 seconds since last access")))))) "sync thread")) (thread-start! th1) (thread-start! th2) -(thread-join! th1) +(thread-join! th2) + +(print "Server exited!") Index: testzmq/testmockup.sh ================================================================== --- testzmq/testmockup.sh +++ testzmq/testmockup.sh @@ -11,16 +11,21 @@ sleep 1 echo Starting clients IVALS= -for i in a b c d e f g h i j k l m n o p q s t u v w x y z; +for i in a b c d e f g h i j k l m n o p q s t u v w x y z; do - for j in 0 1 2 3 4 5 6 7 8 9; + for k in a b; do - echo Starting client $i$j - ./mockupclient $i$j & + for j in 0 1 2 3 4 5 6 7 8 9; + do + waittime=`random 0 20` + runtime=`random 5 20` + echo "Starting client $i$k$j with waittime $waittime and runtime $runtime" + (sleep $waittime;./mockupclient $i$k$j $runtime) & + done done done wait # echo "Running for one minute then killing all mockupserver and mockupclient processes"