Coordination Models and Languages

28
Coordination Models and Languages Part I: Coordination Languages and Linda Part II: Technologies based on Tuple space concept beyond Linda Part III: Comparison of coordination languages. Conclusions.

description

Coordination Models and Languages. Part I: Coordination Languages and Linda Part II: Technologies based on Tuple space concept beyond Linda Part III: Comparison of coordination languages. Conclusions. Coordination Languages and Linda. Natalya Abraham CS854. Problem. - PowerPoint PPT Presentation

Transcript of Coordination Models and Languages

Page 1: Coordination Models and Languages

Coordination Models and Languages

Part I: Coordination Languages and Linda

Part II: Technologies based on Tuple space concept beyond Linda

Part III: Comparison of coordination languages. Conclusions.

Page 2: Coordination Models and Languages

Coordination Languages and Linda

Natalya Abraham

CS854

Page 3: Coordination Models and Languages

Problem

In concurrent and distributed programming:

• We prefer to look at each component as a black box.

• We need a mechanism for controlling interactions between the components.

Page 4: Coordination Models and Languages

Candidate technologies:

• Concurrent OOP

• Concurrent logic programming

• Functional programming

Page 5: Coordination Models and Languages

Concurrent Object Oriented Programming: Limitations

• Based on message-passing

• The process structure - the number of processes and their relationships - determines the program structure.

Concurrent Logic Programming: Limitations

• Too policy-laden and inflexible to serve as a good basis for most parallel programs.

Functional Programming: Limitations

• Fail to provide the expressivity we need

• Gains nothing in terms of machine independence

Page 6: Coordination Models and Languages

The way out - Coordination

“Coordination is managing dependencies between activities.”

(From Coordination Theory)

“Coordination is the process of building programs by gluing together active pieces.”

(Carriero and Gelernter, Linda creators)

Page 7: Coordination Models and Languages

Programming = Computation + Coordination

(Carriero and Gelernter, Linda creators)

Page 8: Coordination Models and Languages

In programming coordination is expressed by:• Coordination models Triple (E, L, M)E – entities being coordinated (agents, processes, tuples)L – media used to coordinate the entities (channels, shared variables, tuple spaces)M – semantic framework of the model (guards, synchr. constraints)

• Coordination languages“The Linguistic embodiment of a coordination

model”

Page 9: Coordination Models and Languages

Coordination Languages must support:

• Separation between computation and coordination.

• Distribution (decentralization)• Dynamics(no need to link the activities before runtime)

• Interoperability

• Encapsulation (implementation details are hidden from other components)

Page 10: Coordination Models and Languages

Leading coordination models and languages

• Tuple Space Model (coordination through Shared Data Space)

Linda, TSpaces, JavaSpaces, Jini

• IWIM (coordination through channels)

Manifold

Page 11: Coordination Models and Languages

Tuple spaces and Linda

• Based on generative communication:

Processes communicate by inserting or retrieving data objects (called Tuples) from shared Data Space ( called Tuple space)

• Interoperability is achieved: Linda places no constraints on the underlying language or platform

Page 12: Coordination Models and Languages

Tuple Space Concept

P

P

P

Eval()

Out()

In/Rd()

Tuple

Tuple Space

Page 13: Coordination Models and Languages

Tuple space operations• Tuple is a series of typed fields.Example: (“a string”, 15.01, 17) (10)

• Operationsout (t) insert a tuple t into the Tuple space (non-blocking)in(t) find and remove a “matching” tuple from the tuple space; block until a matching tuple is foundrd(t) like in(t) except that the tuple is not removedeval(t) add the active tuple t to the tuple space

The model is structurally recursive: a tuple space can be one field of a tuple.

Page 14: Coordination Models and Languages

Tuple matchingLet t(i) denote the ith field in the tuple t.A tuple t given in a in(t) or rd(t) operation “matches” a tuple t’ in

the tuple space iff:1. t and t’ have the same number of fields, and2. for each field if t(i) is a value then t(i) = t’(i) or if t(i) is of the form ?x then t’(i) is a valid value for the type of variable xIf more than one tuple in the tuple space matches, then one is

selected nondeterministically.

As a result of tuple matching if t(i) is of the form ?x, then x := t’(i)

Page 15: Coordination Models and Languages

Example of Tuple matching

