Presentation is loading. Please wait.

Presentation is loading. Please wait.

C. Varela1 Chapter 4: Actors Programming Distributed Computing Systems: A Foundational Approach Carlos Varela Rensselaer Polytechnic Institute.

Similar presentations


Presentation on theme: "C. Varela1 Chapter 4: Actors Programming Distributed Computing Systems: A Foundational Approach Carlos Varela Rensselaer Polytechnic Institute."— Presentation transcript:

1 C. Varela1 Chapter 4: Actors Programming Distributed Computing Systems: A Foundational Approach Carlos Varela Rensselaer Polytechnic Institute

2 Open Distributed Systems Addition of new components Replacement of existing components Changes in interconnections C. Varela2

3 Actor Configurations Model open system components: –Set of indivitually named actors –Messages “en-route” –Interface to environment: Receptionists External actors C. Varela3

4 Synchronous vs. Asynchronous Comminucation π-Calculus (and other process algebras such as CSS, CSP) take synchronous communication as a primitive Actors assume asynchronous communication is more primitive C. Varela4

5 Communication Medium In π-Calculus, channels are explicitly modelled. Multiple processes can share a channel, potentially causing intereference. In the actor model, the communication medium is not explicit. Actors (active objects) are first-class, history- sensitive entities with an explicit identity used for communication. C. Varela5

6 Fairness The actor model theory assumes fair computations: 1.Message delivery is guaranteed. 2.Individual actor computations are guaranteed to progress. Fairness is very useful for reasoning about equivalences of actor programs but can be hard/expensive to guarantee; in particular when distribution and failures are considered. C. Varela6

7 Programming Languages Influenced by П-Calculus and Actors Scheme ‘75 Act1 ‘87 Acore ‘87 Rosette ‘89 Obliq ‘94 Erlang ‘93 ABCL ‘90 SALSA ‘99 C. Varela7 Amber ’86 Facile ’89 CML ’91 Pict ’94 Nomadic Pict ’99 JOCAML ‘99

8 Actor (Agent) Model C. Varela8

9 Agha, Mason, Smith & Talcott 1.Extend a functional language (λ-calculus + ifs and pairs) with actor primitives. 2.Define an operational semantics for actor configurations. 3.Study various notions of equivalence of actor expressions and configurations. 4.Assume fairness: –Guaranteed message delivery. –Individual actor progress. C. Varela9

10 λ-Calculus Syntax e ::= vvalue | λv.efunctional abstraction | ( e e )application Example ( λx.x 2 2 ) x 2 {2/x} (in π-calculus) [2/x]x 2 (in λ-calculus) C. Varela10 λx.x 2 2 2

11 λ-Calculus pr(x,y)returns a pair containing x & y ispr(x)returns t if x is a pair; f otherwise 1 st (pr(x,y)) = xreturns the first value of a pair 2 nd (pr(x,y)) = yreturns the second value of a pair C. Varela11

12 Actor Primitives send(a,v) –Sends value v to actor a. new(b) –Creates a new actor with behavior b and returns the identity/name of the newly created actor. ready(b) –Becomes ready to receive a new message with behavior b. C. Varela12

13 Actor Language Example b5 = rec(λy. λx.seq(send(x,5), ready(y))) Receives an actor name x and sends the number 5 to that actor, then it becomes ready to process new messages with the same behavior y. Sample usage: send(new(b5), a) A Sink: sink = rec(λb. λm.ready(b)) An actor that disregards all messages. C. Varela13

14 Reference Cell Cell = rec(λb.λc.λm. if ( get?(m), seq( send(cust(m), c), ready(b(c))) if ( set?(m), ready(b(contents(m))), ready(b(c))))) Using the cell: Let a = new(cell(0)) in seq( send(a, mkset(7)), send(a, mkset(2)), send(a, mkget(c))) C. Varela14

15 Exercises 1.Write get? cust set? contents mkset mkget to complete the reference cell example in the AMST actor language. 2.Modify B cell to notify a customer when the cell value is updated (such as in the П-calculus cell example). C. Varela15

