distributed systems and algorithms

57
Distributed Systems and Algorithms Sukumar Ghosh University of Iowa Fall 2012

Upload: jody

Post on 23-Mar-2016

36 views

Category:

Documents


0 download

DESCRIPTION

Distributed Systems and Algorithms. Sukumar Ghosh University of Iowa Fall 2012. What is a distributed system ?. What is a distributed system ?. 0. 2. 1. 11. 5. 4. 8. 3. 7. 10. 6. 9. A channel may be physical (wired, wireless) or logical. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Distributed Systems and Algorithms

Distributed Systems and Algorithms

Sukumar GhoshUniversity of Iowa

Fall 2012

Page 2: Distributed Systems and Algorithms

What is a distributed system?

1

Page 3: Distributed Systems and Algorithms

What is a distributed system?

Abstract view: It is a network of processes. (The nodes are processes, and the edges are communication

channels.)

111

2

3

4

5

6

7

8

9

10

1

0

A channel may be physical (wired, wireless) or logical

Page 4: Distributed Systems and Algorithms

Example

2

A record of email communication among 436 employees of one of the Hewlett Packard Research Labs during the completion of a project. It is a

trivial example of a distributed system.

Page 5: Distributed Systems and Algorithms

Facts

Technology has dramatically reduced the cost of processors, so their population is exploding.

User demands for services have increased the scale of systems (Facebook has more than500 million users)

We live in a networked society.

3

Page 6: Distributed Systems and Algorithms

ExamplesLarge networks are very commonplace these days. Think of the world wide web. A few examples of distributed systems are:

- eBay for internet-based auction- Sensor networks- BitTorrent (P2P network) for downloading video / audio- Skype for making free audio and video communication- Facebook (the oxygen of many people)- Process control networks in engineering factories- Computational grids (OSG, Teragrid, SETI@home)- Network of mobile robots collectively doing a job- Distance education, net-meeting etc.- Netbanking- Vehicular networking

4

What are these?

Page 7: Distributed Systems and Algorithms

Sensor Network

The sensor network is checking the structural integrity of the bridge

5

Page 8: Distributed Systems and Algorithms

Mobile robots

I-Swarm Robot(See a video of the I-Swarm Robots on YouTube)

6

The I-Swarm project, consisting of 10 research institutes, is coordinated by Professor Heinz Wörn and Jörg Seyfried of the University of Karsruhe in Germany.

Page 9: Distributed Systems and Algorithms

Goal of a distributed system

The computers coordinate their activities and to share hardware and software and data, so that users perceive it as a single, integrated computing service with a well-defined goal.

7

Downloading music in Bittorrent

Page 10: Distributed Systems and Algorithms

Goal continuedDistributed computing relies on inter-process communication, which involves the various layers of networking. Distributed computing helps create simple abstractions for these layers to facilitate program writing. Examples: (1)TCP implements a reliable end-to-end communication channel,(2) Media Access protocol used in Ethernet LAN or Wireless networks helps resolve network access conflict.

P

Q

Create a reliable channel between P and Q that are

10,000 miles away

8

Page 11: Distributed Systems and Algorithms

Why distributed systems

• Geographic distribution of processes• Resource sharing (example: P2P networks, grids)• Computation speed up (as in a grid or cloud)• Fault tolerance

9

Page 12: Distributed Systems and Algorithms

Important challenges

• Knowledge is local• Clocks are not synchronized• No globally shared address space• Topology and routing : everything is dynamic• Scalability: what is this• Processes and links fail:

Fault tolerance and system availability

11

Page 13: Distributed Systems and Algorithms

Some common subproblems

• Leader election• Mutual exclusion• Time synchronization• Distributed snapshot• Reliable multicast• Replica management• Consensus

12

Page 14: Distributed Systems and Algorithms

Implementation

Most of the practical distributed systems have a real network as its backbone.

However, such systems can also be simulated on a shared-memory multiprocessor, or even on a single processor, or in the cloud.

(How will you do it? Think of simulating multiple processes, and mailboxes between pairs of communicating processes)

13

Page 15: Distributed Systems and Algorithms

ModelsWe will reason about distributed systems using models. There are many dimensions of variability in distributed systems. Examples:

- types of processors- inter-process communication mechanisms- timing assumptions- failure classes - security features, etc

14

Page 16: Distributed Systems and Algorithms

ModelsModels are simple abstractions that help overcome the variability -- abstractions that preserve the essential features, but hide the implementation details and simplify writing distributed algorithms for problem solving

Optical or radio communication?PC or Mac?Are clocks perfectly synchronized?

15

algorithms

models

Real hardware

Implementation of models

Page 17: Distributed Systems and Algorithms

A classification

Client-server modelServer is the coordinator

Peer-to-peer modelNo unique coordinator

Server

Clients

16

Page 18: Distributed Systems and Algorithms

Parallel vs Distributed

In both parallel and distributed systems, the events arepartially ordered. The distinction between parallel and distributed is not always very clear. In parallel systems, the primarily issues are speed-up and increased data handling capability. In distributed systems the primary issues are fault-tolerance, synchronization, scalability etc.