N-element vector stored as n tuples in the Tuple space:

(“V”, 1, FirstElt)

(“V”, 2, SecondElt)…

(“V”, n, NthElt)

To read the jth element and assign it to x, use

rd ( “V”, j, ?x )

To change the ith element, use

in (“V”, i, ?OldVal) // Note: It is impossible to update a tuple without

out (“V”, I, NewVal); // delete/add

Page 16: Coordination Models and Languages

Example 1: Sending and Receiving messages

Page 17: Coordination Models and Languages

Sending and Receiving messages (Cont.)

Manifold:

p.out-> q.in

Linda:channel (p, out, q, in){ while (1) { in (p, out, Index, Data) out (p, in, Index, Data); }}

Page 18: Coordination Models and Languages

Sending and Receiving messages (Cont.)

• Message-passing model contains tree separate parts:

1. Tag (message Id)2. Target 3. Communication

• In Linda, Tuple is a set of fields, any of which may be a tag (message Id) or target (address) or communication (data).

Page 19: Coordination Models and Languages

Sending and Receiving messages (Cont.)

• In message-passing model a process and a message are separate structures.

• In Linda, a process becomes a tuple.

Page 20: Coordination Models and Languages

Example 2: Semaphores

• Semaphores

Initialize: out(“sem”)

wait or P-operation: in(“sem”)

signal or V-operation: out(“sem”)

For counting semaphore execute out(“sem”) n times

Page 21: Coordination Models and Languages

Example 3: LoopTurn a conventional loop into a parallel loop – all

instances of <something> execute simultaneously.for <loop control> <something>

In Linda:for <loop control> // creates many processes to execute eval(“this loop”, something( )); // the loop in parallel

for <loop control> // Forces all executions to be complete in(“this loop”, 1); // before proceeding

Where something( ) – function, returns 1

Page 22: Coordination Models and Languages

Example 4: Masters and Workers• Master divides work into discrete tasks and puts

into global space (tuple space)

• Workers retrieve tasks, execute, and put results back into global space

• Workers notified of work completion by having met some condition

• Master gatherers results from global space

Page 23: Coordination Models and Languages

Masters and Workers (Cont.)master() {

for all tasks {

…/* build task structure*/

out (“task”, task_structure); }

for all tasks {

in (“result”, ? &task_id, ? &result_structure); }

}

worker() {

while (inp (“task”, ? &task_structure) {

…/* exec task */

out (“result”, task_id, result_structure); }

}

Page 24: Coordination Models and Languages

Example 5: Barrier Synchronization Each process within some group must wait at a barrier until

all processes in the group have reached the barrier; then all can proceed.

• Set up barrier:

out (“barrier”, n);

• Each process does the following:

in(“barrier”, ? val);

out(“barrier”, val-1);

rd(“barrier”, 0).

Page 25: Coordination Models and Languages

Example 6: Dining Philosophers Problem

phil(i) int i;{ while (1) { think(); in (“room ticket”); in (“chopstick”, i) in (“chopstick”, (i+1)% Num); eat (); out (“chopstick”, i); out(“chopstick”, (i+1)%Num); out (“room ticket”); }}

initialize()

{

int i;

for (i=0; i< Num; i++){

out (“chopstick”, i);

eval ( phil(i) );

if (i< (Num-1))

out(“room ticket”);

}

}

Page 26: Coordination Models and Languages

Example 7: Client-Server

server()

{

int index = 1;

while (1){

in (“request”, index, ? req)

out (“response”, index++, response);

}

}

client(){ int index; … in (“server index”,? index); out (“server index”, index +1); … out (“server”, index, request); in (“response”, index, ? response); …}

Page 27: Coordination Models and Languages

Linda achieves:• Nondetermenism• Structured naming. Similar to “select” in relational

DB, pattern matching in AI. in(P, i:integer, j:boolean)

in(P, 2, j:boolean)

• Time uncoupling (Communication between time-disjoint processes)

• Distributed sharing (Variables shared between disjoint processes)

Page 28: Coordination Models and Languages

Linda: Limitations

• The language is although intuitive, but minimal

• Security (no encapsulation)

• New problems: How is the tuple space to be implemented in the absence of shared memory?

• Linda is not fault-tolerant

- Processes are assumed not to fail

- If process fails, it tuples can be lost

- Reading operation is bloking, without timeout