distributed*systems* basic*algorithms*...distributed*computaon* •...

54
Distributed Systems Basic Algorithms Rik Sarkar University of Edinburgh 2015/2016

Upload: others

Post on 12-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Distributed  Systems    

Basic  Algorithms  Rik  Sarkar  

 University  of  Edinburgh  

2015/2016  

Page 2: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Distributed  ComputaEon  

•  How  to  send  messages  to  all  nodes  efficiently  •  How  to  compute  sums  of  values  at  all  nodes  efficiently  

•  Network  as  a  graph  •  BroadcasEng  messages  •  CompuEng  sums  in  a  tree  •  CompuEng  trees  in  a  network  •  CommunicaEon  complexity  

Distributed  Systems,  Edinburgh,  2014   2  

Ref:  NL  

Page 3: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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

–  OWen  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  

•  But  a  node  does  not  know  the  rest  of  the  network  

Distributed  Systems,  Edinburgh,  2014   3  

Page 4: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Example:  Unit  disk  graphs  

•  Suppose  all  nodes  are  wireless  •  Each  can  communicate  with  nodes  within  distance  r.  

•  Say,  r  =  1  

•  UDG  is  a  model  •  Not  perfect  

•  In  general,  networks  can  be  any  graph  

Distributed  Systems,  Edinburgh,  2014   4  

Page 5: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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   5  

B  A  

Page 6: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Directed  graphs  

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

•  Or  if  protocol  or  technology  limitaEons  prevent  B  from  communicaEng  with  A  

Distributed  Systems,  Edinburgh,  2014   6  

B  A  

Page 7: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Directed  graphs  

•  Protocols  more  complex  •  Needs  more  messages  

Distributed  Systems,  Edinburgh,  2014   7  

Page 8: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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)  

•  SomeEmes,  edges  can  be  weighted  –  Each  edge  e  =  (a,b)  has  a  weight  w(e)  – w(e)  is  the  cost  of  using  the  communicaEon  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   8  

Page 9: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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  

–  If  network  has  n  nodes  •  How  many  edges  does  a  spanning  tree  have?  

Distributed  Systems,  Edinburgh,  2014   9  

Page 10: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CompuEng  sums  in  a  tree  

•  Suppose  root  wants  to  know  sum  of  values  at  all  nodes  

Distributed  Systems,  Edinburgh,  2014   10  

root  

Page 11: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CompuEng  sums  in  a  tree  •  Suppose  root  wants  to  know  sum  of  values  at  all  nodes  

•  It  sends  “compute”  message  to  all  children  

•  They  forward  the  message  to  all  their  children  (unless  it  is  a  leaf  node)  

•  The  values  move  upward  from  leaves  

•  Each  node  adds  values  from  all  children  and  its  own  value  

•  Sends  it  to  its  parent  

Distributed  Systems,  Edinburgh,  2014   11  

root  

Page 12: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CompuEng  sums  in  a  tree  

•  What  can  you  compute  other  than  sums?  

•  How  many  messages  does  it  take?    

•  How  much  Eme  does  it  take?  

Distributed  Systems,  Edinburgh,  2014   12  

root  

Page 13: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CommunicaEon  complexity  

•  Used  to  represent  communicaEon  cost  for  general  scenarios  

•  Called  CommunicaEon  Complexity  or  AsymptoEc  communicaEon  complexity  

•  Use  big  oh  notaEon:  O  

Distributed  Systems,  Edinburgh,  2014   13  

Page 14: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Big  oh  –  upper  bounds  •  For  a  system  of  n  nodes,  •  CommunicaEon  complexity  c(n)  is  O(f(n))  means:  – There  are  constants  a  and  N,  such  that:  

– For  n>N:  c(n)  <  a*f(n)  

f(n)  

c(n)  

N  Allowing  some  iniEal  irregularity,  ‘c(n)’  is  not    bigger  than  a  constant  Emes  ‘f(n)’    In  the  long  run,  c(n)  does  not  grow  faster  than  f(n)  

a*f(n)  

14  

Page 15: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Examples  

•  3n  =  O(?)  •  1000n  =  O(?)  •  n2/5  =  O(?)  •  10log  n  =  O(?)  •  2n3+n+log  n+  200  =  O(?)  •  15  =  O(?)  

Distributed  Systems,  Edinburgh,  2014   15  

Page 16: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Examples  

•  3n  =  O(n)  •  1000n  =  O(n)  •  n2/5  =  O(n2)  •  10log  n  =  O(log  n)  •  2n3+n+log  n+  200  =  O(n3)  •  15  or  any  other  constant=  O(1)  

Distributed  Systems,  Edinburgh,  2014   16  

Page 17: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Example  1  

•  ‘Star’  network  •  CompuEng  sum  of  all  values  •  CommunicaEon  complexity:  O(n)  

Server  

Distributed  Systems,  Edinburgh,  2014   17  

Page 18: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Example  2a  •  ‘Chain’  topology  network  •  Simple  protocol  where  everyone  sends  value  to  server  

