an r7rs compatible module system for termite scheme els 20
play

An R7RS Compatible Module System for Termite Scheme ELS20 Frdric - PowerPoint PPT Presentation

An R7RS Compatible Module System for Termite Scheme ELS20 Frdric Hamel Marc Feeley 2 Termite Scheme Built on top of Gambit Scheme Designed to simplify programming distributed systems composed of a network of communicating nodes


  1. An R7RS Compatible Module System for Termite Scheme ELS’20 Frédéric Hamel Marc Feeley

  2. 2 Termite Scheme • Built on top of Gambit Scheme • Designed to simplify programming distributed systems composed of a network of communicating nodes • Uses the Actor model : each node executes one or more threads reacting to messages received in their mailbox network

  3. 3 Heterogeneous Systems • A common situation is using nodes with di ff erent characteristics (instruction set, peripherals, type and version of OS, etc) • To allow code to run on any type of node the code is either interpreted or compiled to a portable bytecode or compiled to machine code for each type of node (the best in terms of run time performance) • How to send messages that contain code (procedures) in a heterogeneous system that compiles to machine code? x86/Windows CODE network ARM/Linux

  4. Gambit Features 4 • Gambit compiles to fast portable C code (machine/OS agnostic) • Messages transferred between nodes are encoded by Gambit using a machine independent sequence of bytes #x23 #x51 #x52 #x53 #(1 2 3) #(1 2 3) • The serialization format supports procedures/closures , continuations , sharing and cycles • This simplifies programming: • Remote Procedure Call (RPC) => send a procedure/closure • Task migration => send a continuation • Hot code update => send a proc./closure/cont. of code not previously known by destination node

  5. Hot Code Update Example 5 server (import (termite)) (node-init ":7000") ;; on port 7000 (define server ;; pong service thread (spawn (lambda () (let loop () (recv ((from tag 'PING) (! from (list tag 'PONG)))) (loop))))) (publish-service 'pong-server server) (thread-join! server) ;; wait for end

  6. Hot Code Update Example 6 server Termite Scheme cheat sheet (import (termite)) (node-init ":7000") ;; on port 7000 (define server ;; pong service thread (recv (spawn get next message ( pattern (lambda () from mailbox (let loop () action ) and pattern match ...) (recv ((from tag 'PING) (! from (list tag 'PONG)))) send msg to dest (! dest msg ) (loop))))) (publish-service 'pong-server server) send ( self tag msg ) (thread-join! server) ;; wait for end (!? dest msg ) to dest and receive ( tag result )

  7. Hot Code Update Example 7 server Termite Scheme cheat sheet (import (termite)) (node-init ":7000") ;; on port 7000 (define server ;; pong service thread (recv (spawn get next message ( pattern (lambda () from mailbox (let loop () action ) and pattern match ...) (recv ((from tag 'PING) (! from (list tag 'PONG)))) send msg to dest (! dest msg ) (loop))))) (publish-service 'pong-server server) send ( self tag msg ) (thread-join! server) ;; wait for end (!? dest msg ) to dest and receive ( tag result )

  8. 8 server client (import (termite)) (import (termite)) (node-init ":7000") ;; on port 7000 (node-init) ;; on fresh port (define server ;; pong service thread (define server (spawn (remote-service 'pong-server (lambda () ":7000")) (let loop () PING (recv ((from tag 'PING) (println (!? server 'PING)) (! from (list tag 'PONG)))) PONG (loop))))) (publish-service 'pong-server server) (thread-join! server) ;; wait for end

  9. 9 Add Support for Hot Code Update server (import (termite)) (node-init ":7000") ;; on port 7000 (define server ;; pong service thread (spawn (lambda () (let loop () (recv handling of the UPDATE ((from tag 'PING) (! from (list tag 'PONG)))) message that replaces the behaviour of the ((from tag ('UPDATE k)) (! from (list tag 'ACK)) server with a new (k #t))) continuation k contained (loop))))) in the message (publish-service 'pong-server server) (thread-join! server) ;; wait for end

  10. updater 10 ... server code for new (define new-server (spawn (import (termite)) behaviour of (lambda () (let loop () pong service (node-init ":7000") ;; on port 7000 (recv (define server ;; pong service thread (spawn ((from tag 'PING) (lambda () (! from (list tag 'HELLO))) (let loop () ((from tag ('UPDATE k)) (recv (! from (list tag 'ACK)) (k #t)) handling of the UPDATE ((from tag 'PING) (! from (list tag 'PONG)))) message that replaces ((from tag ('MIGRATE dest)) (call/cc the behaviour of the ((from tag ('UPDATE k)) (lambda (k) (! from (list tag 'ACK)) server with a new (!? dest (list 'UPDATE k)) (k #t))) (! from (list tag 'ACK)))))) continuation k contained (loop))))) (loop))))) in the message (publish-service 'pong-server server) (!? new-server (list 'MIGRATE server)) (thread-join! server) ;; wait for end (println (!? server 'PING)) ;; HELLO

  11. updater 11 ... server code for new (define new-server (spawn (import (termite)) behaviour of (lambda () (let loop () pong service (node-init ":7000") ;; on port 7000 (recv (define server ;; pong service thread (spawn ((from tag 'PING) (lambda () (! from (list tag 'HELLO))) (let loop () ((from tag ('UPDATE k)) (recv (! from (list tag 'ACK)) (k #t)) handling of the UPDATE ((from tag 'PING) (! from (list tag 'PONG)))) message that replaces ((from tag ('MIGRATE dest)) (call/cc the behaviour of the ((from tag ('UPDATE k)) (lambda (k) (! from (list tag 'ACK)) UPDATE server with a new (!? dest (list 'UPDATE k)) (k #t))) (! from (list tag 'ACK)))))) continuation k contained (loop))))) MIGRATE (loop))))) in the message (publish-service 'pong-server server) (!? new-server (list 'MIGRATE server)) (thread-join! server) ;; wait for end (println (!? server 'PING)) ;; HELLO

  12. updater 12 ... server code for new (define new-server (spawn (import (termite)) behaviour of (lambda () (let loop () continuation (let loop () pong service (node-init ":7000") ;; on port 7000 (recv (recv ((from tag 'PING) (define server ;; pong service thread (! from (list tag 'HELLO))) (spawn ((from tag ('UPDATE k)) ((from tag 'PING) (lambda () (! from (list tag 'ACK)) (! from (list tag 'HELLO))) (k #t)) (let loop () ((from tag ('MIGRATE dest)) ((from tag ('UPDATE k)) (call/cc (recv (lambda (k) (! from (list tag 'ACK)) (!? dest (list 'UPDATE k)) (k #t)) (! from (list tag 'ACK)))))) handling of the UPDATE ((from tag 'PING) (loop)) (! from (list tag 'PONG)))) message that replaces ((from tag ('MIGRATE dest)) (call/cc the behaviour of the ((from tag ('UPDATE k)) (lambda (k) (! from (list tag 'ACK)) UPDATE server with a new (!? dest (list 'UPDATE k)) (k #t))) (! from (list tag 'ACK)))))) continuation k contained (loop))))) MIGRATE (loop))))) in the message (publish-service 'pong-server server) (!? new-server (list 'MIGRATE server)) (thread-join! server) ;; wait for end (println (!? server 'PING)) ;; HELLO

  13. updater 13 ... server code for new (define new-server (spawn (import (termite)) behaviour of (lambda () (let loop () continuation (let loop () pong service (node-init ":7000") ;; on port 7000 (recv (recv ((from tag 'PING) (define server ;; pong service thread (! from (list tag 'HELLO))) (spawn ((from tag ('UPDATE k)) ((from tag 'PING) (lambda () (! from (list tag 'ACK)) (! from (list tag 'HELLO))) (k #t)) (let loop () ((from tag ('MIGRATE dest)) ((from tag ('UPDATE k)) (call/cc (recv (lambda (k) (! from (list tag 'ACK)) (!? dest (list 'UPDATE k)) (k #t)) (! from (list tag 'ACK)))))) handling of the UPDATE PING ((from tag 'PING) (loop)) (! from (list tag 'PONG)))) message that replaces ((from tag ('MIGRATE dest)) (call/cc the behaviour of the ((from tag ('UPDATE k)) (lambda (k) (! from (list tag 'ACK)) server with a new (!? dest (list 'UPDATE k)) (k #t))) (! from (list tag 'ACK)))))) HELLO continuation k contained (loop))))) (loop))))) in the message (publish-service 'pong-server server) (!? new-server (list 'MIGRATE server)) (thread-join! server) ;; wait for end (println (!? server 'PING)) ;; HELLO

  14. 14 Issues with Compiled code • The original implementation of Termite Scheme allows unrestricted serialization/deserialization of interpreted code • Compiled code can only be deserialized when the receiving node contains the same compiled code (by identifying each control point symbolically, e.g. control point #5 in procedure foobar ) • This restriction • limits changing the code base during execution • hinders the use of fast compiled code in RPC • precludes the use of hot code update of a compiled program • Our work brings a solution to this issue in the form of a R7RS compatible module system that installs and compiles code on demand

  15. Our Solution 15 • A module’s source code is hosted on a VCS server accessible on the network, such as github or gitlab • A hosted module’s name identifies its location and version : (github.com/fred hello @2.0) or equivalently github.com/fred/hello@2.0 • The hosted module’s name is embedded in the name of procedures defined in the module (in the namespace) allowing the deserialization process to locate, fetch and compile the module’s source code if it is not yet installed: github.com/fred/hello@2.0#hi name in module namespace prefix of module

Recommend


More recommend