dataflow network programming with neuron
play

Dataflow Network Programming with Neuron Eric Griffis RacketCon - PowerPoint PPT Presentation

Dataflow Network Programming with Neuron Eric Griffis RacketCon 2018 St. Louis, MO 1 I. Meet Nick 2 Nick cares about cancer 3 Curing cancer is expensive 4 5 6 II. Enter Neuron 7 The Neuron Framework concurrency model messaging API


  1. Dataflow Network Programming with Neuron Eric Griffis RacketCon 2018 St. Louis, MO 1

  2. I. Meet Nick 2

  3. Nick cares about cancer 3

  4. Curing cancer is expensive 4

  5. 5

  6. 6

  7. II. Enter Neuron 7

  8. The Neuron Framework concurrency model messaging API process construction library 8

  9. Lightweight Processes (process ( λ () (forever (emit (f (take)))))) 9

  10. Synchronous and Asymmetric Simple Exchange (give π v) → (take) (recv π ) ← (emit v) 10-11

  11. Synchronous and Asymmetric Mediated Exchange (give π fwd v) → (forward-to π ) → (take) (recv π fwd ) ← (forward-from π ) ← (emit v) 12

  12. Serial Messaging Endpoints Codecs Sockets 13-14

  13. Sockets • input-output port • simplified messaging API • prevent half-open connections 15

  14. Codecs • printer and parser functions • encoder and decoder functions 16

  15. Parsers & Printers parser :: (-> input-port? any/c) read read-json printer :: (-> any/c output-port? void?) writeln write-json 17

  16. Codecs decoder :: (-> parser (-> socket process)) encoder :: (-> printer (-> socket process)) codec :: (-> parser printer (-> socket process)) 18

  17. UDP Endpoints (define π udp-src (udp-source read "::" 5000)) (define π udp-snk (udp-sink write "somehost" 5000)) 19

  18. TCP Endpoints (define π tcp-cli (tcp-client "somehost" 1234)) (define π tcp-srv (tcp-server 1234)) (define π tcp-svc (tcp-service sexp-codec 1234)) 20

  19. III. Putting it all Together 21

  20. Multiplayer Game Server TCP service register clients UDP sinks broadcast world state world simulator refresh world state (default 10 Hz) 22-23

  21. Game Server: TCP Service (define π svc (tcp-service sexp-codec 3000)) (forever (define-values (key msg) (recv π svc )) (match msg [`(SET ,host ,port) (set-client key host port)] [`(DROP ,host ,port) (drop-client key)] [`(MOVE , Δ x , Δ y) (move-client key Δ x Δ y)])) 24-25

  22. Game Server: UDP Sinks (udp-sink writeln host port) 26

  23. Game Server: World Simulator (define π sim (simulator update-world)) (for ([ π pub (all-clients)]) (give π pub the-world)) 27-28

  24. Complete Game Server (define-values (world clients) (values (make-hash) (make-hash))) (define π svc (tcp-service sexp-codec 3000)) (define (set-client key host port) ... (hash-set! clients key (udp-sink writeln host port))) (define (update-world Δ t) ... (define the-world (hash->list world)) (for ([ π pub (hash-values clients)]) (give π pub the-world))) (define π sim (simulator update-world)) (forever (define-values (key msg) (recv π svc )) (match msg [`(SET ,host ,port) (set-client key host port)] [`(DROP ,host ,port) (drop-client key)] [`(MOVE , Δ x , Δ y) (move-client key Δ x Δ y)])) 29

  25. IV. Summary & Conclusion 30

  26. Summary • Neuron is a compositional framework • Making network software development easy (and fun!) 31

  27. What Happened to Nick? 32-33

  28. Thank You Eric Griffis https://dedbox.github.io/ dedbox@gmail.com @dedbox on twitter and github 34

Recommend


More recommend