distributed systems tree and flood algorithms...distributed systems tree and flood algorithms rik...

32
Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017

Upload: others

Post on 25-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

DistributedSystems

TreeandFloodAlgorithmsRikSarkar

UniversityofEdinburgh

2016/2017

Page 2: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

DistributedComputaEon

•  Howtosendmessagestoallnodesefficiently•  Howtocomputesumsofvaluesatallnodesefficiently

•  BroadcasEngmessages•  CompuEngsumsinatree•  CompuEngtreesinanetwork

DistributedSystems,Edinburgh,2016

Ref:NL

Page 3: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

Networkasagraph

•  Diameter–  Themaximumdistancebetween2nodesinthenetwork

•  Radius–  Halfthediameter

•  Spanningtreeofagraph:–  Asubgraphwhichisatree,andreachesallnodesofthegraph

–  Ifnetworkhasnnodes•  Howmanyedgesdoesaspanningtreehave?

DistributedSystems,Edinburgh,2016

Page 4: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

CompuEngsumsinatree

•  Supposerootwantstoknowsumofvaluesatallnodes

DistributedSystems,Edinburgh,2016

root

Page 5: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

CompuEngsumsinatree•  Supposerootwantstoknowsumofvaluesatallnodes

•  Itsends“compute”messagetoallchildren

•  Theyforwardthemessagetoalltheirchildren(unlessitisaleafnode)

•  Thevaluesmoveupwardfromleaves

•  Eachnodeaddsvaluesfromallchildrenanditsownvalue

•  Sendsittoitsparent

DistributedSystems,Edinburgh,2016

root

Page 6: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

CompuEngsumsinatree

•  Whatcanyoucomputeotherthansums?

•  Howmanymessagesdoesittake?

•  HowmuchEmedoesittake?

DistributedSystems,Edinburgh,2016

root

Page 7: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

GlobalMessagebroadcast•  Messagemustreachallnodesinthenetwork– DifferentfrombroadcasttransmissioninLAN– Allnodesinalargenetworkcannotbereachedwithsingletransmission

DistributedSystems,Edinburgh,2016

Source

Page 8: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

GlobalMessagebroadcast•  Messagemustreachallnodesinthenetwork– DifferentfrombroadcasttransmissioninLAN– Allnodesinalargenetworkcannotbereachedwithsingletransmissions

DistributedSystems,Edinburgh,2016

Source

Page 9: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

FloodingforBroadcast

•  ThesourcesendsaFloodmessagetoallneighbors

•  Themessagehas– TypeFlood– Uniqueid:(sourceid,messageseq)– Data

DistributedSystems,Edinburgh,2016

Page 10: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

FloodingforBroadcast

•  ThesourcesendsaFloodmessage,withauniquemessageidtoallneighbors

•  Everynodepthatreceivesafloodmessagem,doesthefollowing:–  Ifm.idwasseenbefore,discardm– Otherwise,Addm.idtolistofpreviouslyseenmessagesandsendmtoallneighborsofp

DistributedSystems,Edinburgh,2016

Page 11: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

Floodingforbroadcast

•  Storage– Eachnodeneedstostorealistoffloodidsseenbefore

–  Ifaprotocolrequiresxfloods,theneachnodemuststorexids•  (thereisawaytoreducethis.Think!)

DistributedSystems,Edinburgh,2016

Page 12: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

AssumpEons

•  Weareassuming:– NodesareworkinginsynchronouscommunicaDonrounds(e.g.transmissionsoccurinintervalsof1secondexactly)

– MessagesfromallneighborsarriveatthesameEme,andprocessedtogether

–  Ineachround,eachnodecansuccessfullysend1messagetoeachneighbor

– AnynecessarycomputaEoncanbecompletedbeforethenextround

DistributedSystems,Edinburgh,2016

Page 13: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

CommunicaEoncomplexity

•  Themessage/communicaEoncomplexityis:

DistributedSystems,Edinburgh,2016

Page 14: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

CommunicaEoncomplexity

•  Thethemessage/communicaEoncomplexityis:– O(|E|)

DistributedSystems,Edinburgh,2016

Page 15: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

CommunicaEoncomplexity

•  Thethemessage/communicaEoncomplexityis:– O(|E|)– Worstcase:O(n2)

DistributedSystems,Edinburgh,2016

Page 16: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

ReducingCommunicaEoncomplexity(slightly)

•  Nodepneednotsendmessagemtoanynodefromwhichithasalreadyreceivedm– Needstokeeptrackofwhichnodeshavesentthemessage

– Savessomemessages– DoesnotchangeasymptoEccomplexity

DistributedSystems,Edinburgh,2016

Page 17: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

Timecomplexity

•  Thenumberofroundsneededtoreachallnodes:diameterofG