17

Parallel Distributed

Grid P2P

Page 19: Distributed Systems and Algorithms

The Case of Facebook

17

30,000 servers

The new Facebook data center in Prineville, Oregon. The new servers have been redesigned are networked, for energy efficiency, speed-up and for fault-tolerance.

The set up mimics client-server kind of operation, with the servers having a high level of parallelism. However, the network of servers may also be viewed as a distributed system.

user

user

user

Page 20: Distributed Systems and Algorithms

Objective of the course

We will not discuss programming issues here, although you can choose a project and work on it at your own initiative. We will discuss about it soon.

18

With some knowledge in networking, it is not difficult to put together a distributed system. It is however, much more difficult guarantee that it behaves the way we want it to behave. Remember that a system that “sometimes work” is no good. Wewill study what are the critical issues, why a system fails, and howWe can guarantee our design.

Page 21: Distributed Systems and Algorithms

Understanding Models and abstractions

Page 22: Distributed Systems and Algorithms

How models help

algorithms

models

Real hardware

Implementation of models

Page 23: Distributed Systems and Algorithms

Message passing vs. shared memory

Page 24: Distributed Systems and Algorithms

Modeling Communication

System topology is a graph G = (V, E), where V = set of nodes (sequential processes) E = set of edges (links or channels, bi/unidirectional).

Four types of actions by a process:

- internal action

- input action

- communication action

- output action

Page 25: Distributed Systems and Algorithms

Example: A Message Passing Model

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 26: Distributed Systems and Algorithms

Life of a process

When a message m arrives

1. Receive it

2. Evaluate a predicate (with message m and the local variables);

3. if predicate = true then

update zero or more internal variables;

send zero or more messages;

end if

A B

C D

E

m

Page 27: Distributed Systems and Algorithms

Example: Shared memory model

Address spaces of processes overlap

M1

1 32

4

M2

Concurrent operations on a shared variable are serialized

Processes

Page 28: Distributed Systems and Algorithms

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 29: Distributed Systems and Algorithms

What is the difference between a synchronous distributed system and an

asynchronous distributed system?

Page 30: Distributed Systems and Algorithms

Synchrony vs. Asynchrony

Send & receive can be blocking or non-blocking

Postal communication is asynchronous:

Telephone communication is synchronous

Synchronous communication or not?

(1) Remote Procedure Call,(2) Email

Synchronous clocks

Physical clocks are synchronized

Synchronous processes

Lock-step synchrony

Synchronous channels

Bounded delay

Synchronous message-order

First-in first-out channels

Synchronous communication

Communication via handshaking

Any constraint defines some form of synchrony …

Page 31: Distributed Systems and Algorithms

Modeling wireless networks• Communication via broadcast• Limited range• Dynamic topology• Collision of broadcasts

(handled by CSMA/CA)

0

1

2

3

4

5

6

0

1

2

3

4

5

6

(a)

(b)

RTS RTS

CTS

Request To Send

Request To SendClear To Send

Page 32: Distributed Systems and Algorithms

Weak vs. Strong Models

One object (or operation) of a strong model = More than one simpler objects (or simpler 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.

Examples

High level language is stronger than assembly language.

Asynchronous is weaker than synchronous (communication).

Bounded delay is stronger than unbounded delay (channel)

Page 33: Distributed Systems and Algorithms

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 exercisesNon-FIFO to FIFO channelMessage passing to shared memoryNon-atomic broadcast to atomic broadcast

Page 34: Distributed Systems and Algorithms

Non-FIFO to FIFO channel

P Q

buffer

m1m4m3m2

1234567

FIFO = First-In-First-Out

Sends out m1, m2, m3, m4, …

Page 35: Distributed Systems and Algorithms

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];

Needs unbounded buffer buffer [k] := empty; k := k+1;& unbounded sequence no end

THIS IS BAD forever

Page 36: Distributed Systems and Algorithms

ObservationsNow 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. (Lesson) Stronger model helps.

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

Page 37: Distributed Systems and Algorithms

Example1 second window

Last message

First message

sender

receiver

Page 38: Distributed Systems and Algorithms

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.

Atomic = all or nothing

This is incomplete and stillnot correct. There are more pitfalls here.

Page 39: Distributed Systems and Algorithms

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?

How to implement atomic broadcast in presence of crash?

Page 40: Distributed Systems and Algorithms

Mobile-agent based communication

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

What isthe lowestPrice of aniPad in Iowa?

Carries bothprogram and data

Best Buy

Cedar RapidsUniversityof Iowa

Page 41: Distributed Systems and Algorithms

Other classifications of modelsReactive 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 system (Examples?)

Named 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. Saves

log N bits.

Page 42: Distributed Systems and Algorithms

Knowledge based communication

Alice and Bob enter into an agreement: whenever one falls sick, (s)he will call the other person. Since making the agreement, no one called the other person, so both concluded that they are in good health. Assume that the clocks are synchronized, communication links are perfect, and a telephone call requires zero time to reach.

What kind of interprocess communication model is this?

Page 43: Distributed Systems and Algorithms