•  CommunicaEon  complexity:?  

Server  

Distributed  Systems,  Edinburgh,  2014   18  

Page 19: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Example  2a  •  ‘Chain’  topology  network  •  Simple  protocol  where  everyone  sends  value  to  server  

•  CommunicaEon  complexity:  1+2+…+n  =  O(n2)  

Server  

Distributed  Systems,  Edinburgh,  2014   19  

Page 20: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Example  2b  •  ‘Chain’  network  •  Protocol  where  each  node  waits  for  sum  of  previous  values  and  sends    

•  CommunicaEon  complexity:  1+1+…+1  =  O(n)  

Server  

Distributed  Systems,  Edinburgh,  2014   20  

Page 21: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CompuEng  sums  in  a  tree  

•  How  many  messages  does  it  take?    

•  How  much  Eme  does  it  take?  

Distributed  Systems,  Edinburgh,  2014   21  

root  

Page 22: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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  transmission  

Distributed  Systems,  Edinburgh,  2014   22  

Source  

Page 23: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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   23  

Source  

Page 24: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Flooding  for  Broadcast  

•  The  source  sends  a  Flood  message  to  all  neighbors  

•  The  message  has  – Type  Flood  – Unique  id:  (source  id,  message  seq)  – Data  

Distributed  Systems,  Edinburgh,  2014   24  

Page 25: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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   25  

Page 26: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Flooding  for  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    •  (there  is  a  way  to  reduce  this.  Think!)  

Distributed  Systems,  Edinburgh,  2014   26  

Page 27: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

AssumpEons  

•  We  are  assuming:  – Nodes  are  working  in  synchronous  communicaDon  rounds  (e.g.  transmissions  occur  in  intervals  of  1  second  exactly)  

– Messages  from  all  neighbors  arrive  at  the  same  Eme,  and  processed  together  

–  In  each  round,  each  node  can  successfully  send  1  message  to  all  its  neighbors  

– Any  necessary  computaEon  can  be  completed  before  the  next  round    

Distributed  Systems,  Edinburgh,  2014   27  

Page 28: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CommunicaEon  complexity  

•  The  the  message/communicaEon  complexity  is:  

Distributed  Systems,  Edinburgh,  2014   28  

Page 29: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CommunicaEon  complexity  

•  The  the  message/communicaEon  complexity  is:  – O(|E|)  

Distributed  Systems,  Edinburgh,  2014   29  

Page 30: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CommunicaEon  complexity  

•  The  the  message/communicaEon  complexity  is:  – O(|E|)  – Worst  case:  O(n2)  

Distributed  Systems,  Edinburgh,  2014   30  

Page 31: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Reducing  CommunicaEon    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  asymptoEc  complexity  

Distributed  Systems,  Edinburgh,  2014   31  

Page 32: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Time  complexity  

•  The  number  of  rounds  needed  to  reach  all  nodes:  diameter  of  G  

Distributed  Systems,  Edinburgh,  2014   32  

Page 33: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CompuEng  Tree  from  a  network  

•  BFS  tree  – The  Breadth  first  search  tree  – With  a  specified  root  node  

Distributed  Systems,  Edinburgh,  2014   33  

Page 34: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

BFS  Tree  

•  Breadth  first  search  tree  – Every  node  has  a  parent  pointer  – And  zero  or  more  child  pointers  

– BFS  Tree  construcEon  algorithm  sets  these  pointers  

Distributed  Systems,  Edinburgh,  2014   34  

Page 35: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

BFS  Tree  ConstrucEon  algorithm  •  Breadth  first  search  tree  –  The  root(source)  node  decides  to  construct  a  tree  – Uses  flooding  to  construct  a  tree  –  Every  node  p  on  gesng  the  message  forwards  to  all  neighbors  

– AddiEonally,  every  node  p  stores  parent  pointer:  node  from  which  it  first  received  the  message  •  If  mulEple  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  selecEon  •  Parent  creates  a  child  pointer  to  p  

Distributed  Systems,  Edinburgh,  2014   35  

Page 36: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

BFS  Tree  

•  Property:  BFS  tree  is  a  shortest  path  tree  – For  source  s  and  any  node  p  – The  shortest  path  between  s  and  p  is  contained  in  the  BFS  tree  

Distributed  Systems,  Edinburgh,  2014   36  

Page 37: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Time  &  message  complexity  

•  AsymptoEcally  Same  as  Flooding  

Distributed  Systems,  Edinburgh,  2014   37  

root  

Page 38: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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   38  

root  

Page 39: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Tree  based  broadcast  

•  Simpler  than  flooding:  send  message  to  all  children  

•  CommunicaEon:  Number  of  edges  in  spanning  tree:  n-­‐1  

Distributed  Systems,  Edinburgh,  2014   39  

Page 40: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

AggregaEon:  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   40  

Page 41: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

AggregaEon  

•  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  operaEon,  all  the  rest  sEll  get  some  value  

Distributed  Systems,  Edinburgh,  2014   41  