DistributedSystems,Edinburgh,2016

Page 18: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

CompuEngTreefromanetwork

•  BFStree– TheBreadthfirstsearchtree– Withaspecifiedrootnode

DistributedSystems,Edinburgh,2016

Page 19: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

BFSTree

•  Breadthfirstsearchtree– Everynodehasaparentpointer– Andzeroormorechildpointers

– BFSTreeconstrucEonalgorithmsetsthesepointers

DistributedSystems,Edinburgh,2016

Page 20: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

BFSTreeConstrucEonalgorithm•  Breadthfirstsearchtree–  Theroot(source)nodedecidestoconstructatree– Usesfloodingtoconstructatree–  Everynodepongebngthemessageforwardstoallneighbors

– AddiEonally,everynodepstoresparentpointer:nodefromwhichitfirstreceivedthemessage•  IfmulEpleneighborshadfirstsentpthemessageinthesameround,chooseparentarbitrarily.E.g.nodewithsmallestid

–  pinformsitsparentoftheselecEon•  Parentcreatesachildpointertop

DistributedSystems,Edinburgh,2016

Page 21: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

BFSTree

•  Property:BFStreeisashortestpathtree– Forsourcesandanynodep– TheshortestpathbetweensandpiscontainedintheBFStree

DistributedSystems,Edinburgh,2016

Page 22: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

Time&messagecomplexity

•  AsymptoEcallySameasFlooding

DistributedSystems,Edinburgh,2016

root

Page 23: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

Treebasedbroadcast

•  Sendmessagetoallnodesusingtree– BFStreeisaspanningtree:connectsallnodes

•  Floodingonthetree

•  Receivemessagefromparent,sendtochildren

DistributedSystems,Edinburgh,2016

root

Page 24: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

Treebasedbroadcast

•  Simplerthanflooding:sendmessagetoallchildren

•  CommunicaEon:Numberofedgesinspanningtree:n-1

DistributedSystems,Edinburgh,2016

Page 25: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

AggregaEon:Findthesumofvaluesatallnodes

•  WithBFStree

•  Startfromleafnodes– Nodeswithoutchildren– Sendthevaluetoparent

•  Everyothernode:– Waitforallchildrentoreport– Sumvaluesfromchildren+ownvalue– Sendtoparent

DistributedSystems,Edinburgh,2016

Page 26: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

AggregaEon

•  Withoutthetree•  Floodfromallnodes:– O(|E|)costpernode– O(n*|E|)totalcost:expensive– Eachnodeneedstostorefloodidsfromnnodes•  RequiresΩ(n)storageateachnode

– Goodfaulttolerance•  IfafewnodesfailduringoperaEon,alltherestsEllgetsomevalue

DistributedSystems,Edinburgh,2016

Page 27: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

AggregaEon

•  WithTree

•  AlsocalledConvergecast

DistributedSystems,Edinburgh,2016

Page 28: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

AggregaEon•  WithTree

•  Oncetreeisbuilt,anynodecanuseforbroadcast–  Justfloodonthetree

•  Anynodecanuseforconvergecast–  FirstfloodamessageonthetreerequesEngdata– Nodesstoreparentpointer–  Thenreceivedata

•  WhatisthedrawbackoftreebasedaggregaEon?

DistributedSystems,Edinburgh,2016

Page 29: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

AggregaEon•  WithTree

•  Oncetreeisbuilt,anynodecanuseforbroadcast–  Justfloodonthetree

•  Anynodecanuseforconvergecast–  FirstfloodamessageonthetreerequesEngdata–  Nodesstoreparentpointer–  Thenreceivedata

•  Faulttolerancenotverygood–  Ifanodefails,themessagesinitssubtreewillbelost–  WillneedtorebuildthetreeforfutureoperaEons

DistributedSystems,Edinburgh,2016

Page 30: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

CompuEngTrees:

•  Whatiftheedgeshaveweights?

DistributedSystems,Edinburgh,2016

Page 31: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

AggregaEonusingTrees:

•  Whatiftheedgeshaveweights?•  ThecostmaynotbeO(n)sinceweightscanbehigher

•  Howtogetthebestperformance?

DistributedSystems,Edinburgh,2016

Page 32: Distributed Systems Tree and Flood Algorithms...Distributed Systems Tree and Flood Algorithms Rik Sarkar University of Edinburgh 2016/2017 Distributed Computaon • How to send messages

Minimumspanningtreeis

•  Aspanningtree(reachesallnodes)•  Withminimumpossibletotalweight

•  Howcanwecomputeaminimumspanningtreeefficientlyinadistributedsystem?

•  (remember,anodeknowsonlyitsneighborsandedgeweights)

DistributedSystems,Edinburgh,2016