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

dataflow network programming with neuron
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Dataflow Network Programming with Neuron

Eric Griffis RacketCon 2018

  • St. Louis, MO

1

slide-2
SLIDE 2
  • I. Meet Nick

2

slide-3
SLIDE 3

Nick cares about cancer

3

slide-4
SLIDE 4

Curing cancer is expensive

4

slide-5
SLIDE 5

5

slide-6
SLIDE 6

6

slide-7
SLIDE 7
  • II. Enter Neuron

7

slide-8
SLIDE 8

The Neuron Framework

concurrency model messaging API process construction library

8

slide-9
SLIDE 9

Lightweight Processes

(process (λ () (forever (emit (f (take))))))

9

slide-10
SLIDE 10

Synchronous and Asymmetric

Simple Exchange

(give π v) → (take) (recv π) ← (emit v)

10-11

slide-11
SLIDE 11

Synchronous and Asymmetric

Mediated Exchange

(give πfwd v) → (forward-to π) → (take) (recv πfwd) ← (forward-from π) ← (emit v)

12

slide-12
SLIDE 12

Serial Messaging Endpoints

Sockets Codecs

13-14

slide-13
SLIDE 13

Sockets

  • input-output port
  • simplified messaging API
  • prevent half-open connections

15

slide-14
SLIDE 14

Codecs

  • printer and parser functions
  • encoder and decoder functions

16

slide-15
SLIDE 15

Parsers & Printers

parser :: (-> input-port? any/c)

read read-json

printer :: (-> any/c output-port? void?)

writeln write-json

17

slide-16
SLIDE 16

Codecs

decoder :: (-> parser (-> socket process)) encoder :: (-> printer (-> socket process)) codec :: (-> parser printer (-> socket process))

18

slide-17
SLIDE 17

UDP Endpoints

(define πudp-src (udp-source read "::" 5000)) (define πudp-snk (udp-sink write "somehost" 5000))

19

slide-18
SLIDE 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

slide-19
SLIDE 19
  • III. Putting it all Together

21

slide-20
SLIDE 20

Multiplayer Game Server

TCP service register clients UDP sinks broadcast world state world simulator refresh world state (default 10 Hz)

22-23

slide-21
SLIDE 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

slide-22
SLIDE 22

Game Server: UDP Sinks

(udp-sink writeln host port)

26

slide-23
SLIDE 23

Game Server: World Simulator

(define πsim (simulator update-world)) (for ([πpub (all-clients)]) (give πpub the-world))

27-28

slide-24
SLIDE 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

slide-25
SLIDE 25
  • IV. Summary & Conclusion

30

slide-26
SLIDE 26

Summary

  • Neuron is a compositional framework
  • Making network software development easy

(and fun!)

31

slide-27
SLIDE 27

What Happened to Nick?

32-33

slide-28
SLIDE 28

Thank You

Eric Griffis https://dedbox.github.io/ dedbox@gmail.com @dedbox on twitter and github

34