syndicate-rkt/syndicate-examples/speed-tests/box-and-client-with-dataspa...

45 lines
1.5 KiB
Racket

#lang syndicate
(require syndicate/schemas/gen/box-protocol)
(define (report-stats REPORT_EVERY)
(define start-time (current-inexact-milliseconds))
(define prev-value 0)
(lambda (new-value)
(when (zero? (remainder new-value REPORT_EVERY))
(define end-time (current-inexact-milliseconds))
(define delta (/ (- end-time start-time) 1000.0))
(define count (- new-value prev-value))
(set! prev-value new-value)
(set! start-time end-time)
(log-info "Box got ~a (~a Hz)" new-value (/ count delta)))))
(define box
(action (ds LIMIT REPORT_EVERY)
(spawn #:name 'box
(define root-facet this-facet)
(define-field value 0)
(define reporter (report-stats REPORT_EVERY))
(at ds
(assert (BoxState (value)))
(when (message (SetBox $new-value))
(reporter new-value)
(when (= new-value LIMIT) (stop-facet root-facet))
(value new-value))))))
(define client
(action (ds)
(spawn #:name 'client
(define root-facet this-facet)
(at ds
(when (asserted (BoxState $value)) (send! ds (SetBox (+ value 1))))
(during (BoxState _)
(on-stop (log-info "Client detected box termination")
(stop-facet root-facet)))))))
(module+ main
(time
(actor-system/dataspace (ds)
(box this-turn ds 500000 100000)
(client this-turn ds))))