分布式算法領(lǐng)導(dǎo)者選舉_第1頁(yè)
分布式算法領(lǐng)導(dǎo)者選舉_第2頁(yè)
分布式算法領(lǐng)導(dǎo)者選舉_第3頁(yè)
分布式算法領(lǐng)導(dǎo)者選舉_第4頁(yè)
分布式算法領(lǐng)導(dǎo)者選舉_第5頁(yè)
已閱讀5頁(yè),還剩61頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

分布協(xié)同計(jì)算基礎(chǔ)第二章:分布式算法(2)

---領(lǐng)導(dǎo)者選舉張錫哲副教授計(jì)算機(jī)應(yīng)用技術(shù)研究所東北大學(xué)信息科學(xué)與工程學(xué)院選舉問(wèn)題Ifweareusingoneprocessasacoordinatorforasharedresource……h(huán)owdoweselectthatoneprocess?Often,thereisnoownerormasterthatisautomaticallyconsideredascoordinator選舉問(wèn)題Manydistributedsystemsareclientserverbased,withoneserver/coordinator(leader),andmultipleclientsWhathappensiftheleaderfails?ElectanewoneCannotassumeonlyoneprocessdetectsthecrashTheelectionshouldgetalloftheprocessestoagreethatonenodeisaleader選舉誰(shuí)?Basicidea:Ifeachprocesshasauniqueidentity,andtheidentitiesareorderedElectthenon-crashednodewithminimum/maximumidentity選舉算法旳應(yīng)用whenacentralizedalgorithmistobe

executedinadistributedsystemforinstance,afterasystemcrashwhenitis

unknownwhichnodesareworking什么是選舉

“tostartfromaconfigurationwhereall

processesareinthesamestateandarriveat

aconfigurationwhereexactlyoneprocessis

theleader”

Goal:toobtainlowmessagecomplexity選舉算法旳定義Formally,analgorithmisanelectionalgorithmiff:EachprocesshasthesamelocalalgorithmThealgorithmisdecentralizedItcanbeinitiatedbyanynumberofprocessesinthesystemItreachesaterminalconfiguration,andineachreachableterminalconfigurationoneprocessisinstateleaderandtherestareinthestatelost假設(shè)FullyasynchronoussystemNoglobalclock,transmissiontimesarbitraryEveryprocesshasauniqueidentityIdentitiesaretotallyorderedBecausewehavefinitenumberofprocesses:MaxidentityandMinidentityavailable(extremevalues)RemarkProcessorsareinoneofthreestates:undecided,leader,lostInitiallyeveryprocessisintheundecidedstateWhenleavingtheundecidedstate,aprocessorgoesintoaterminatedstate(leaderorlost)環(huán)網(wǎng)上旳選舉單向環(huán)雙向環(huán)LeLann77,O(N2)Chang-Roberts79Ω(N2),Θ(NlogN)Hirshbergetal.80Ω(NlogN)Petersen/Dolevetal.82Ω(NlogN)11環(huán)網(wǎng)上旳選舉ThefirsteverelectionalgorithmwasdoneforringsbyLeLannSimpleidea:LeteveryinitiatorsendatokenwiththeiridentityaroundthewholeringNodesarenotallowedtoinitiateaftertheyreceiveatoken(example…)12ExampleNodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example…)35198267initiator13ExampleNodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example…)35198267initiator14ExampleNodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example…)35198267initiatornotallowedtoinitiate15ExampleNodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example…)35198267initiatornotallowedtoinitiatenotallowedtoinitiate16ExampleNodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example…)35198267initiatornotallowedtoinitiatenotallowedtoinitiatenotallowedtoinitiate17ExampleNodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example…)35198267initiatornotallowedtoinitiatenotallowedtoinitiateinitiatornotallowedtoinitiate18ExampleNodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example…)35198267initiatornotallowedtoinitiatenotallowedtoinitiateinitiatornotallowedtoinitiatenotallowedtoinitiate19ExampleNodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example…)35198267initiatornotallowedtoinitiatenotallowedtoinitiateinitiatornotallowedtoinitiatenotallowedtoinitiatenotallowedtoinitiate20LeLann’sringelectionWheneveranodereceivesbackitsid,ithasseeneveryotherinitiatorsidAssumingFIFOchannelsLeteverynodekeepalistofeveryidentifierseen(listp)Ifnon-initiator,state=lostimmediatelyIfinitiator,whenownidreceived:state=leaderifmin{listp}=pstate=lost

