Distributed Systems Basic Algorithms Rik Sarkar James - - PowerPoint PPT Presentation

distributed systems basic algorithms
SMART_READER_LITE
LIVE PREVIEW

Distributed Systems Basic Algorithms Rik Sarkar James - - PowerPoint PPT Presentation

Distributed Systems Basic Algorithms Rik Sarkar James Cheney University of Edinburgh Spring 2014 Network as a graph Network is a graph :


slide-1
SLIDE 1

Distributed ¡Systems ¡ ¡ Basic ¡Algorithms ¡

Rik ¡Sarkar ¡ James ¡Cheney ¡ ¡ University ¡of ¡Edinburgh ¡ Spring ¡2014 ¡

slide-2
SLIDE 2

Network ¡as ¡a ¡graph ¡

  • Network ¡is ¡a ¡graph ¡: ¡G ¡= ¡(V,E) ¡
  • Each ¡vertex/node ¡is ¡a ¡computer/process ¡
  • Each ¡edge ¡is ¡communicaOon ¡link ¡between ¡2 ¡nodes ¡
  • Every ¡node ¡has ¡a ¡Unique ¡idenOfier ¡known ¡to ¡itself. ¡ ¡

– OTen ¡used ¡1, ¡2, ¡3, ¡… ¡n ¡

  • Every ¡node ¡knows ¡its ¡neighbors ¡– ¡the ¡nodes ¡it ¡can ¡

reach ¡directly ¡without ¡needing ¡other ¡nodes ¡to ¡route ¡

– Edges ¡incident ¡on ¡the ¡vertex ¡ – For ¡example, ¡in ¡LAN ¡or ¡WLAN, ¡through ¡listening ¡to ¡the ¡ broadcast ¡medium ¡ – Or ¡by ¡explicitly ¡asking: ¡Everyone ¡that ¡receives ¡this ¡ message, ¡please ¡report ¡back ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 2 ¡

slide-3
SLIDE 3

Network ¡as ¡a ¡graph ¡

  • Distance/cost ¡between ¡nodes ¡p ¡and ¡q ¡in ¡the ¡

network ¡

– Number ¡of ¡edges ¡on ¡the ¡shortest ¡path ¡between ¡p ¡and ¡ q ¡(when ¡all ¡edges ¡are ¡same: ¡unweighted) ¡

  • SomeOmes, ¡edges ¡can ¡be ¡weighted ¡

– Each ¡edge ¡e ¡= ¡(a,b) ¡has ¡a ¡weight ¡w(e) ¡ – w(e) ¡is ¡the ¡cost ¡of ¡using ¡the ¡communicaOon ¡link ¡e ¡ (may ¡be ¡length ¡e) ¡ – Distance/cost ¡between ¡p ¡and ¡q ¡is ¡total ¡weight ¡of ¡ edges ¡on ¡the ¡path ¡from ¡p ¡to ¡q ¡ ¡with ¡least ¡weight ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 3 ¡

slide-4
SLIDE 4

Network ¡as ¡a ¡graph ¡

  • Diameter ¡

– The ¡maximum ¡distance ¡between ¡2 ¡nodes ¡in ¡the ¡ network ¡

  • Radius ¡

– Half ¡the ¡diameter ¡

  • Spanning ¡tree ¡of ¡a ¡graph: ¡

– A ¡subgraph ¡which ¡is ¡a ¡tree, ¡and ¡reaches ¡all ¡nodes ¡of ¡ the ¡graph ¡ – How ¡many ¡edges ¡does ¡a ¡spanning ¡tree ¡have? ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 4 ¡

slide-5
SLIDE 5

Size ¡of ¡ids ¡

  • In ¡a ¡network ¡of ¡n ¡nodes ¡
  • Each ¡node ¡id ¡needs ¡Θ(log ¡n) ¡(that ¡is, ¡both ¡

O(log ¡n) ¡and ¡Ω(log ¡n)) ¡bits ¡for ¡storage ¡

– The ¡binary ¡representaOon ¡of ¡n ¡needs ¡log2 ¡n ¡bits ¡

  • Ω ¡– ¡since ¡we ¡need ¡at ¡least ¡this ¡many ¡bits ¡

– May ¡vary ¡by ¡constant ¡factors ¡depending ¡on ¡base ¡

  • f ¡logarithm ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 5 ¡