16 Dining Philosophers phil = rec(λb.λl.λr.λself.λsticks.λm. if (eq?(sticks, 0), ready(b(l,r,self,1)), seq( send(l,mkrelease(self)), send(r,mkrelease(self)), send(l,mkpickup(self)), send(r,mkpickup(self)), ready(b(l,r,self,0))))) C. Varela16

17 Dining Philosophers chopstick = rec(λb.λh.λw.λm. if(pickup?(m), if(eq?(h,nil), seq( send(getphil(m), nil), ready(b(getphil(m),nil))), ready(b(h,getphil(m))), if(release?(m), if(eq?(w,nil), ready(b(nil, nil)), seq( send(w,nil), ready(b(w,nil)))), ready(b(h,w))))) C. Varela17

18 Dining Philosophers letrec c1 = new(chopstick(nil,nil)), c2 = new(chopstick(nil,nil)), p1 = new(phil(c1,c2,p1,0)), p2 = new(phil(c2,c1,p2,0)) in seq( send(c1,mkpickup(p1)), send(c2,mkpickup(p1)), send(c1,mkpickup(p2)), send(c2,mkpickup(p2))) C. Varela18

19 Dining Philosophers Auxiliary definitions: mkpickup = λp.p mkrelease = nil pickup? = λm.not(eq?(m,nil)) release? = λm.eq?(m,nil) getphil = λm.m C. Varela19

20 Actor Garbage Collection C. Varela20 2 8 3 4 5 7 9 11 10 12 6 1 Blocked (idle) Unblocked (non-idle) Root

21 Join Continuations Consider: treeprod = rec(λf.λtree. if(isnat(tree), tree, f(left(tree))*f(right(tree)) )) Which multiplies all leaves of a tree, which are numbers. You can do the “left” and “right” computations concurrently. C. Varela21

22 Tree Product Behavior B treeprod = rec(λb.λself.λm. seq(become(b(self)), if(isnat(tree(m)), send(cust(m),tree(m)), letactor{newcust := B joincont (cust(m),0,nil)} seq(send(self, pr(left(tree(m)),newcust)), send(self, pr(right(tree(m)),newcust))) ) C. Varela22

23 Tree Product (continued) B joincont = rec(λb.λcust.λnargs.λfirstnum.λnum. if(eq(nargs,0), become(b(cust,1,num)), seq(become(sink), send(cust,firstnum*num)))) C. Varela23

24 Sample Execution C. Varela24 Cust f(tree,cust) JC Cust JC (a)(b)

25 Sample Execution C. Varela25 Cust JC ’ JC Cust JC firstnum (c) JC ' JC firstnum JC ' Cust firstnum JC (d)

26 Sample Execution C. Varela26 num Cust firstnum Cust JC (e) firstnum * num Cust (f)

27 Operational Semantics for Actor Configurations k = > α is a function mapping actor names (represented as variables) to actor states. µ is a multi-set of messages “en-route.” ρ is a set of receptionists. χ is a set of external actors C. Varela27 ρχρχ

28 Operational Semantics Given A = Dom(α): P is a subset of A, A ∩ χ is empty. If α(a) = (?a ’ ), then a ’ is in A. If a in A, then fv(α(a)) is a subset of A U χ. If in µ, then fv(v 0,v 1 ) is a subset of A U χ. C. Varela28

29 Operational Semantics α in X As As = (?x) U (V) U [E] µ in M w [M] M = ρ,χ in P w [X] V = At U X U λX.E U pr(V,V) E = V U app(E,E) U Fn(E n ) C. Varela29 ├

30 Labeled Transition Relation e e ' > > > > > >> C. Varela30 Dom(α)U{a} ρχρχ ρχρχ ρχρχ ρχρχ (where a’ is fresh) ρχρχ ρχρχ

31 Labeled Transition Relation, µ>> > >> > > >> C. Varela31 ρχρχ ρχρχ ρχρχ ρ'χρ'χ If v 0 is in χ and ρ ' = ρ U (fv(v 1 ) ∩ Dom(α)) ρχρχ ρχ'ρχ' If v 0 is in ρ and fv(v 1 ) ∩ Dom(α) is a subset of ρ and χ ' =χ U (fv(v 1 ) – Dom(α)

32 Computation Sequences and Paths If k is a configuration, then the computation tree T(k) is the set of all finite sequences of labeled transitions [k i k i+1 | i < n ] for some n in the natural numbers with k = k 0. Such sequences are called computation sequences. A computation path from k is a maximal linearly ordered set of computation sequences in the computation tree,T(k). T ∞ (k) denotes the set of all paths from k. C. Varela32 lili

33 A path π = [k i k i+1 | i < ] in the computation tree T ∞ (k) is fair if each enabled transition eventually happens or becomes permanently disabled. For a configuration k we define F(k) to be the subset of T ∞ (k) that are fair. Fairness C. Varela33 lili

34 Composition of Actor Configurations k 0 = > k 1 = > k 0 || k 1 = > Configurations are “composable” if Dom(α 0 ) ∩ Dom(α 1 ) is empty and χ 0 ∩ Dom(α 1 ) is a subset of ρ 1 χ 1 ∩ Dom(α 0 ) is a subset of ρ 0 k 0 = > C. Varela34 ρ0χ0ρ0χ0 ρ1χ1ρ1χ1 ρ 0 U ρ 1 (χ 0 U χ 1 ) – (ρ 0 U ρ 1 ) 0000

35 Composition of Actor Configurations (AC) k 0 || k 1 = k 1 || k 0 k 0 || k = k 0 (k 0 || k 1 ) || k 2 = k 0 || (k 1 || k 2 ) Closed Configurations: A configuration in which both the receptionist and external actor sets are empty is said to be closed Composition preserves computations paths: T(k 0 || k 1 ) = T(k 0 ) || T(k 1 ) F(k 0 || k 1 ) = F(k 0 ) || F(k 1 ) C. Varela35 0

36 Equivalence of Expressions Operational equivalence Testing equivalence Two program expressions are said to be equivalent if they behave the same when placed in any observing context. An observing context is a complete program with a hole, such that all free variables in expressions being evaluated become captured when placed in the hole. C. Varela36 Observational equivalence

37 Events and Observing Contexts A new event primitive operator is introduced. The reduction relation is extended: > > An observing configuration is on of the form: > where C is a hole-containing expression or context. C. Varela37 ρχρχ ρχρχ

38 Observations Let k be a configuration of the extended language and let π = [k i k i+1 | i < ] be a fair path, i.e., π is in F(k). Define: obs(π) = obs(k) = C. Varela38 lili S if there exists a, i F otherwise S if, for all π in F(k), obs(π) = s SF otherwise F if, for all π in F(k), obs(π) = s

39 Three Equivalences The natural equivalence is equal are made in all closing configuration contexts. Other two equivalences (weaker) arise if SF observations are considered as good as S observations; or if SF observations are considered as bad as F observations. 1.Testing or Convex or Plotkin or Egli-Milner e 0 = 1 e 1 iff Obs(O[e 0 ]) = Obs(O[e 1 ]). 1.Must or Upper or Smyth e 0 = 2 e 1 iff Obs(O[e 0 ]) = S Obs(O[e 1 ]) = S. 2.May or Lower or Hoare e 0 = 3 e 1 iff Obs(O[e 0 ]) = F Obs(O[e 1 ]) = F. C. Varela39 ~ ~ ~

40 Congruence e 0 = j e 1 c[e 0 ] = j c[e 1 ] for j = 1,2,3,… By construction, all equivalences defined are congruencies. Partial Collapse C. Varela40 ~~ = 1 S SF F S SF F XX X X X X = 2 S SF F S SF F = 3 S SF F S SF F (1 = 2): e 0 = 1 e 1 iff e 0 = 2 e 1 (due to fairness) (1 => 3): e 0 = 1 e 1 implies e 0 = 3 e 1 ~~ ~~ XX X XX X X X * * e0e0 e1e1


Download ppt "C. Varela1 Chapter 4: Actors Programming Distributed Computing Systems: A Foundational Approach Carlos Varela Rensselaer Polytechnic Institute."

Similar presentations


Ads by Google