History

The paper “Cheating Husbands and Other Stories: A Case Study of Knowledge,

Action, and Communication” by Yoram Moses, Danny Dolev, Joseph Halpern

(PODC 1985) illustrates how actions are taken and decisions are made without

explicit communication using common knowledge. (Adaptation of Gamow and

Stern, “Forty unfaithful wives,” Puzzle Math, 1958)

(Bidding in the game of cards like bridge is an example of knowledge-based

communication)

Page 44: Distributed Systems and Algorithms

Observations

Knowledge-based communication relies on making

deductions from the absence of a signal or actions.

Page 45: Distributed Systems and Algorithms

Cheating Husband’s puzzle:

In a matriarchal town, the Queen read out the following in a meeting at

the town square.

①There are one or more unfaithful husbands in our community.

②None of you know whether your husband is faithful. But each of you

which of the other husbands are unfaithful.

③Do not discuss this with anyone, but should you discover that your own

husband is unfaithful, you should shoot him on the midnight of the day

you find out about it.

Page 46: Distributed Systems and Algorithms

What happened after this

Thirty nine silent nights went by, and on the

fortieth night, gunshots were heard.

• What was going on for 39 nights?

• How many unfaithful husbands were there?

• Why did it take so long?

Page 47: Distributed Systems and Algorithms

A simple case

• W2 does not know of any other unfaithful husband.

• W2 knows that there is at least one (common knowledge)

• W2 concludes that it must be H2, and kills him on the first night.

W1 H1W2 H2W3 H3W4 H4

Page 48: Distributed Systems and Algorithms

Theorem

If there are N unfaithful H’s, then they will all be killed on the midnight of the Nth day.

If you are interested to learn more, then read the original paper.

Page 49: Distributed Systems and Algorithms

The Complexity of Distributed Algorithms

Page 50: Distributed Systems and Algorithms

Common measuresSpace complexityHow much space is needed per process to run an algorithm?(measured in terms of N, the size of the network)

Time complexityWhat is the max. time (number of steps) needed to complete theexecution of the algorithm?

Message complexityHow many message are exchanged to complete the execution of the

algorithm?

Page 51: Distributed Systems and Algorithms

Other measuresBit complexityMeasures how many bits are transmitted when the algorithm runs. It

may be a better measure, since messages may be of arbitrary size.

LOCAL and CONGEST models(LOCAL) In unit time, each process can send a message of arbitrarily

large size to its neighbors. This ignores link congestion.(CONGEST) In unit time, a process can send a message of size up to

O(log n) bits to each of its neighbors

(These are variations of the synchronous message passing models)

Page 52: Distributed Systems and Algorithms

An exampleConsider initializing the values of a variable x at the nodes of an n-cube. Process 0 is the leader, broadcasting a value v to initialize the cube. Here n=3 and N = total number of processes = 2n = 8

source

Each process j > 0 has a variable x[j], whose initial value is arbitrary.

Finally, x[0] = x[1] = x[2] = … = x[7] = v

Page 53: Distributed Systems and Algorithms

Broadcasting using message passing

{Process 0} m.value := x[0]; send m to all neighbors

{Process i > 0}repeat receive m {m contains the value}; if m is received for the first time then x[i] := m.value; send x[i] to each neighbor j > I else discard m end ifforever

What is the (1) message complexity(2) space complexity per process?

0 1

23

4

5

67

m

m

m

Number of edgeslog2N

Page 54: Distributed Systems and Algorithms

Broadcasting using shared memory

{Process 0} x[0] := v{Process i > 0}repeat

if there exists a neighbor j < i : x[i] ≠ x[j] then x[i] := x[j] (PULL DATA){this is a step} else skip end if

forever

What is the time complexity?(i.e. how many steps are needed?)

0 1

23

4

5

67

Arbitrarily large. Why?

Page 55: Distributed Systems and Algorithms

Broadcasting using shared memory

{Process 0} x[0] := v{Process i > 0}repeat

if there exists a neighbor j < i : x[i] ≠ x[j] then x[i] := x[j] (PULL DATA){this is a step} else skip

end ifforever

0 1

23

4

5

67

15

10

12

27

99 32

1453

Node 7 can keep copying from 5, 6, 4 indefinitely long before the value in node 0is eventually copied into it.

Page 56: Distributed Systems and Algorithms

Broadcasting using shared memory

Now, use “large atomicity”, where

in one step, a process j reads the state x[k]

of each neighbor k < j, and updates x[j]

only when these are equal, but

different from x[j].

What is the time complexity? How many steps are needed?

Time complexity is now O(n3) = O(log2N)3

(n = dimension of the cube)

0 1

23

4

5

67

Why?

Page 57: Distributed Systems and Algorithms

Time complexity in rounds

Rounds are truly defined for synchronous

systems. An asynchronous round consists

of a number of steps where every eligible

process (including the slowest one)

takes at least one step. How many rounds

will you need to complete the broadcast

using the large atomicity model?0 1

23

4

5

67

An easier way to measure complexity in rounds is to assume that processes executing their steps in lock-step synchrony