slide-6
SLIDE 6

Global ¡Message ¡broadcast ¡

  • Message ¡must ¡reach ¡all ¡nodes ¡in ¡the ¡network ¡

– Different ¡from ¡broadcast ¡transmission ¡in ¡LAN ¡ – All ¡nodes ¡in ¡a ¡large ¡network ¡cannot ¡be ¡reached ¡ with ¡single ¡transmissions ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 6 ¡

Source ¡

slide-7
SLIDE 7

Global ¡Message ¡broadcast ¡

  • Message ¡must ¡reach ¡all ¡nodes ¡in ¡the ¡network ¡

– Different ¡from ¡broadcast ¡transmission ¡in ¡LAN ¡ – All ¡nodes ¡in ¡a ¡large ¡network ¡cannot ¡be ¡reached ¡ with ¡single ¡transmissions ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 7 ¡

Source ¡

slide-8
SLIDE 8

Flooding ¡for ¡Broadcast ¡

  • The ¡source ¡sends ¡a ¡Flood ¡message ¡to ¡all ¡

neighbors ¡

  • The ¡message ¡has ¡

– Flood ¡type ¡ – Unique ¡id: ¡(source ¡id, ¡message ¡seq) ¡ – Data ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 8 ¡

slide-9
SLIDE 9

Flooding ¡for ¡Broadcast ¡

  • The ¡source ¡sends ¡a ¡Flood ¡message, ¡with ¡a ¡

unique ¡message ¡id ¡to ¡all ¡neighbors ¡

  • Every ¡node ¡p ¡that ¡receives ¡a ¡flood ¡message ¡m, ¡

does ¡the ¡following: ¡

– If ¡m.id ¡was ¡seen ¡before, ¡discard ¡m ¡ – Otherwise, ¡Add ¡m.id ¡to ¡list ¡of ¡previously ¡seen ¡ messages ¡and ¡send ¡m ¡to ¡all ¡neighbors ¡of ¡p ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 9 ¡

slide-10
SLIDE 10

Flooding ¡form ¡broadcast ¡ ¡

  • Storage ¡

– Each ¡node ¡needs ¡to ¡store ¡a ¡list ¡of ¡flood ¡ids ¡seen ¡ before ¡ – If ¡a ¡protocol ¡requires ¡x ¡floods, ¡then ¡each ¡node ¡ must ¡store ¡x ¡ids ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 10 ¡

slide-11
SLIDE 11

Flooding ¡form ¡broadcast ¡ ¡

  • Storage ¡

– Each ¡node ¡needs ¡to ¡store ¡a ¡list ¡of ¡flood ¡ids ¡seen ¡ before ¡ – If ¡a ¡protocol ¡requires ¡x ¡floods, ¡then ¡each ¡node ¡ must ¡store ¡x ¡ids ¡ – Requires ¡Ω(x) ¡storage ¡ – (Actual ¡storage ¡depends ¡on ¡size ¡of ¡m.id) ¡ ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 11 ¡

slide-12
SLIDE 12

AssumpOons ¡

  • We ¡are ¡assuming: ¡

– Nodes ¡are ¡working ¡in ¡synchronous ¡communicaDon ¡ rounds ¡ – Messages ¡from ¡all ¡neighbors ¡arrive ¡at ¡the ¡same ¡ Ome, ¡and ¡processed ¡together ¡ – In ¡each ¡round, ¡each ¡node ¡can ¡successfully ¡send ¡1 ¡ message ¡to ¡all ¡its ¡neighbors ¡ – Any ¡necessary ¡computaOon ¡can ¡be ¡completed ¡ before ¡the ¡next ¡round ¡ ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 12 ¡

slide-13
SLIDE 13

CommunicaOon ¡complexity ¡

  • The ¡the ¡message/communicaOon ¡complexity ¡

is: ¡

– O(|E|) ¡ ¡ – E ¡is ¡set ¡of ¡communicaOon ¡edges ¡in ¡the ¡network. ¡ – |E| ¡is ¡the ¡number ¡of ¡communicaOon ¡edges ¡

  • Since ¡each ¡node ¡sends ¡the ¡message ¡to ¡each ¡

neighbor ¡exactly ¡once ¡