otherwiseLeLann’sAlgorithmNon-initiatorsjustforwardandloseInitiallyonlyknowmyselfSendmyid,andwaitRepeatforwardingandcollectingidsuntilwereceiveouridTermination:didwewinorlose22MessageComplexityWorstcaseiseverynodeisinitiator(N)EveryinitiatorsendsNmessagesGivesatotalofN2messages23時(shí)間復(fù)雜度AssumelastinitiatorfstartsattimeN-1fterminatesafteritstokenhascirculatedthering,NstepsTimecomplexity2N-135198267initiatorlastinitiator24Chang-Roberts算法ChangandRobertscameupwithasmallimprovementIdea:Whenanodereceivesatokenwithlargeridthanitself,whyshoulditkeepforwardingit?Itisawaste,weknowthatthatidwillneverwin!Letsdroptokenswithlargeridsthanourselves!25HowtomakeitworkButifwedropatokenwithids,nodeswillbewaitingforeveronitstokentocomebackHowdowesolvethat?26HowtomakeitworkIfnodestokenisdropped,itwillanywayreceiveanothertokenwithloweridInthatcase,sshouldsetstate=lostChangandRobertsAlgoNon-initiatorsjustforwardandloseInitiatorsendsitstokenWhilenotleader,keepreceivingtokensIfmytokencomes,thenIwonOtherwise,onlyforwardifit’sloweridthanmeandlose28ChangRoberts-ExampleNodes1,3,6areinitiators6913Non-initiatorLostWon6Initiator132901753264ChangRobertsAnalysisWorstcasecomplexitysameasLeLann’sTimeComplexity:2N-1MessageComplexity:O(N2)ConsideredasortedringwithNinitiators8times7times6times5times4times3times2times1times30Furtherimprovements?Letthenon-initiatorsalsofilterloweridsDonotjustcomparewithyourid,comparewiththelowestidyouhaveseen!HSRingElectionHirschbergSinclairAlgorithm(ringmodification)O(N2)isalotofmessages.HereisamodificationthatisO(NlogN).Assumptions:theringsizecanbeunknown.Thecommunicationsmustbebidirectional.Allnodesstartmoreorlessatthesametime.Eachnodeoperatesinphasesandsendsouttokens.Thetokenscarryhop-countsanddirectionflagsinadditiontotheIDofthesender.3

ID=3,2hops

clockwise

ID=3,2hops

