已阅读5页,还剩61页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
分布协同计算基础,第二章:分布式算法(2)-领导者选举张锡哲副教授计算机应用技术研究所东北大学信息科学与工程学院,选举问题,Ifweareusingoneprocessasacoordinatorforasharedresourcehowdoweselectthatoneprocess?Often,thereisnoownerormasterthatisautomaticallyconsideredascoordinator,选举问题,Manydistributedsystemsareclientserverbased,withoneserver/coordinator(leader),andmultipleclientsWhathappensiftheleaderfails?ElectanewoneCannotassumeonlyoneprocessdetectsthecrashTheelectionshouldgetalloftheprocessestoagreethatonenodeisaleader,选举谁?,Basicidea:Ifeachprocesshasauniqueidentity,andtheidentitiesareorderedElectthenon-crashednodewithminimum/maximumidentity,选举算法的应用,whenacentralizedalgorithmistobeexecutedinadistributedsystemforinstance,afterasystemcrashwhenitisunknownwhichnodesareworking,什么是选举,“tostartfromaconfigurationwhereallprocessesareinthesamestateandarriveataconfigurationwhereexactlyoneprocessistheleader”Goal:toobtainlowmessagecomplexity,选举算法的定义,Formally,analgorithmisanelectionalgorithmiff:EachprocesshasthesamelocalalgorithmThealgorithmisdecentralizedItcanbeinitiatedbyanynumberofprocessesinthesystemItreachesaterminalconfiguration,andineachreachableterminalconfigurationoneprocessisinstateleaderandtherestareinthestatelost,假设,FullyasynchronoussystemNoglobalclock,transmissiontimesarbitraryEveryprocesshasauniqueidentityIdentitiesaretotallyorderedBecausewehavefinitenumberofprocesses:MaxidentityandMinidentityavailable(extremevalues),Remark,Processorsareinoneofthreestates:undecided,leader,lostInitiallyeveryprocessisintheundecidedstateWhenleavingtheundecidedstate,aprocessorgoesintoaterminatedstate(leaderorlost),环网上的选举,单向环双向环LeLann77,O(N2)Chang-Roberts79(N2),(NlogN)Hirshbergetal.80(NlogN)Petersen/Dolevetal.82(NlogN),11,环网上的选举,ThefirsteverelectionalgorithmwasdoneforringsbyLeLannSimpleidea:LeteveryinitiatorsendatokenwiththeiridentityaroundthewholeringNodesarenotallowedtoinitiateaftertheyreceiveatoken(example),12,Example,Nodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example),3,5,1,9,8,2,6,7,initiator,13,Example,Nodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example),3,5,1,9,8,2,6,7,initiator,14,Example,Nodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example),3,5,1,9,8,2,6,7,initiator,notallowedtoinitiate,15,Example,Nodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example),3,5,1,9,8,2,6,7,initiator,notallowedtoinitiate,notallowedtoinitiate,16,Example,Nodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example),3,5,1,9,8,2,6,7,initiator,notallowedtoinitiate,notallowedtoinitiate,notallowedtoinitiate,17,Example,Nodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example),3,5,1,9,8,2,6,7,initiator,notallowedtoinitiate,notallowedtoinitiate,initiator,notallowedtoinitiate,18,Example,Nodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example),3,5,1,9,8,2,6,7,initiator,notallowedtoinitiate,notallowedtoinitiate,initiator,notallowedtoinitiate,notallowedtoinitiate,19,Example,Nodesarenotallowedtoinitiateamessageaftertheyreceiveatoken(example),3,5,1,9,8,2,6,7,initiator,notallowedtoinitiate,notallowedtoinitiate,initiator,notallowedtoinitiate,notallowedtoinitiate,notallowedtoinitiate,20,LeLannsringelection,Wheneveranodereceivesbackitsid,ithasseeneveryotherinitiatorsidAssumingFIFOchannelsLeteverynodekeepalistofeveryidentifierseen(listp)Ifnon-initiator,state=lostimmediatelyIfinitiator,whenownidreceived:state=leaderifminlistp=pstate=lostotherwise,LeLannsAlgorithm,Initiallyonlyknowmyself,Sendmyid,andwait,Termination:didwewinorlose,22,MessageComplexity,Worstcaseiseverynodeisinitiator(N)EveryinitiatorsendsNmessagesGivesatotalofN2messages,23,时间复杂度,AssumelastinitiatorfstartsattimeN-1fterminatesafteritstokenhascirculatedthering,NstepsTimecomplexity2N-1,3,5,1,9,8,2,6,7,initiator,lastinitiator,24,Chang-Roberts算法,ChangandRobertscameupwithasmallimprovementIdea:Whenanodereceivesatokenwithlargeridthanitself,whyshoulditkeepforwardingit?Itisawaste,weknowthatthatidwillneverwin!Letsdroptokenswithlargeridsthanourselves!,25,Howtomakeitwork,Butifwedropatokenwithids,nodeswillbewaitingforeveronitstokentocomebackHowdowesolvethat?,26,Howtomakeitwork,Ifnodestokenisdropped,itwillanywayreceiveanothertokenwithloweridInthatcase,sshouldsetstate=lost,ChangandRobertsAlgo,Initiatorsendsitstoken,Whilenotleader,keepreceivingtokens,Ifmytokencomes,thenIwon,28,ChangRoberts-Example,Nodes1,3,6areinitiators,6,9,1,3,Non-initiator,Lost,Won,6,Initiator,1,3,29,0,1,7,5,3,2,6,4,ChangRobertsAnalysis,WorstcasecomplexitysameasLeLannsTimeComplexity:2N-1MessageComplexity:O(N2)ConsideredasortedringwithNinitiators,8times,7times,6times,5times,4times,3times,2times,1times,30,Furtherimprovements?,HSRingElection,HirschbergSinclairAlgorithm(ringmodification)O(N2)isalotofmessages.HereisamodificationthatisO(NlogN).Assumptions:theringsizecanbeunknown.Thecommunicationsmustbebidirectional.Allnodesstartmoreorlessatthesametime.Eachnodeoperatesinphasesandsendsouttokens.Thetokenscarryhop-countsanddirectionflagsinadditiontotheIDofthesender.,3,ID=3,2hopsclockwise,ID=3,2hopscounterclckws,HSRingElection,Phasesarenumbered0,1,2,3,Ineachphase,k,nodejsendsouttokensujcontainingitsIDinbothdirections.Thetokenstravel2khopsthenreturntotheiroriginj.Ifbothtokensmakeitback,processjcontinueswiththenextphase(incrementsk).Ifbothtokensdonotmakeitback,processjsimplywaitstobetoldwhotheresultsoftheelection.,3,3,x,x,Trajectoryofsuccessivetokensoriginatingatprocessi,HSRingElection,6-34,HSRingElection,Ifaprocessmreceivesatokenujgoingintheoutbounddirection,itcomparesthetokensIDwithitsown.IfithasalargerID,itsimplydiscardsthetoken.IfithasasmallerID,itrelaysthetokenasrequested.IfitisequaltothetokenID,ithasreceiveditsowntokenintheoutbounddirection,sothetokenhasgonecleararoundtheringandtheprocessdeclaresitselfleader.Allprocessesalwaysrelayinboundtokens.,4,ID=3,2hopsclockwise,非形式化描述,Eachprocessioperatesinphases0,1,2,.Ineachphasel,processisendsouttokenscontainingitsUIDuiinbothdirections.Theseareintendedtotraveldistance2l,thenreturntotheirorigini.Ifbothtokensmakeitbacksafely,processicontinueswiththefollowingphase.However,thetokensmightnotmakeitbacksafely.Whileauitokenisproceedingintheoutbounddirection,eachotherprocessjonuispathcomparesuiwithitsownUIDuj.Ifuiuj,thenjrelaysui.Ifui=uj,thenitmeansthatprocessjhasreceiveditsownUIDbeforethetokenhasturnedaround,soprocessjelectsitselfastheleader.Allprocessalwaysrelayalltokensintheinbounddirection.,HSRingElection,一个例子,Fordemonstrationpurposes,wewillignoretheasynchronousnatureofthesystemandassumethatallnodesoperateatthesamespeedandatthesametime.InitialnetworkconfigurationwithUIDvaluesinblue.,Thealgorithmstartsinphase0,andeachnodewillsendanoutboundmessagetoitsneighbors.Themessageisintendedtotraveladistanceof20hops.,ThenodesthatreceivedaninboundmessagewithitsOWNUIDfrombothneighborsarequalifiedtoproceedtothenextphase.Theyareindicatedingray.,Nowweadvancetophase1,andeachactivenodewillsendanoutboundmessagetoitsneighbors.Themessagethistimeisintendedtotraveladistanceof21hops.Thestraightarrowsrepresentsoutboundandthecurvedarrowsrepresentsinbound.,Phase2.Onlynode4isactiveinphase2.Itistheonlynodethatcaninitiateamessage.Themessageisintendedtotravel22hops.Outgoingmessagessentbynode4intheclockwisedirectionareinpink.Outgoingmessagesinthecounter-clockwisedirectionareingreen.Straightlinesareoutgoingmessages,curvedlinesareincoming.,Phase3.Onlynode4isactiveinphase2.Itistheonlynodethatcaninitiateamessage.Itsmessagesareintendedtotravel23hops.,43,AnalysisofHSRingElection,MessageComplexity:Eachmsgbelongstoaparticularphaseandisinitiatedbyaparticularproc.Probedistanceinphaseiis2iNumberofmsgsinitiatedbyaproc.inphaseiisatmost4*2i(probesandrepliesinbothdirections),44,AnalysisofHSRingElection,Howmanyprocs.initiateprobesinphasei?Fori=0,everyproc.doesFori0,everyproc.thatisawinnerinphasei-1doeswinnermeanshaslargestidinits2i-1neighborhood,45,AnalysisofHSRingElection,Maximumnumberofphasei-1winnersoccurswhentheyarepackedasdenselyaspossible:totalnumberofphasei-1winnersisatmostn/(2i-1+1),46,AnalysisofHSRingElection,Howmanyphasesarethere?Ateachphasethenumberof(phase)winnersiscutinhalf(atleast)Soafteratmostlog2nphases,onlyonewinnerisleft.,47,AnalysisofHSRingElection,Totalnumberofmessagesissum,overallphases,ofnumberofwinnersatthatphasetimesnumberofmessagesoriginatedbythatwinner:,phase0msgs,msgsforphases1tologn,terminationmsgs,Franklin算法,AllactiveidentitiescomparethemselveswiththeclosestactiveneighbortotheleftandtotherightTheidentityremainsactiveifitisthelocalmin.,Peterson/Dolev-Klawe-Rodeh,PetersonLeader-ElectionAlgorithm,ArbitraryelectionofleaderusingcomparisonofUIDsusingunidirectionalcommunicationAlgorithmrunsinphasesinwhicheachprocessisassignedtoactiveorpassivemode(allprocessesstartasactive)ThenumberofactiveprocessesisreducedbyafactoroftwoduringeachphaseSummary:AtthebeginningofeachphaseeachactiveprocessisendsitsUIDtwostepsclockwise.ThenprocessicomparesitsownUIDtothetwoUIDsitreceived.Ifui-1ui-2andui-11.TherecanbeatmostlogNphasestoreachoneactiveprocess.Duringaphaseeveryprocesssends(andreceive)twomessages,andonthelastphasetheloneactiveprocesssendsonemessagewhichisrelayedaroundtothemaximumforatotalof2NlogN+N.,54,55,同步环中的选举,Hereisasimplealgorithm.Grouproundsintophases,eachphasecontainingnroundsInphasei,theprocessorwithidi,ifthereisone,sendsamessagearoundtheringandiselected.,56,ExampleofSimpleSynchronousAlgorithm,n=4,thesmallestidis7.Inphases0through6(correspondingtorounds1through28),nomessageiseversent.Atbeginningofphase7(round29),processorwithid7sendsmessagewhichisforwardedaroundthering.,Reliesonsynchronyandknowingn,57,AnalysisofSimpleAlgorithm,Correctness:Easytosee.Messagecomplexity:O(n),whichisoptimalTimecomplexity:O(n*m),wheremisthesmallestidinthering.notboundedbyanyfunctionofn!,58,AnotherSynchronousAlgorithm,Worksinaslightlyweakermodelthantheprevioussynchronousalgorithm:processorsmightnotallstartatsameround;aprocessoreitherwakesupspontaneouslyorwhenitfirstgetsamessageuniform(doesnotrelyonknowingn),59,AnotherSynchronousAlgorithm,Aprocessorthatwakesupspontaneouslyisactive;sendsitsidinafastmessage(oneedgeperround)Aprocessorthatwakesupwhenreceivingamsgisrelay;neverinthecompetitionAfastmessagecarryingidmbecomesslowifitreachesanactiveprocessor;startstravelingatoneedgeper2mroundsAprocessoronlyforwardsamsgwhoseidissmallerthananyidishaspreviouslysentIfaproc.getsitsownidback,electsself,60,AnalysisofSynchronousAlgorithm,Correctness:convinceyourselfthattheactiveprocessorwithsmallestidiselected.Messagecomplexity:Winnersmsgisthefastest.Whileittraversesthering,othermsgsareslower,sotheyareovertakenandstoppedbeforetoomanymessagesaresent.,61,MessageComplexity,Dividemsgsintothreekinds:fastmsgsslowmsgssentwhiletheleadersmsgisfastslowmsgssentwhiletheleadersmsgisslowNext,countthenumberofeachtypeofmsg.,62,Showthatnoprocessorforwardsmorethanonefastmsg:S
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 浙江2025年下半年桐乡市事业单位招考易考易错模拟试题(共500题)试卷后附参考答案
- 河南新郑市刑事技术鉴定服务中心招考事业单位工作人员易考易错模拟试题(共500题)试卷后附参考答案
- 江门市高新技术产业促进会招考易考易错模拟试题(共500题)试卷后附参考答案
- 分公司运营合同范本
- 冷藏出售转让协议书
- 杭州市上城区2025年下半年下半年招考50名专职社区工作者易考易错模拟试题(共500题)试卷后附参考答案
- 招商银行博士后科研工作站面向海内外招考第十一批博士后研究人员易考易错模拟试题(共500题)试卷后附参考答案
- 广州市荔湾区沙面街公房管理中心招考房屋建筑工程技术员易考易错模拟试题(共500题)试卷后附参考答案
- 供热出售协议合同书
- 广东从化市市政工程建设管理中心事业单位招考易考易错模拟试题(共500题)试卷后附参考答案
- 腹膜透析患者健康教育讲课件
- 星海中学择校考试试题及答案
- T/TMAC 041.F-2022科技服务机构星级评价规范
- T/CECS 10107-2020超高性能混凝土(UHPC)技术要求
- JJF(京) 130-2024 重型汽车氮氧化物快速检测仪校准规范
- 早产儿肠内营养管理专家共识(2024年)解读
- 砌体结构后锚固技术规程
- 2025年招标师(招标采购专业实务)考试真题试卷(附完整解析)
- 教师角色的嬗变之路
- 2025年第三届天扬杯建筑业财税知识竞赛题库附答案(1-500题)
- 《红岩》知识竞赛读书会 课件-2024-2025学年统编版语文七年级下册
评论
0/150
提交评论