– The ¡actual ¡number ¡of ¡messages ¡is ¡2|E| ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 13 ¡

slide-14
SLIDE 14

Reducing ¡CommunicaOon ¡ ¡ complexity ¡(slightly) ¡

  • Node ¡p ¡need ¡not ¡send ¡message ¡m ¡to ¡any ¡node ¡

from ¡which ¡it ¡has ¡already ¡received ¡m ¡

– Needs ¡to ¡keep ¡track ¡of ¡which ¡nodes ¡have ¡sent ¡the ¡ message ¡ – Saves ¡some ¡messages ¡ – Does ¡not ¡change ¡asymptoOc ¡complexity ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 14 ¡

slide-15
SLIDE 15

Time ¡complexity ¡

  • The ¡number ¡of ¡rounds ¡needed ¡to ¡reach ¡all ¡

nodes: ¡diameter ¡of ¡G ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 15 ¡

slide-16
SLIDE 16

BFS ¡Tree ¡

  • Breadth ¡first ¡search ¡tree ¡

– Every ¡node ¡has ¡a ¡parent ¡pointer ¡ – And ¡zero ¡or ¡more ¡child ¡pointers ¡ – BFS ¡Tree ¡construcOon ¡algorithm ¡sets ¡these ¡ pointers ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 16 ¡

slide-17
SLIDE 17

BFS ¡Tree ¡ConstrucOon ¡algorithm ¡

  • Breadth ¡first ¡search ¡tree ¡

– The ¡root(source) ¡node ¡decides ¡to ¡construct ¡a ¡tree ¡ – Uses ¡flooding ¡to ¡construct ¡a ¡tree ¡ – Every ¡node ¡p ¡on ¡gekng ¡the ¡message ¡forwards ¡to ¡all ¡ neighbors ¡ – AddiOonally, ¡every ¡node ¡p ¡stores ¡parent ¡pointer: ¡node ¡ from ¡which ¡it ¡first ¡received ¡the ¡message ¡

  • If ¡mulOple ¡neighbors ¡had ¡first ¡sent ¡p ¡the ¡message ¡in ¡the ¡

same ¡round, ¡choose ¡parent ¡arbitrarily. ¡E.g. ¡node ¡with ¡ smallest ¡id ¡

– p ¡informs ¡its ¡parent ¡of ¡the ¡selecOon ¡

  • Parent ¡creates ¡a ¡child ¡pointer ¡to ¡p ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 17 ¡

slide-18
SLIDE 18

Time ¡& ¡message ¡complexity ¡

  • AsymptoOcally ¡Same ¡as ¡Flooding ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 18 ¡

root ¡

slide-19
SLIDE 19

Tree ¡based ¡broadcast ¡

  • Send ¡message ¡to ¡all ¡nodes ¡

using ¡tree ¡

– BFS ¡tree ¡is ¡a ¡spanning ¡tree: ¡ connects ¡all ¡nodes ¡

  • Flooding ¡on ¡the ¡tree ¡
  • Receive ¡message ¡from ¡

parent, ¡send ¡to ¡children ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 19 ¡

root ¡

slide-20
SLIDE 20

Tree ¡based ¡broadcast ¡

  • Simpler ¡than ¡flooding: ¡send ¡message ¡to ¡all ¡

children ¡

  • CommunicaOon: ¡Number ¡of ¡edges ¡in ¡spanning ¡

tree: ¡n-­‑1 ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 20 ¡

slide-21
SLIDE 21

AggregaOon ¡

  • Without ¡the ¡tree ¡
  • Flood ¡from ¡all ¡nodes: ¡

– O(|E|) ¡cost ¡per ¡node ¡ – O(n*|E|) ¡total ¡cost: ¡expensive ¡ – Each ¡node ¡needs ¡to ¡store ¡flood ¡ids ¡from ¡n ¡nodes ¡

  • Requires ¡Ω(n) ¡storage ¡at ¡each ¡node ¡

– Good ¡fault ¡tolerance ¡

  • If ¡a ¡few ¡nodes ¡fail ¡during ¡operaOon, ¡all ¡the ¡ ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 21 ¡

slide-22
SLIDE 22