counterclckwsHSRingElectionPhasesarenumbered0,1,2,3,…Ineachphase,k,nodejsendsouttokensujcontainingitsIDinbothdirections.Thetokenstravel2khopsthenreturntotheiroriginj.Ifbothtokensmakeitback,processjcontinueswiththenextphase(incrementsk).Ifbothtokensdonotmakeitback,processjsimplywaitstobetoldwhotheresultsoftheelection.33xxiPhase0:20Phase1:21Phase2:22TrajectoryofsuccessivetokensoriginatingatprocessiHSRingElection6-34HSRingElectionIfaprocessmreceivesatokenujgoingintheoutbounddirection,itcomparesthetoken’sIDwithitsown.IfithasalargerID,itsimplydiscardsthetoken.IfithasasmallerID,itrelaysthetokenasrequested.IfitisequaltothetokenID,ithasreceiveditsowntokenintheoutbounddirection,sothetokenhasgonecleararoundtheringandtheprocessdeclaresitselfleader.Allprocessesalwaysrelayinboundtokens.4ID=3,2hopsclockwise非形式化描述Eachprocessioperatesinphases0,1,2,....Ineachphasel,processisendsout"tokens"containingitsUIDuiinbothdirections.Theseareintendedtotraveldistance2l,thenreturntotheirorigini.Ifbothtokensmakeitbacksafely,processicontinueswiththefollowingphase.However,thetokensmightnotmakeitbacksafely.Whileauitokenisproceedingintheoutbounddirection,eachotherprocessjonui'spathcomparesuiwithitsownUIDuj.Ifui<uj,thenjsimplydiscardsthetoken,whereasifui>uj,thenjrelaysui.Ifui=uj,thenitmeansthatprocessjhasreceiveditsownUIDbeforethetokenhasturnedaround,soprocessjelectsitselfastheleader.Allprocessalwaysrelayalltokensintheinbounddirection.HSRingElection一種例子Fordemonstrationpurposes,wewillignoretheasynchronousnatureofthesystemandassumethatallnodesoperateatthesamespeedandatthesametime.InitialnetworkconfigurationwithUIDvaluesinblue.015225314456544134Initialconfiguration.BluenumbersareUIDvaluesThealgorithmstartsinphase0,andeachnodewillsendanoutboundmessagetoitsneighbors.Themessageisintendedtotraveladistanceof20

hops.ThenodesthatreceivedaninboundmessagewithitsOWNUIDfrombothneighborsarequalifiedtoproceedtothenextphase.Theyareindicatedingray.015225314456544134Thenodeseligibletocontinuetophase2Nowweadvancetophase1,andeachactivenodewillsendanoutboundmessagetoitsneighbors.Themessagethistimeisintendedtotraveladistanceof21

hops.Thestraightarrowsrepresentsoutboundandthecurvedarrowsrepresentsinbound.

015225314456544134Phase1.Onlynode4receivesaninboundmessagefrombothneighbors34345656Phase2.Onlynode4isactiveinphase2.Itistheonlynodethatcaninitiateamessage.Themessageisintendedtotravel22

hops.Outgoingmessagessentbynode4intheclockwisedirectionareinpink.Outgoingmessagesinthecounter-clockwisedirectionareingreen.Straightlinesareoutgoingmessages,curvedlinesareincoming.015225314456544134Phase2.Node4onceagainreceivesbothinboundmessageswithownUID5656Phase3.Onlynode4isactiveinphase2.Itistheonlynodethatcaninitiateamessage.Itsmessagesareintendedtotravel23

hops.015225314456544134Phase3.Node4changesitsstatustoleader.43AnalysisofHSRingElectionMessageComplexity:Eachmsgbelongstoaparticularphaseandisinitiatedbyaparticularproc.Probedistanceinphaseiis2iNumberofmsgsinitiatedbyaproc.inphaseiisatmost4*2i(probesandrepliesinbothdirections)44AnalysisofHSRingElectionHowmanyprocs.initiateprobesinphasei?Fori=0,everyproc.doesFori>0,everyproc.thatisa"winner"inphasei-1does"winner"meanshaslargestidinits2i-1neighborhood45AnalysisofHSRingElectionMaximumnumberofphasei-1winnersoccurswhentheyarepackedasdenselyaspossible:totalnumberofphasei-1winnersisatmostn/(2i-1+1)46AnalysisofHSRingElectionHowmanyphasesarethere?Ateachphasethenumberof(phase)winnersiscutinhalf(atleast)Soafteratmostlog2

nphases,onlyonewinnerisleft.47AnalysisofHSRingElectionTotalnumberofmessagesissum,overallphases,ofnumberofwinnersatthatphasetimesnumberofmessagesoriginatedbythatwinner:phase0msgsmsgsforphases1tolognterminationmsgsFranklin算法Allactiveidentitiescomparethemselveswiththe

