Index: testzmq/mockupclient.scm ================================================================== --- testzmq/mockupclient.scm +++ testzmq/mockupclient.scm @@ -6,30 +6,30 @@ (begin (print "Usage: mockupclient clientname") (exit)) (set! cname (cadr args)))) -(define sub (make-socket 'sub)) -(define push (make-socket 'push)) -(socket-option-set! sub 'subscribe cname) -(connect-socket sub "tcp://localhost:5563") -(connect-socket push "tcp://localhost:5564") - -(define (dbaccess cmd var val) - (let ((msg (conc cname ":" cmd ":" (if val (conc var " " val) var)))) - (print "Sending msg: " msg) - (send-message push msg) - (receive-message* sub) - (receive-message* sub))) +(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") + +(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 'sync "nodat" #f)) - ((2 3 4 5)(dbaccess 'set varname (random 999))) - ((6 7 8 9 10)(print cname ": Get \"" varname "\" " (dbaccess 'get varname #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.01))) - (loop))) + (thread-sleep! 0.1))) + (if (< (current-seconds) endtime) + (loop)))) - +(print "Client " cname " all done!!") Index: testzmq/mockupserver.scm ================================================================== --- testzmq/mockupserver.scm +++ testzmq/mockupserver.scm @@ -5,10 +5,11 @@ (use zmq srfi-18 sqlite3) (define pub (make-socket 'pub)) (define pull (make-socket 'pull)) +(define cname "server") (bind-socket pub "tcp://*:5563") (bind-socket pull "tcp://*:5564") (define (open-db) @@ -20,10 +21,11 @@ (if (not dbexists) (for-each (lambda (stmt) (execute db stmt)) (list + "PRAGMA SYNCHRONOUS=0;" "CREATE TABLE clients (id INTEGER PRIMARY KEY,name TEXT,num_accesses INTEGER DEFAULT 0);" "CREATE TABLE vars (var TEXT,val TEXT,CONSTRAINT vars_constraint UNIQUE (var));"))) db)) (define cid-cache (make-hash-table)) @@ -56,10 +58,12 @@ (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")) @@ -84,30 +88,29 @@ (svect (vector (current-seconds) cname clcmd cdata))) ;; record for the queue (count-client db cname) (case clcmd ((sync) ;; just process the queue (print "Got sync from " cname) - (process-queue queuelst) + (process-queue (cons svect queuelst)) (loop '())) - ((imediate) + ((get) (process-queue (cons svect queuelst)) (loop '())) (else (loop (cons svect queuelst)))))))) "server thread")) -(define push (make-socket 'push)) -(connect-socket push "tcp://localhost:5564") +(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") - (send-message push "server:sync:nodat") + (dbaccess "server" 'sync "nada" #f) (loop))) "sync thread")) (thread-start! th1) (thread-start! th2) (thread-join! th1) Index: testzmq/testmockup.sh ================================================================== --- testzmq/testmockup.sh +++ testzmq/testmockup.sh @@ -10,15 +10,19 @@ ./mockupserver & sleep 1 echo Starting clients -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;do +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; + do + for j in 0 1 2 3 4 5 6 7 8 9; + do echo Starting client $i$j ./mockupclient $i$j & done done -echo "Running for one minute then killing all mockupserver and mockupclient processes" -sleep 60 -killall -v mockupserver mockupclient +wait +# echo "Running for one minute then killing all mockupserver and mockupclient processes" +# sleep 60 +# killall -v mockupserver mockupclient