41
CSE 812

CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Embed Size (px)

Citation preview

Page 1: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

CSE 812

Page 2: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Outline

• What is a distributed system/program?

• Program Models

• Program transformation

Page 3: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

What is a distributed system?

A network of processes. The nodes are processes, and the edges are communicationchannels

Page 4: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Code for Distributed Systems

• Each node would need some code.– CSE 231?

• Communication between nodes– Network level issues– CSE 824

• Protocols/Programs for allowing this system to function– This course– Focus on abstract protocols (in my presentations)– Focus on implementation issues (Student

presentations)

Page 5: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Important issues

• Knowledge is local

• Clocks are not synchronized

• No shared address space

•Most of the time

• Topology and routing

• Scalability

• Fault tolerance

Page 6: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Some common subproblems

• Leader election

• Mutual exclusion

• Time synchronization

• Distributed snapshot

• Replica management

Page 7: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

A classification

Client-server model Peer-to-peer model:

Notion of neighbors

Server

Clients

Page 8: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Outline

• What is a distributed system/program?

• Program Models

• Program transformation

Page 9: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Defining Programs

• Goal of this discussion is to extend the concept of programs from programs such as that in C/C++/… to more abstract programs

• Consider the map of MSU shown on the next page.

• A robot needs to be programmed so that it can go from point A to point B– Identify a program for such robot

Page 10: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

A

B

Page 11: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

A

B

Page 12: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Issues

• Non determinism – At a certain state, the program is presented

from a set of multiple options. – Assumption: the program may choose

either of these options non-deterministically.

• Note that this does not imply any fairness unless assumed otherwise.

Page 13: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Abstraction

• Thinking of the program as a finite automata

Page 14: CSE 812. Outline What is a distributed system/program? Program Models Program transformation
Page 15: CSE 812. Outline What is a distributed system/program? Program Models Program transformation
Page 16: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Defining Safety

• Example:– Consider the arrows in previous picture

• Intuitively, safety identifies transitions that should not be executed by the program

Page 17: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Example 2

• Peterson’s mutual exclusion algorithm– Two processes

• State can be n (non critical), t (trying), or c (critical)

• It is necessary to ensure that both processes are not in state c simultaneously

• If a process is in state t, then it must eventually go to state c

• When a process in state n (respectively, t, c) changes its state, it must change it to t (respectively, c, n)

– Additional variable turn

Page 18: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Automata for Peterson’s Mutual Exclusion

n1,n2

t1,n2 n1,t2

c1,n2 n1,c2t1,t2

turn=1

t1,t2

turn=2

c1,t2 t1,c2

Page 19: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Safety

• Examples– [c1, c2] not reached– ([n1, n2], [c1, n2]) is not permitted

Page 20: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Example 3

• Car climate control– Driver side temperature– Passenger side temperature– Controls for increasing and decreasing