AggregaOon: ¡Find ¡the ¡sum ¡of ¡values ¡at ¡ all ¡nodes ¡

  • With ¡BFS ¡tree ¡
  • Start ¡from ¡leaf ¡nodes ¡

– Nodes ¡without ¡children ¡ – Send ¡the ¡value ¡to ¡parent ¡

  • Every ¡other ¡node: ¡

– Wait ¡for ¡all ¡children ¡to ¡report ¡ – Sum ¡values ¡from ¡children ¡+ ¡own ¡value ¡ – Send ¡to ¡parent ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 22 ¡

slide-23
SLIDE 23

AggregaOon ¡

  • With ¡Tree ¡
  • Also ¡called ¡Convergecast ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 23 ¡

slide-24
SLIDE 24

AggregaOon ¡

  • With ¡Tree ¡
  • Once ¡tree ¡is ¡built, ¡any ¡node ¡can ¡use ¡for ¡broadcast ¡

– Just ¡flood ¡on ¡the ¡tree ¡

  • Any ¡node ¡can ¡use ¡for ¡convergecast ¡

– First ¡flood ¡a ¡message ¡on ¡the ¡tree ¡requesOng ¡data ¡ – Nodes ¡store ¡parent ¡pointer ¡ – Then ¡receive ¡data ¡

  • Fault ¡tolerance ¡not ¡very ¡good ¡

– If ¡a ¡node ¡fails, ¡the ¡messages ¡in ¡the ¡subtree ¡will ¡be ¡lost ¡ – Will ¡need ¡to ¡rebuild ¡the ¡tree ¡for ¡future ¡operaOons ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 24 ¡

slide-25
SLIDE 25

Shortest ¡paths ¡

  • BFS ¡tree ¡rooted ¡at ¡node ¡p ¡contains ¡shortest ¡

paths ¡to ¡p ¡from ¡all ¡nodes ¡in ¡the ¡network ¡

  • From ¡any ¡node ¡q, ¡follow ¡parent ¡pointers ¡to ¡p ¡

– Gives ¡shortest ¡path ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 25 ¡

slide-26
SLIDE 26

BFS ¡trees ¡can ¡be ¡used ¡for ¡rouOng ¡

  • From ¡each ¡node, ¡create ¡a ¡separate ¡BFS ¡tree ¡
  • Each ¡node ¡stores ¡a ¡parent ¡pointer ¡

corresponding ¡to ¡each ¡BFS ¡tree ¡

  • Acts ¡as ¡rouOng ¡table ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 26 ¡

1 ¡ 4 ¡ 2 ¡ 4 ¡ 3 ¡ 4 ¡ 4 ¡ 4 ¡ 1 ¡ 3 ¡ 2 ¡ 3 ¡ 3 ¡ 3 ¡ 5 ¡ 5 ¡ 1 ¡ 1 ¡ 2 ¡ 2 ¡ 4 ¡ 4 ¡ 5 ¡ 4 ¡ 2 ¡ 2 ¡ 3 ¡ 3 ¡ 4 ¡ 3 ¡ 5 ¡ 3 ¡ 1 ¡ 2 ¡ 4 ¡ 3 ¡ 5 ¡ 1 ¡ 1 ¡ 3 ¡ 3 ¡ 4 ¡ 3 ¡ 5 ¡ 3 ¡ Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡

26 ¡

slide-27
SLIDE 27

BFS ¡trees ¡can ¡be ¡used ¡for ¡rouOng ¡

  • From ¡each ¡node, ¡create ¡a ¡separate ¡BFS ¡tree ¡
  • Each ¡node ¡stores ¡a ¡parent ¡pointer ¡

corresponding ¡to ¡each ¡BFS ¡tree ¡

  • Acts ¡as ¡rouOng ¡table ¡
  • O(n*|E|) ¡message ¡complexity ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 27 ¡

slide-28
SLIDE 28

Shortest ¡(least ¡weight) ¡paths ¡with ¡BFS ¡ tree ¡and ¡edge ¡weights ¡

  • Bellman-­‑Ford ¡algorithm ¡
  • Each ¡node ¡p ¡has ¡a ¡variable ¡dist ¡represenOng ¡

distance ¡to ¡root. ¡IniOally ¡p.dist ¡=∞, ¡ ¡ ¡ ¡root.dist ¡= ¡0 ¡

  • In ¡each ¡round, ¡each ¡node ¡sends ¡its ¡dist ¡to ¡all ¡