Page 42: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

AggregaEon  

•  With  Tree  

•  Also  called  Convergecast  

Distributed  Systems,  Edinburgh,  2014   42  

Page 43: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

AggregaEon  •  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  requesEng  data  – Nodes  store  parent  pointer  –  Then  receive  data  

•  What  is  the  drawback  of  tree  based  aggregaEon?  

Distributed  Systems,  Edinburgh,  2014   43  

Page 44: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

AggregaEon  •  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  requesEng  data  –  Nodes  store  parent  pointer  –  Then  receive  data  

•  Fault  tolerance  not  very  good  –  If  a  node  fails,  the  messages  in  its  subtree  will  be  lost  –  Will  need  to  rebuild  the  tree  for  future  operaEons  

Distributed  Systems,  Edinburgh,  2014   44  

Page 45: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

BFS  trees  can  be  used  for  rouEng  •  From  each  node,  create  a  separate  BFS  tree  •  Each  node  stores  a  parent  pointer  corresponding  to  each  BFS  tree  

•  Acts  as  rouEng  table  

Distributed  Systems,  Edinburgh,  2014   45  

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   45  

Page 46: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

BFS  trees  can  be  used  for  rouEng  •  From  each  node,  create  a  separate  BFS  tree  •  Each  node  stores  a  parent  pointer  corresponding  to  each  BFS  tree  

•  Acts  as  rouEng  table  •  O(n*|E|)  message  complexity  in  compuEng  rouEng  table  

Distributed  Systems,  Edinburgh,  2014   46  

Page 47: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

ObservaEon  on  complexity    

•  Suppose  c(n)=n  – Then  c(n)  is  O(n)  and  also  O(n2)  –   Although,  when  we  ask  for  the  complexity,  we  are  looking  for  the  Eghtest  possible  bound,  which  is  O(n)  

 

Distributed  Systems,  Edinburgh,  2014   47  

Page 48: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Big  Ω  –  lower  bounds  •  For  a  system  of  n  nodes,  •  CommunicaEon  complexity  c(n)  is  Ω(f(n))  means:  – There  are  constants  a  and  N,  such  that:  

– For  n>N:    b*f(n)  <  c(n)  

f(n)  c(n)  

N  Allowing  some  iniEal  irregularity,  ‘c(n)’  is  not    smaller  than  a  constant  Emes  ‘f(n)’    In  the  long  run,  f(n)  does  not  grow  faster  than  c(n)  

b*f(n)  

48  

Page 49: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Big  θ  –  Eght  bounds:  both  O  and  Ω  •  For  a  system  of  n  nodes,  •  CommunicaEon  complexity  c(n)  is  θ(f(n))  means:  – There  are  constants  a,b  and  N,  such  that:  

– For  n>N:  b*f(n)<c(n)<a*f(n)  

f(n)  c(n)  

N  Allowing  some  iniEal  irregularity,  c(n)  and  f(n)  are  Within  constant  factors  of  each  other.  In  the  long  run,  c(n)  grows  at  same  rate  as  f(n),  upto  constant  factors.    

b*f(n)  

49  

a*f(n)  

Page 50: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Bit  complexity  of  communicaEon  •  We  have  assumed  that  each  communicaEon  is  1  message,  

and  we  counted  the  messages  •  SomeEmes,  communicaEon  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  pracEce  this  is  may  not  be  criEcal  since  log  n  is  much  smaller  than  packet  sizes,  so  it  does  not  change  the  number  of  packets  communicated  

•  But  depending  on  what  other  data  the  algorithm  is  communicaEng,  sizes  of  messages  may  mazer  

Distributed  Systems,  Edinburgh,  2014   50  

Page 51: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

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  representaEon  of  n  needs  log2  n  bits  

•  Ω  –  since  we  need  at  least  this  many  bits  – May  vary  by  constant  factors  depending  on  base  of  logarithm  

Distributed  Systems,  Edinburgh,  2014   51  

Page 52: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

CompuEng  Trees:  

•  What  if  the  edges  have  weights?    

Distributed  Systems,  Edinburgh,  2014   52  

Page 53: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

AggregaEon  using  Trees:  

•  What  if  the  edges  have  weights?    •  The  cost  may  not  be  O(n)  since  weights  can  be  higher  

•  How  to  get  the  best  performance?  

Distributed  Systems,  Edinburgh,  2014   53  

Page 54: Distributed*Systems* Basic*Algorithms*...Distributed*Computaon* • How*to*send*messages*to*all*nodes*efficiently* • How*to*compute*sums*of*values*atall*nodes* efficiently* • Network*as*agraph

Minimum  spanning  tree  is  

•  A  spanning  tree  (reaches  all  nodes)  •  With  minimum  possible  total  weight  

•  How  can  we  compute  a  minimum  spanning  tree  efficiently  in  a  distributed  system?  

•  (remember,  a  node  knows  only  its  neighbors  and  edge  weights)  

Distributed  Systems,  Edinburgh,  2014   54