closestactiveneighbortotheleftandtotherightTheidentityremainsactiveifitisthelocalmin.Peterson/Dolev-Klawe-RodehPetersonLeader-ElectionAlgorithmArbitraryelectionofleaderusingcomparisonofUID’susingunidirectionalcommunicationAlgorithmrunsinphasesinwhicheachprocessisassignedtoactiveorpassivemode(allprocessesstartasactive)ThenumberofactiveprocessesisreducedbyafactoroftwoduringeachphaseSummary:AtthebeginningofeachphaseeachactiveprocessisendsitsUIDtwostepsclockwise.ThenprocessicomparesitsownUIDtothetwoUIDsitreceived.Ifui-1<ui-2andui-1<ui,processiremainsactiveadoptingtheUIDofitscounterclockwiseneighborOtherwiseprocessibecomesarelayPetersonLeaderElectionExamplei11UID=9i10UID=4i9UID=5i12UID=7i8UID=11i7UID=12i6UID=3i5UID=2i4UID=6i3UID=1i2UID=10i1UID=8nPhase1Phase2Phase3Phase4187,9---2108,7---3110,8109,12--461,10---526,1610,91012,101212,12632,6---7123,2---81112,3126,10--9511,12---1045,11---1194,5---1279,4912,61210,12-PetersonLeader-ElectionExamplePetersonLeader-ElectionAlgorithmAnyactiveprocesssurvivesaphaseonlyiftheactiveprocesstoitsleftdoesnotsurvivethatphase.Henceofmactiveprocessesduringaphase,atmostm/2willsurviveform>1.TherecanbeatmostlogNphasestoreachoneactiveprocess.Duringaphaseeveryprocesssends(andreceive)twomessages,andonthelastphasetheloneactiveprocesssendsonemessagewhichisrelayedaroundtothemaximumforatotalof2NlogN+N.5455同步環(huán)中旳選舉Hereisasimplealgorithm.Grouproundsintophases,eachphasecontainingn

roundsInphasei,theprocessorwithidi,ifthereisone,sendsamessagearoundtheringandiselected.56ExampleofSimpleSynchronousAlgorithmn=4,thesmallestidis7.Inphases0through6(correspondingtorounds1through28),nomessageiseversent.Atbeginningofphase7(round29),processorwithid7sendsmessagewhichisforwardedaroundthering.Reliesonsynchronyandknowingn57AnalysisofSimpleAlgorithmCorrectness:Easytosee.Messagecomplexity:

O(n),whichisoptimalTimecomplexity:

O(n*m),wheremisthesmallestidinthering.notboundedbyanyfunctionofn!58AnotherSynchronousAlgorithmWorksinaslightlyweakermodelthantheprevioussynchronousalgorithm:processorsmightnotallstartatsameround;aprocessoreitherwakesupspontaneouslyorwhenitfirstgetsamessageuniform(doesnotrelyonknowingn)59AnotherSynchronousAlgorithmAprocessorthatwakesupspontaneouslyisactive;sendsitsidinafast

message(oneedgeperround)Aprocessorthatwakesupwhenreceivingamsgisrelay;neverinthecompetitionAfastmessagecarryingidmbecomesslow

ifitreachesanactiveprocessor;startstravelingatoneedgeper2mroundsAprocessoronlyforwardsamsgwhoseidissmallerthananyidishaspreviouslysentIfaproc.getsitsownidback,electsself60AnalysisofSynchronousAlgorithmCorrectness:convinceyourselfthattheactiveprocessorwithsmallestidiselected.Messagecomplexity:Winner'smsgisthefastest.Whileittraversesthering,othermsgsareslower,sotheyareovertakenandstoppedbeforetoomanymessagesaresent.61MessageComplexityDividemsgsintothreekinds:fastmsgsslowmsgssentwhiletheleader'smsgisfastslowmsgssentwhiletheleader'smsgisslowNext,countthenumberofeachtypeofmsg.62

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論