neighbors ¡

  • If ¡for ¡neighbor ¡q ¡of ¡p: ¡ ¡q.dist ¡+ ¡w(p,q) ¡< ¡p.dist ¡

– Then ¡set ¡p.dist ¡= ¡q.dist ¡+ ¡w(p,q) ¡

¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 28 ¡

slide-29
SLIDE 29

Shortest ¡(least ¡weight) ¡paths ¡with ¡BFS ¡ tree ¡and ¡edge ¡weights ¡

  • Complexity ¡

– Time: ¡O(Diameter) ¡ – Message: ¡O(diameter*|E|) ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 29 ¡

slide-30
SLIDE 30

Directed ¡graphs ¡

  • We ¡have ¡considered ¡only ¡undirected ¡graphs ¡
  • CommunicaOon ¡may ¡be ¡directed ¡
  • When ¡A ¡can ¡send ¡message ¡to ¡B, ¡but ¡B ¡cannot ¡

send ¡message ¡to ¡A ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 30 ¡

slide-31
SLIDE 31

Directed ¡graphs ¡

  • When ¡A ¡can ¡send ¡message ¡to ¡B, ¡but ¡B ¡cannot ¡

send ¡message ¡to ¡A ¡

  • For ¡example, ¡in ¡wireless ¡transmission, ¡if ¡B ¡is ¡in ¡

A’s ¡range, ¡but ¡A ¡is ¡not ¡in ¡B’s ¡range ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 31 ¡

B ¡ A ¡

slide-32
SLIDE 32

Directed ¡graphs ¡

  • When ¡A ¡can ¡send ¡message ¡to ¡B, ¡but ¡B ¡cannot ¡

send ¡message ¡to ¡A ¡

  • Or ¡if ¡protocol ¡or ¡technology ¡limitaOons ¡

prevent ¡B ¡from ¡communicaOng ¡with ¡A ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 32 ¡

B ¡ A ¡

slide-33
SLIDE 33

Directed ¡graphs ¡

  • Protocols ¡more ¡complex ¡
  • Needs ¡more ¡messages ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 33 ¡

slide-34
SLIDE 34

Bit ¡complexity ¡of ¡communicaiton ¡

  • We ¡have ¡assumed ¡that ¡each ¡communicaOon ¡is ¡1 ¡message, ¡

and ¡we ¡counted ¡the ¡messages ¡

  • SomeOmes, ¡communicaOon ¡is ¡evaluated ¡by ¡bit ¡complexity ¡

– ¡the ¡number ¡of ¡bits ¡communicated ¡

  • This ¡is ¡different ¡from ¡message ¡complexity ¡because ¡a ¡

message ¡may ¡have ¡number ¡of ¡bits ¡that ¡depend ¡on ¡n ¡or ¡|E| ¡

  • For ¡example, ¡node ¡ids ¡in ¡message ¡have ¡size ¡Θ(log ¡n) ¡
  • In ¡pracOce ¡this ¡is ¡may ¡not ¡be ¡criOcal ¡since ¡log ¡n ¡is ¡much ¡

smaller ¡than ¡packet ¡sizes, ¡so ¡it ¡does ¡not ¡change ¡the ¡number ¡

  • f ¡packets ¡communicated ¡
  • But ¡depending ¡on ¡what ¡other ¡data ¡the ¡algorithm ¡is ¡

communicaOng, ¡sizes ¡of ¡messages ¡may ¡maser ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 34 ¡

slide-35
SLIDE 35

Finding ¡diameter ¡of ¡a ¡network ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 35 ¡

slide-36
SLIDE 36

About ¡Course ¡Assignment ¡

  • Will ¡be ¡based ¡on ¡implementaOon ¡of ¡a ¡

distributed ¡algorithm/protocol ¡

  • Will ¡be ¡simulaOon ¡oriented, ¡so ¡not ¡dependent ¡
  • n ¡knowledge ¡of ¡any ¡specific ¡technology ¡or ¡

API ¡

  • Will ¡have ¡a ¡small ¡part ¡of ¡theoreOcal ¡quesOons ¡

Distributed ¡Systems, ¡Edinburgh, ¡2014 ¡ 36 ¡