temperature– A button for `Sync’– Minimum and maximum temperature

Page 21: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Automata for Car Climate Control

Page 22: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Use of Invariants

• Sync ==> d_temp = p_temp

• d_temp >= min

• p_temp >= min

• d_temp <= max

• p_temp <= max

Page 23: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Stepping back

• Overview of different program models– Message passing model– Shared memory model

• Different semantics

Page 24: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Why do we need models?

There are many dimensions of variability in distributed systems. Examples:

- interprocess communication mechanisms, - failure classes, - security mechanisms etc.

Page 25: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Why do we need models?

Models are simple abstractions that help understand the variability -- abstractions that preserve the essential features, but hide the implementation details from observers who view the system at a higher level.

For example C program is an abstraction of the assembly program that preserves certain properties

Page 26: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

A message passing model

System topology is a graph G = (V, E), where

V = set of nodes (sequential processes)

E = set of edges

Four types of actions by a process:

- Internal action -input action

- Communication action -output action

Page 27: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

A Reliable FIFO channel

Axiom 1. Message m sent message m received

Axiom 2. Message propagation delay is arbitrary but finite.

Axiom 3. m1 sent before m2 m1 received before m2.

P

Q

Page 28: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Life of a process in message passing model

When a message m is rec’d

1. Evaluate a predicate with m

and the local variables;

2. if predicate = true then

-update internal variables;

-send zero or more

messages;

else skip {do nothing}

end if

Page 29: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Shared memory model

Address spaces of processes overlap

M1

1 32

4

M2

Concurrent operations on a shared variable are serialized

Page 30: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Variations of shared memory models

0

3

21 State reading model

Each process can read

the states of its neighbors

0

3

21Link register model

Each process can read from

and write to adjacent

registers. The entire local

state is not shared.

Page 31: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Weak vs. Strong Models

One object (or operation) of a strong model = More than one objects (or operations) of a weaker model.

Often, weaker models are synonymous with fewer restrictions.

One can add layers (additional restrictions) to create a stronger model from weaker one.

ExamplesHLL model is stronger

than assembly language model.

Asynchronous is weaker than synchronous.

Bounded delay is stronger than unbounded delay (channel)

Page 32: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Model transformation

Stronger models

- simplify reasoning, but

- needs extra work to implement

Weaker models

- are easier to implement.

- Have a closer relationship with the real world

“Can model X be implemented using model Y?” is an interesting question in computer science.

Sample problems

Non-FIFO to FIFO channel

Message passing to shared memory

Non-atomic broadcast to atomic broadcast

Page 33: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Non-FIFO to FIFO channel

P Q

buffer

m1m4m3m2

Page 34: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Non-FIFO to FIFO channel

{Sender process P} {Receiver process Q}var i : integer {initially 0} var k : integer {initially 0}

buffer: buffer[0..∞] of msg {initially k: buffer [k] = empty

repeat repeat send m[i],i to Q; {STORE} receive m[i],i from P; i := i+1 store m[i] into buffer[i];

forever {DELIVER} while buffer[k] ≠ empty do begin

deliver content of buffer [k]; buffer [k] := empty k :=

k+1; endforever

Page 35: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Observations

(a) Needs Unbounded sequence numbers and (b) Unbounded number of buffer slots (Both are bad)

Now solve the same problem on a model where (a) The propagation delay has a known upper bound of T.(b) The messages are sent out @r per unit time.(c) The messages are received at a rate faster than r.

The buffer requirement drops to r.T. Synchrony pays.

Question. How to solve the problem using bounded buffer space if the propagation delay is arbitrarily large?

Page 36: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Message-passing to Shared memory

{Read X by process i}: read x[i]

{Write X:= v by process i}- x[i] := v;- Atomically broadcast v to

every other process j (j ≠ i);- After receiving broadcast,

process j (j ≠ i) sets x[j] to v.

Understand the significance of atomic operations. It is not trivial, but is very important in distributed systems

0 1 2 3

X

processes

memory

x[0]

x[1]

x[2]

x[3]

(a) (b)

This is incomplete. There aremore pitfalls here.

Page 37: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Non-atomic to atomic broadcast

Atomic broadcast = either everybody or nobody receives

{process i is the sender}for j = 1 to N-1 (j ≠ i) send message m to neighbor[j] (Easy!)

Now include crash failure as a part of our model. What if the sender crashes at the middle? Implement atomic broadcast in presence of crash.

Page 38: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Mobile-agent based communication

Communicates via messengers instead of (or in addition to) messages.

What is the lowestPrice of aniPod in Michigan?

Carries bothprogram and data

Page 39: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

June 20, 2007 ProSe: Programming Tool for Sensor Networks;

41

Computational Model in Sensor Networks

• More generally in wireless networks– Communication pattern is local broadcast

• However, if multiple nodes broadcast simultaneously then a collision may occur

Page 40: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Write-All with Collision Model

• Thus, communication in sensor networks is local broadcast with collision

• In one action,– A sensor can (1) write its own state and (2) the

state of all its neighbors at once– However, simultaneous execution of 2 or more

sensors may cause the state of the common neighbors to remain unchanged

• Can we convert a program in shared memory to write-all with collision model?– Why?

Page 41: CSE 812. Outline What is a distributed system/program? Program Models Program transformation

Other classifications of models

Reactive vs Transformational systemsA reactive system never sleeps (like: a server)A transformational (or non-reactive systems) reaches a fixed

point after which no further change occurs in the systemNamed vs Anonymous systemsIn named systems, process id is a part of the algorithm. In anonymous systems, it is not so. All are equal.

(-) Symmetry breaking is often a challenge.(+) Easy to switch one process by another with no side effect.