




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
分布式系統(tǒng)中的通信進(jìn)程間通信是一切分布式系統(tǒng)的核心。分布式系統(tǒng)中的通信都是基于底層網(wǎng)絡(luò)提供的低層消息傳遞機(jī)制的。通過(guò)消息傳遞來(lái)描述通信過(guò)程比使用基于共享存儲(chǔ)器的原語(yǔ)來(lái)描述要更困難。分布式系統(tǒng)中的通信進(jìn)程間通信是一切分布式系統(tǒng)的核心。14種廣泛使用的通信模型遠(yuǎn)程過(guò)程調(diào)用(remoteprocedurecall,RPC)遠(yuǎn)程方法調(diào)用(remotemethodinvocation,RMI)面向消息的中間件(message-orientedmiddleware,MOM)面向流的通信(stream-orientedcommunication)4種廣泛使用的通信模型2CommunicationProtocols
由于沒(méi)有共享存儲(chǔ)器,分布式系統(tǒng)中的所有通信都是基于(低層)消息交換的。Protocolsareagreements/rulesoncommunicationProtocolscouldbeconnection-orientedorconnectionlessApplicationPresentationSessionTransportNetworkDatalinkPhysicalApplicationprotocolPresentationprotocolSessionprotocolTransportprotocolNetworkprotocolDatalinkprotocolPhysicalprotocolNetwork7654321CommunicationProtocols由于沒(méi)3LayeredProtocolsAtypicalmessageasitappearsonthenetwork.2-2LayeredProtocolsAtypicalmes4DataLinkLayerDiscussionbetweenareceiverandasenderinthedatalinklayer.2-3DataLinkLayerDiscussionbetw5Client-ServerInteractionusingTCPNormaloperationofTCP(常規(guī)TCP的許多開(kāi)銷(xiāo)都耗費(fèi)在連接的管理上).TransactionalTCP(更經(jīng)濟(jì)的方式).2-4服務(wù)器執(zhí)行請(qǐng)求的操作告訴服務(wù)器關(guān)閉該連接客戶啟動(dòng)連接建立過(guò)程1,2,3要求客戶釋放連接將發(fā)送請(qǐng)求當(dāng)作連接的建立標(biāo)志(一個(gè)消息包含三條信息)把送回結(jié)果當(dāng)作連接的關(guān)閉標(biāo)志確認(rèn)連接的終止確認(rèn)已收到客戶的請(qǐng)求Client-ServerInteractionusin6MiddlewareProtocolsMiddleware:-Anapplicationthatlogicallylivesintheapplicationlayer-Containsmanygeneral-purposeprotocolsthatwarrant(代表)
theirownlayers-(會(huì)話層和表示層由一個(gè)單一的中間件層代替)ApplicationMiddlewareTransportNetworkDatalinkPhysicalApplicationprotocolMiddlewareprotocolTransportprotocolNetworkprotocolDatalinkprotocolPhysicalprotocolNetwork654321MiddlewareProtocolsMiddleware7Client-ServerCommunicationModelStructure:groupofserversofferingservicetoclients-Servers:offerservicestotheuserscalled“clients”-Clients:applicationsrequiringservicesfromservers-Example:WebServer/clients,Fileserver…Whyuseclient-servermodel-simplicity-low(er)overheadsclientkernelfileserverkernelprocessserverkernelterminalserverkernelClient-ServerCommunicationMo8Client-ServerCommunicationModelBasedonarequest/responseparadigm-Clientssendarequestaskingforservice(e.g.,afileblock)-Serverprocessesandreplieswithresult(orerror)Techniques:-Socket,RemoteProcedureCalls(RPC),RemoteMethodInvocation(RMI)
clientkernelfileserverkernelprocessserverkernelterminalserverkernelClient-ServerCommunicationMo9RemoteProcedureCall(RPC)Client-ServerprovidesamechanismforservicesindistributedsystemsBUT-requiresexplicitcommunication(send-receive)Q:Howdowemake“distributedcomputinglookliketraditional(centralized)computing”?Canweuseprocedurecalls?AcallsB->Asuspended,Bexecutes->Breturns,Aexecutes
?InformationfromA(caller)toB(callee)transferredusingparameters
?SomewhateasiersincebothcallerandcalleeexecuteinthesameaddressspaceRemoteProcedureCall(RPC)Cli10ConventionalProcedureCallParameterpassinginalocalprocedurecall:thestackbeforethecalltoread(fd,buf,nbytes)Thestackwhilethecalledprocedureisactive(執(zhí)行時(shí))調(diào)用方(主程序)把參數(shù)、返回地址反序壓入堆棧ConventionalProcedureCallPar11RPCInDistributedsystems:thecalleemaybeonadifferentsystem
-RemoteProcedurecall(RPC,允許程序調(diào)用位于其它機(jī)器上的進(jìn)程)-NOEXPLICITMESSAGEPASSING(對(duì)編程人員)
從而達(dá)到隱藏通信(send和receive),實(shí)現(xiàn)分布式系統(tǒng)中的訪問(wèn)透明性Goal:MakeRPClook(asmuchaspossible)likelocalprocedurecall
-allowremoteservicestobecalledasprocedures-callershouldnotbeawareofthefactthatthecalleeis(executing)onadifferentmachine(orviceversa)Althoughnomessagepassing(atuserlevel),parametersmuststillbepassed&resultsmuststillbereturned!RPCInDistributedsystems:the12ClientandServerStubsPrincipleofRPCbetweenaclientandserverprogram.
客戶通過(guò)執(zhí)行普通的(本地)過(guò)程調(diào)用來(lái)訪問(wèn)遠(yuǎn)程服務(wù),它并不需要直接調(diào)用Send和Receive,消息傳遞的所有細(xì)節(jié)都隱藏在雙方的庫(kù)過(guò)程(Stub,Skeleton)中。ClientandServerStubs13StepsofaremoteprocedurecallClientprocedurecallsclientstubinnormalwayClientstubbuildsmessage,callslocalOSClient’sOSsendsmessagetoremoteOSRemoteOSgivesmessagetoserverstubServerstubunpacksparameters,callsserverServerdoeswork,returnsresulttothestubServerstubpacksitinmessage,callslocalOSServer’sOSsendsmessagetoclient’sOSClient’sOSgivesmessagetoclientstubStubunpacksresult,returnstoclientStepsofaremoteprocedureca14PassingValueParameters(1)StepsinvolvedindoingremotecomputationthroughRPC2-8PassingValueParameters(1)2-15PassingValueParameters(2)Problem:differentmachineshavedifferentdataformats-Intel:littleendian,SPARC:bigendianSolution:useastandardrepresentation-Example:externaldatarepresentation(XDR)PassingValueParameters(2)Pr16Marshalling:ReferenceParametersProblem:howdowepasspointers?
(指針只在它被使用的進(jìn)程的地址空間里面是有意義的)-Ifitpointstoawell-defineddatastructure,passacopytotheserverandtheserverstubpasses(使用)
apointertothelocalcopy
(來(lái)調(diào)用服務(wù)器程序)Whataboutdatastructurescontainingpointers?-Prohibit-Copy/restore,
machineindependentrepresentationCallbyCopy/restore:
首先由調(diào)用者將變量拷貝到Stack,調(diào)用完成之后,將堆棧中的變量復(fù)制回去覆蓋調(diào)用方該變量原先的值。參數(shù)從客戶發(fā)送到服務(wù)器,在那里修改,然后發(fā)送回客戶,覆蓋原來(lái)的值。
Marshalling(編組,即把參數(shù)打包進(jìn)消息中發(fā)送到服務(wù)器):transformparameters/resultsintoabytestreamMarshalling:ReferenceParamet17BindingProblem:howdoesaclientlocateaserver?
(Client要發(fā)送消息到服務(wù)器,它需要知道服務(wù)器的地址)-UseBindingsServer-Exportserverinterfaceduringinitialization-Sendname,version#,uniqueidentifier,handle(address)tobinderClient(第一次調(diào)用遠(yuǎn)程過(guò)程,還沒(méi)有綁定到一個(gè)Server)-FirstRPC:sendmsgtobindertoimportserverinterface-Binder:checktoseeifsomeserverhasexportedtheinterface
?ReturnhandleanduniqueidentifiertoclientBinder充當(dāng)一個(gè)注冊(cè)服務(wù)器的角色。BindingProblem:howdoesacli18Binding:CommentsMethodflexible-canhandlemultipleserverswithsameinterface-bindercanpollaservertoseeifitisupandmayderegisteritifitisdownforfaulttolerance-canenforceauthentication(notgivinginterfacetousernotonlist)ExportingandimportingincursoverheadsBindercanbeabottleneck-UsemultiplebindersBindercandoloadbalancing
隨機(jī)地?cái)U(kuò)展(散播)Clients到這些Servers來(lái)平衡負(fù)載。Binding:CommentsMethodflexib19AsynchronousRPC(1)TheinterconnectionbetweenclientandserverinatraditionalRPCTheinteractionusingasynchronousRPC2-12AsynchronousRPC(1)Theinterc20AsynchronousRPC(2)AclientandserverinteractingthroughtwoasynchronousRPCs2-13AsynchronousRPC(2)2-1321WritingaClientandaServerThestepsinwritingaclientandaserverinDCERPC.2-14WritingaClientandaServerT22BindingaClienttoaServerClient-to-serverbindinginDCE.2-15BindingaClienttoaServer2-23RemoteMethodInvocation(RMI)RPCsappliedto(distributed)objects,i.e.,instancesofaclass-Class:object-orientedabstraction;modulewithdataandoperations-Separationbetweeninterfaceandimplementation-Interfaceresidesononemachine,implementationonanotherRMIssupportsystem-wideobjectreferences-ParameterscanbeobjectreferencesRemoteMethodInvocation(RMI)24DistributedObjectsWhenaclientbindstoadistributedobject,loadtheinterface(“proxy”)intoclientaddressspace-ProxyanalogoustostubsServerstubisreferredtoasaskeletonClientOSClientinvokesamethodClientServerOSSkeletonServerStateMethodInterfaceProxySkeletoninvokessamemethodatobjectSameinterfaceasobjectClientmachineServermachineObjectNetworkMarshalledinvocationispassedacrossnetworkDistributedObjectsClientOSCl25ProxiesandSkeletonsProxy:clientstub-MaintainsserverID,endpoint,objectID-Setsupandtearsdownconnectionwiththeserver-Doesserializationoflocalobjectparameters-Inpractice,canbedownloaded/constructedontheflySkeleton:serverstub-DoesdeserializationandpassesparameterstoserverandsendsresulttoproxyProxiesandSkeletonsProxy:cl26BindingaClienttoanObjectAnexamplewithimplicitbindingusingonlyglobalreferencesAnexamplewithexplicitbindingusingglobalandlocalreferencesDistr_object*obj_ref; //Declareasystemwideobjectreference
obj_ref=…; //Initializethereferencetoadistributedobject
obj_ref->do_something(); //Implicitlybindandinvokeamethod (a)Distr_objectobjPref; //Declareasystemwideobjectreference
Local_object*obj_ptr; //Declareapointertolocalobjects
obj_ref=…; //Initializethereferencetoadistributedobject
obj_ptr=bind(obj_ref); //Explicitlybindandobtainapointertothelocalproxy
obj_ptr->do_something(); //Invokeamethodonthelocalproxy (b)BindingaClienttoanObjectA27ParameterPassingThesituationwhenpassinganobjectbyreferenceorbyvalue.2-18ParameterPassingThesituation28TheDCEDistributed-ObjectModelDistributeddynamicobjectsinDCE.Distributednamedobjects2-19TheDCEDistributed-ObjectMod29面向消息的通信遠(yuǎn)程過(guò)程調(diào)用和遠(yuǎn)程對(duì)象調(diào)用都有助于隱藏分布式系統(tǒng)中的通信,也就是說(shuō)增強(qiáng)了訪問(wèn)透明性。不幸的是,這兩種機(jī)制并不總是適用的。特別是當(dāng)無(wú)法保證發(fā)出請(qǐng)求時(shí)接收端一定正在執(zhí)行的情況下,就必須有其他的通信服務(wù)。同時(shí),RPC和RMI的同步特性也會(huì)造成客戶在發(fā)出的請(qǐng)求得到處理之前被阻塞,因而有時(shí)也需要采取其他辦法。這里所說(shuō)的“其他方法”就是消息傳遞機(jī)制。面向消息的通信遠(yuǎn)程過(guò)程調(diào)用和遠(yuǎn)程對(duì)象調(diào)用都有助于隱藏分布式系30Message-orientedcommunication-Persistenceandsynchronicity-Message-orientedtransientcommunication
?Berkeleysocket
?MPI-Message-orientedpersistentcommunicationmessage?MessagequeuingsystemsMessage-orientedcommunication31持久通信與暫時(shí)通信持久(persistent)通信需要傳輸?shù)南⒃谔峤恢笥赏ㄐ畔到y(tǒng)來(lái)存儲(chǔ),直到將其交付給接收者為止。即在將消息成功交付給下一個(gè)通信服務(wù)器之前,消息一直存儲(chǔ)在通信服務(wù)器中。其典型例子是電子郵件系統(tǒng)。暫時(shí)(transient)通信通信系統(tǒng)只在發(fā)送和接收消息的應(yīng)用程序的運(yùn)行期間存儲(chǔ)消息。更準(zhǔn)確地說(shuō),如果通信服務(wù)器無(wú)法將消息遞送到下一個(gè)服務(wù)器或者接收者,消息將會(huì)被簡(jiǎn)單地丟棄。持久通信與暫時(shí)通信持久(persistent)通信32異步通信與同步通信異步通信發(fā)送者把要傳輸?shù)南⑻峤恢罅⒓蠢^續(xù)執(zhí)行其其他程序,這意味著該消息存儲(chǔ)在位于發(fā)送端主機(jī)的本地緩沖區(qū)中,或者存儲(chǔ)在送達(dá)的第一個(gè)通信服務(wù)器上的緩沖區(qū)中。同步通信發(fā)送者在提交消息之后會(huì)被阻塞,直到消息已經(jīng)到達(dá)并存儲(chǔ)在接收主機(jī)的本地緩沖區(qū)中以后,也就是消息確實(shí)已經(jīng)傳送到接收者之后,才會(huì)繼續(xù)執(zhí)行其它程序。異步通信與同步通信異步通信33PersistenceandSynchronicity:CommentsTransientsynchronouscomm:response-based=>weakerforms,suchasdelivery-basedandreply-basedTransientasynchronouscomm:message-passingsystemsPersistentcomm:developingofmiddlewareforlarge-scaleinterconnectednetworks;failuremaskingandrecoveryPersistenceandSynchronicity:34Message-orientedTransientComm.Manydistributedsystemsbuiltontopofsimplemessage-orientedmodel-Example:Berkeleysockets-AsocketisanabstractrepresentationofacommunicationendpointPrimitiveMeaningSocketCreateanewcommunicationendpointBindAttachalocaladdresstoasocketListenAnnouncewillingnesstoacceptconnectionsAcceptBlockcalleruntilaconnectionrequestarrivesConnectActivelyattempttoestablishaconnectionSendSendsomedataovertheconnectionReceiveReceivesomedataovertheconnectionCloseReleasetheconnectionSocketprimitivesforTCP/IP.Message-orientedTransientCom35BerkeleySocketsConnection-orientedcommunicationpatternusingsockets.BerkeleySocketsConnection-or36TheMessage-Passing
Interface(MPI)Someofthemostintuitivemessage-passingprimitivesofMPI.PrimitiveMeaningMPI_bsendAppendoutgoingmessagetoalocalsendbufferMPI_sendSendamessageandwaituntilcopiedtolocalorremotebufferMPI_ssendSendamessageandwaituntilreceiptstartsMPI_sendrecvSendamessageandwaitforreplyMPI_isendPassreferencetooutgoingmessage,andcontinueMPI_issendPassreferencetooutgoingmessage,andwaituntilreceiptstartsMPI_recvReceiveamessage;blockiftherearenoneMPI_irecvCheckifthereisanincomingmessage,butdonotblockTheMessage-Passing
Interface37Message-orientedPersistentComm.MessagequeuingsystemsorMessage-OrientedMiddleware(MOM)-Supportasynchronouspersistentcommunication-Intermediatestorageformessagewhilesender/receiverareinactive-Exampleapplication:email-支持那些時(shí)間要求較為寬松的消息傳輸,比如那些要求幾分鐘完成的傳輸,而適用于那些必須在幾秒內(nèi)甚至幾微秒內(nèi)完成的傳輸。(不同于Socket及MPI)Message-orientedPersistentCo38Message-QueuingModel(1)Communicatebyinsertingmessagesinqueues消息由一系列通信服務(wù)器依次進(jìn)行轉(zhuǎn)發(fā),最終送達(dá)目的地。即使在消息發(fā)送過(guò)程中接受者的機(jī)器未處于運(yùn)行狀態(tài),消息也能送到。原則上,每一個(gè)應(yīng)用程序都擁有歸其私有的消息隊(duì)列,其他應(yīng)用程序可以發(fā)送消息到該隊(duì)列中。隊(duì)列只能由相應(yīng)的(也就是擁有該隊(duì)列的應(yīng)用程序)讀取,但是也可能有多個(gè)應(yīng)用程序共享單個(gè)隊(duì)列。Senderisonlyguaranteedthatmessagewillbeeventuallyinsertedinrecipient'squeue-NoguaranteesonwhenarrivingorifthemessagewillbereadMessage-QueuingModel(1)Commu39Message-QueuingModel(2)Fourcombinationsforloosely-coupledcommunicationsusingqueues.2-26Looselycoupledcommunication
消息進(jìn)入接收者的消息隊(duì)列時(shí),接收者不必處于運(yùn)行狀態(tài);即使發(fā)送者沒(méi)有運(yùn)行,接收者也可以讀出發(fā)送給它的消息。發(fā)送者和接收者可以彼此完全獨(dú)立地運(yùn)行。Message-QueuingModel(2)Four40Message-QueuingModel(3)Basicinterfacetoaqueueinamessage-queuingsystem.PrimitiveMeaningPutAppendamessagetoaspecifiedqueueGetBlockuntilthespecifiedqueueisnonempty,andremovethefirstmessagePollCheckaspecifiedqueueformessages,andremovethefirst.Neverblock.NotifyInstallahandlertobecalledwhenamessageisputintothespecifiedqueue.Message-QueuingModel(3)Basic41Example:CommunicationSystem主機(jī)通過(guò)網(wǎng)絡(luò)相連的通信系統(tǒng)的一般組織結(jié)構(gòu)Example:CommunicationSystem主42消息隊(duì)列系統(tǒng)消息由(發(fā)送者的)源隊(duì)列向(接收者的)目的隊(duì)列傳輸。全部隊(duì)列的集合是分布在多臺(tái)機(jī)器上的,因此,對(duì)于要傳輸消息的消息隊(duì)列系統(tǒng)來(lái)說(shuō),他應(yīng)該維護(hù)一個(gè)由隊(duì)列到其所在網(wǎng)絡(luò)位置之間的映射關(guān)系,即維護(hù)一個(gè)存儲(chǔ)網(wǎng)絡(luò)位置(IP地址)所對(duì)應(yīng)的隊(duì)列名的數(shù)據(jù)庫(kù)。消息隊(duì)列系統(tǒng)消息由(發(fā)送者的)源隊(duì)列向(接收者的)目的隊(duì)列傳43GeneralArchitectureofaMessage-QueuingSystem(1)Therelationshipbetweenqueue-leveladdressingandnetwork-leveladdressing.GeneralArchitectureofaMess44隊(duì)列由隊(duì)列管理器來(lái)管理。一般來(lái)說(shuō),隊(duì)列管理器與發(fā)送或者接收消息的應(yīng)用程序直接交互。然而,也有一些特殊的隊(duì)列管理器發(fā)揮了路由器或者中繼器的作用:他們將輸入的消息轉(zhuǎn)發(fā)給其他的隊(duì)列管理器。一種解決方案是,使用若干了解網(wǎng)絡(luò)拓?fù)涞穆酚善?。如果發(fā)送者A將目的地為B的消息放入其本地隊(duì)列中,該消息將會(huì)首先傳輸?shù)阶钹徑穆酚善?,該路由器知道如何將該消息往B的方向轉(zhuǎn)發(fā)。GeneralArchitectureofaMessage-QueuingSystem(2)隊(duì)列由隊(duì)列管理器來(lái)管理。一般來(lái)說(shuō),隊(duì)列管理器與發(fā)送或者接收消45GeneralArchitectureofaMessage-QueuingSystem(3)Thegeneralorganizationofamessage-queuingsystemwithrouters.2-29GeneralArchitectureofaMess46Stream-orientedcommunication隨著多媒體分布式系統(tǒng)的出現(xiàn),必須引入流(stream)的概念,以支持連續(xù)媒體的通信。-Datastream-Qualityofservices-StreamsynchronizationStream-orientedcommunication隨47DataStreamAdatastreamisasequenceofdataunitsDiscreteorcontinuous:-Discretestream:UNIXpipesorTCP/IPconnections-Continuousstream:audioorvideo(同步非常關(guān)鍵)Forcontinuousstream,threetransmissionmodes:-Asynchronoustransmissionmode:thedataitemsaretransmittedoneaftertheother,buttherearenofurthertimingconstraintsonwhentransmissionshouldtakeplace-Synchronoustransmissionmode:thereisamaximumend-to-enddelaydefinedforeachunitinadatastream-Isochronous(等時(shí))
transmissionmode:dataunitsaretransferredontime,haveamaximumandminimumend-to-enddelayDataStreamAdatastreamisa48
(a)通過(guò)網(wǎng)絡(luò)在兩個(gè)進(jìn)程間建立流連接(b)在兩個(gè)設(shè)備間直接建立流連接分布式系統(tǒng)中的通信課件49ReadingMaterials
“DistributedSystems:PrinciplesandParadigms”byTanenbaumandVanSteen,PrenticeHall2002“DistributedSystems:ConceptsandDesign”byGeorgeCoulourisetc.,Addison-Wesley2001(Thirdedition)分布式系統(tǒng)設(shè)計(jì),(美)JieWu著,高傳善等譯,機(jī)械工業(yè)出版社,2001分布式操作系統(tǒng),AndrewS.Tanenbaum著,電子工業(yè)出版社,1999ReadingMaterials50分布式系統(tǒng)中的通信進(jìn)程間通信是一切分布式系統(tǒng)的核心。分布式系統(tǒng)中的通信都是基于底層網(wǎng)絡(luò)提供的低層消息傳遞機(jī)制的。通過(guò)消息傳遞來(lái)描述通信過(guò)程比使用基于共享存儲(chǔ)器的原語(yǔ)來(lái)描述要更困難。分布式系統(tǒng)中的通信進(jìn)程間通信是一切分布式系統(tǒng)的核心。514種廣泛使用的通信模型遠(yuǎn)程過(guò)程調(diào)用(remoteprocedurecall,RPC)遠(yuǎn)程方法調(diào)用(remotemethodinvocation,RMI)面向消息的中間件(message-orientedmiddleware,MOM)面向流的通信(stream-orientedcommunication)4種廣泛使用的通信模型52CommunicationProtocols
由于沒(méi)有共享存儲(chǔ)器,分布式系統(tǒng)中的所有通信都是基于(低層)消息交換的。Protocolsareagreements/rulesoncommunicationProtocolscouldbeconnection-orientedorconnectionlessApplicationPresentationSessionTransportNetworkDatalinkPhysicalApplicationprotocolPresentationprotocolSessionprotocolTransportprotocolNetworkprotocolDatalinkprotocolPhysicalprotocolNetwork7654321CommunicationProtocols由于沒(méi)53LayeredProtocolsAtypicalmessageasitappearsonthenetwork.2-2LayeredProtocolsAtypicalmes54DataLinkLayerDiscussionbetweenareceiverandasenderinthedatalinklayer.2-3DataLinkLayerDiscussionbetw55Client-ServerInteractionusingTCPNormaloperationofTCP(常規(guī)TCP的許多開(kāi)銷(xiāo)都耗費(fèi)在連接的管理上).TransactionalTCP(更經(jīng)濟(jì)的方式).2-4服務(wù)器執(zhí)行請(qǐng)求的操作告訴服務(wù)器關(guān)閉該連接客戶啟動(dòng)連接建立過(guò)程1,2,3要求客戶釋放連接將發(fā)送請(qǐng)求當(dāng)作連接的建立標(biāo)志(一個(gè)消息包含三條信息)把送回結(jié)果當(dāng)作連接的關(guān)閉標(biāo)志確認(rèn)連接的終止確認(rèn)已收到客戶的請(qǐng)求Client-ServerInteractionusin56MiddlewareProtocolsMiddleware:-Anapplicationthatlogicallylivesintheapplicationlayer-Containsmanygeneral-purposeprotocolsthatwarrant(代表)
theirownlayers-(會(huì)話層和表示層由一個(gè)單一的中間件層代替)ApplicationMiddlewareTransportNetworkDatalinkPhysicalApplicationprotocolMiddlewareprotocolTransportprotocolNetworkprotocolDatalinkprotocolPhysicalprotocolNetwork654321MiddlewareProtocolsMiddleware57Client-ServerCommunicationModelStructure:groupofserversofferingservicetoclients-Servers:offerservicestotheuserscalled“clients”-Clients:applicationsrequiringservicesfromservers-Example:WebServer/clients,Fileserver…Whyuseclient-servermodel-simplicity-low(er)overheadsclientkernelfileserverkernelprocessserverkernelterminalserverkernelClient-ServerCommunicationMo58Client-ServerCommunicationModelBasedonarequest/responseparadigm-Clientssendarequestaskingforservice(e.g.,afileblock)-Serverprocessesandreplieswithresult(orerror)Techniques:-Socket,RemoteProcedureCalls(RPC),RemoteMethodInvocation(RMI)
clientkernelfileserverkernelprocessserverkernelterminalserverkernelClient-ServerCommunicationMo59RemoteProcedureCall(RPC)Client-ServerprovidesamechanismforservicesindistributedsystemsBUT-requiresexplicitcommunication(send-receive)Q:Howdowemake“distributedcomputinglookliketraditional(centralized)computing”?Canweuseprocedurecalls?AcallsB->Asuspended,Bexecutes->Breturns,Aexecutes
?InformationfromA(caller)toB(callee)transferredusingparameters
?SomewhateasiersincebothcallerandcalleeexecuteinthesameaddressspaceRemoteProcedureCall(RPC)Cli60ConventionalProcedureCallParameterpassinginalocalprocedurecall:thestackbeforethecalltoread(fd,buf,nbytes)Thestackwhilethecalledprocedureisactive(執(zhí)行時(shí))調(diào)用方(主程序)把參數(shù)、返回地址反序壓入堆棧ConventionalProcedureCallPar61RPCInDistributedsystems:thecalleemaybeonadifferentsystem
-RemoteProcedurecall(RPC,允許程序調(diào)用位于其它機(jī)器上的進(jìn)程)-NOEXPLICITMESSAGEPASSING(對(duì)編程人員)
從而達(dá)到隱藏通信(send和receive),實(shí)現(xiàn)分布式系統(tǒng)中的訪問(wèn)透明性Goal:MakeRPClook(asmuchaspossible)likelocalprocedurecall
-allowremoteservicestobecalledasprocedures-callershouldnotbeawareofthefactthatthecalleeis(executing)onadifferentmachine(orviceversa)Althoughnomessagepassing(atuserlevel),parametersmuststillbepassed&resultsmuststillbereturned!RPCInDistributedsystems:the62ClientandServerStubsPrincipleofRPCbetweenaclientandserverprogram.
客戶通過(guò)執(zhí)行普通的(本地)過(guò)程調(diào)用來(lái)訪問(wèn)遠(yuǎn)程服務(wù),它并不需要直接調(diào)用Send和Receive,消息傳遞的所有細(xì)節(jié)都隱藏在雙方的庫(kù)過(guò)程(Stub,Skeleton)中。ClientandServerStubs63StepsofaremoteprocedurecallClientprocedurecallsclientstubinnormalwayClientstubbuildsmessage,callslocalOSClient’sOSsendsmessagetoremoteOSRemoteOSgivesmessagetoserverstubServerstubunpacksparameters,callsserverServerdoeswork,returnsresulttothestubServerstubpacksitinmessage,callslocalOSServer’sOSsendsmessagetoclient’sOSClient’sOSgivesmessagetoclientstubStubunpacksresult,returnstoclientStepsofaremoteprocedureca64PassingValueParameters(1)StepsinvolvedindoingremotecomputationthroughRPC2-8PassingValueParameters(1)2-65PassingValueParameters(2)Problem:differentmachineshavedifferentdataformats-Intel:littleendian,SPARC:bigendianSolution:useastandardrepresentation-Example:externaldatarepresentation(XDR)PassingValueParameters(2)Pr66Marshalling:ReferenceParametersProblem:howdowepasspointers?
(指針只在它被使用的進(jìn)程的地址空間里面是有意義的)-Ifitpointstoawell-defineddatastructure,passacopytotheserverandtheserverstubpasses(使用)
apointertothelocalcopy
(來(lái)調(diào)用服務(wù)器程序)Whataboutdatastructurescontainingpointers?-Prohibit-Copy/restore,
machineindependentrepresentationCallbyCopy/restore:
首先由調(diào)用者將變量拷貝到Stack,調(diào)用完成之后,將堆棧中的變量復(fù)制回去覆蓋調(diào)用方該變量原先的值。參數(shù)從客戶發(fā)送到服務(wù)器,在那里修改,然后發(fā)送回客戶,覆蓋原來(lái)的值。
Marshalling(編組,即把參數(shù)打包進(jìn)消息中發(fā)送到服務(wù)器):transformparameters/resultsintoabytestreamMarshalling:ReferenceParamet67BindingProblem:howdoesaclientlocateaserver?
(Client要發(fā)送消息到服務(wù)器,它需要知道服務(wù)器的地址)-UseBindingsServer-Exportserverinterfaceduringinitialization-Sendname,version#,uniqueidentifier,handle(address)tobinderClient(第一次調(diào)用遠(yuǎn)程過(guò)程,還沒(méi)有綁定到一個(gè)Server)-FirstRPC:sendmsgtobindertoimportserverinterface-Binder:checktoseeifsomeserverhasexportedtheinterface
?ReturnhandleanduniqueidentifiertoclientBinder充當(dāng)一個(gè)注冊(cè)服務(wù)器的角色。BindingProblem:howdoesacli68Binding:CommentsMethodflexible-canhandlemultipleserverswithsameinterface-bindercanpollaservertoseeifitisupandmayderegisteritifitisdownforfaulttolerance-canenforceauthentication(notgivinginterfacetousernotonlist)ExportingandimportingincursoverheadsBindercanbeabottleneck-UsemultiplebindersBindercandoloadbalancing
隨機(jī)地?cái)U(kuò)展(散播)Clients到這些Servers來(lái)平衡負(fù)載。Binding:CommentsMethodflexib69AsynchronousRPC(1)TheinterconnectionbetweenclientandserverinatraditionalRPCTheinteractionusingasynchronousRPC2-12AsynchronousRPC(1)Theinterc70AsynchronousRPC(2)AclientandserverinteractingthroughtwoasynchronousRPCs2-13AsynchronousRPC(2)2-1371WritingaClientandaServerThestepsinwritingaclientandaserverinDCERPC.2-14WritingaClientandaServerT72BindingaClienttoaServerClient-to-serverbindinginDCE.2-15BindingaClienttoaServer2-73RemoteMethodInvocation(RMI)RPCsappliedto(distributed)objects,i.e.,instancesofaclass-Class:object-orientedabstraction;modulewithdataandoperations-Separationbetweeninterfaceandimplementation-Interfaceresidesononemachine,implementationonanotherRMIssupportsystem-wideobjectreferences-ParameterscanbeobjectreferencesRemoteMethodInvocation(RMI)74DistributedObjectsWhenaclientbindstoadistributedobject,loadtheinterface(“proxy”)intoclientaddressspace-ProxyanalogoustostubsServerstubisreferredtoasaskeletonClientOSClientinvokesamethodClientServerOSSkeletonServerStateMethodInterfaceProxySkeletoninvokessamemethodatobjectSameinterfaceasobjectClientmachineServermachineObjectNetworkMarshalledinvocationispassedacrossnetworkDistributedObjectsClientOSCl75ProxiesandSkeletonsProxy:clientstub-MaintainsserverID,endpoint,objectID-Setsupandtearsdownconnectionwiththeserver-Doesserializationoflocalobjectparameters-Inpractice,canbedownloaded/constructedontheflySkeleton:serverstub-DoesdeserializationandpassesparameterstoserverandsendsresulttoproxyProxiesandSkeletonsProxy:cl76BindingaClienttoanObjectAnexamplewithimplicitbindingusingonlyglobalreferencesAnexamplewithexplicitbindingusingglobalandlocalreferencesDistr_object*obj_ref; //Declareasystemwideobjectreference
obj_ref=…; //Initializethereferencetoadistributedobject
obj_ref->do_something(); //Implicitlybindandinvokeamethod (a)Distr_objectobjPref; //Declareasystemwideobjectreference
Local_object*obj_ptr; //Declareapointertolocalobjects
obj_ref=…; //Initializethereferencetoadistributedobject
obj_ptr=bind(obj_ref); //Explicitlybindandobtainapointertothelocalproxy
obj_ptr->do_something(); //Invokeamethodonthelocalproxy (b)BindingaClienttoanObjectA77ParameterPassingThesituationwhenpassinganobjectbyreferenceorbyvalue.2-18ParameterPassingThesituation78TheDCEDistributed-ObjectModelDistributeddynamicobjectsinDCE.Distributednamedobjects2-19TheDCEDistributed-ObjectMod79面向消息的通信遠(yuǎn)程過(guò)程調(diào)用和遠(yuǎn)程對(duì)象調(diào)用都有助于隱藏分布式系統(tǒng)中的通信,也就是說(shuō)增強(qiáng)了訪問(wèn)透明性。不幸的是,這兩種機(jī)制并不總是適用的。特別是當(dāng)無(wú)法保證發(fā)出請(qǐng)求時(shí)接收端一定正在執(zhí)行的情況下,就必須有其他的通信服務(wù)。同時(shí),RPC和RMI的同步特性也會(huì)造成客戶在發(fā)出的請(qǐng)求得到處理之前被阻塞,因而有時(shí)也需要采取其他辦法。這里所說(shuō)的“其他方法”就是消息傳遞機(jī)制。面向消息的通信遠(yuǎn)程過(guò)程調(diào)用和遠(yuǎn)程對(duì)象調(diào)用都有助于隱藏分布式系80Message-orientedcommunication-Persistenceandsynchronicity-Message-orientedtransientcommunication
?Berkeleysocket
?MPI-Message-orientedpersistentcommunicationmessage?MessagequeuingsystemsMessage-orientedcommunication81持久通信與暫時(shí)通信持久(persistent)通信需要傳輸?shù)南⒃谔峤恢笥赏ㄐ畔到y(tǒng)來(lái)存儲(chǔ),直到將其交付給接收者為止。即在將消息成功交付給下一個(gè)通信服務(wù)器之前,消息一直存儲(chǔ)在通信服務(wù)器中。其典型例子是電子郵件系統(tǒng)。暫時(shí)(transient)通信通信系統(tǒng)只在發(fā)送和接收消息的應(yīng)用程序的運(yùn)行期間存儲(chǔ)消息。更準(zhǔn)確地說(shuō),如果通信服務(wù)器無(wú)法將消息遞送到下一個(gè)服務(wù)器或者接收者,消息將會(huì)被簡(jiǎn)單地丟棄。持久通信與暫時(shí)通信持久(persistent)通信82異步通信與同步通信異步通信發(fā)送者把要傳輸?shù)南⑻峤恢罅⒓蠢^續(xù)執(zhí)行其其他程序,這意味著該消息存儲(chǔ)在位于發(fā)送端主機(jī)的本地緩沖區(qū)中,或者存儲(chǔ)在送達(dá)的第一個(gè)通信服務(wù)器上的緩沖區(qū)中。同步通信發(fā)送者在提交消息之后會(huì)被阻塞,直到消息已經(jīng)到達(dá)并存儲(chǔ)在接收主機(jī)的本地緩沖區(qū)中以后,也就是消息確實(shí)已經(jīng)傳送到接收者之后,才會(huì)繼續(xù)執(zhí)行其它程序。異步通信與同步通信異步通信83PersistenceandSynchronicity:CommentsTransientsynchronouscomm:response-based=>weakerforms,suchasdelivery-basedandreply-basedTransientasynchronouscomm:message-passingsystemsPersistentcomm:developingofmiddlewareforlarge-scaleinterconnectednetworks;failuremaskingandrecoveryPersistenceandSynchronicity:84Message-orientedTransientComm.Manydistributedsystemsbuiltontopofsimplemessage-orientedmodel-Example:Berkeleysockets-AsocketisanabstractrepresentationofacommunicationendpointPrimitiveMeaningSocketCreateanewcommunicationendpointBindAttachalocaladdresstoasocketListenAnnouncewillingnesstoacceptconnectionsAcceptBlockcalleruntilaconnectionrequestarrivesConnectAc
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 安全生產(chǎn)月活動(dòng)開(kāi)展情況展板
- 2024屆護(hù)理專業(yè)研究生招生計(jì)劃
- 機(jī)械傷害培訓(xùn)
- 防偷課件下載
- 文庫(kù)發(fā)布:防倒桿課件
- 有獎(jiǎng)知識(shí)競(jìng)猜比賽
- 年產(chǎn)15萬(wàn)噸中藥材提取物及3萬(wàn)噸獸用提取物項(xiàng)目可行性研究報(bào)告寫(xiě)作模板-備案審批
- 混凝土雕塑施工方案
- 客戶信用管理培訓(xùn)
- 兒女養(yǎng)老的協(xié)議書(shū)
- 酒店升級(jí)改造方案
- 教師培訓(xùn)績(jī)效評(píng)價(jià)報(bào)告
- 淡季服裝促銷(xiāo)活動(dòng)方案
- 動(dòng)物飼養(yǎng)與養(yǎng)殖中的危險(xiǎn)源識(shí)別與風(fēng)險(xiǎn)評(píng)估
- 2023版靜脈治療護(hù)理技術(shù)操作標(biāo)準(zhǔn)(WST 433-2023)解讀
- 酒店投資項(xiàng)目融資計(jì)劃書(shū)
- 深圳市建筑工務(wù)署材料設(shè)備參考品牌庫(kù)(更新至2019年11月27日)
- 公安機(jī)關(guān)辦理行政案件程序規(guī)定專業(yè)考試題庫(kù)
- 人教版新教材高中英語(yǔ)選擇性必修四全冊(cè)單詞語(yǔ)境記憶(復(fù)習(xí)必背)
- 西藏自治區(qū)班戈縣班嘎錯(cuò)、(3湖)鹽湖液體礦補(bǔ)充勘查環(huán)評(píng)報(bào)告
- 光伏斜屋頂計(jì)算書(shū)屋頂光伏電站項(xiàng)目荷載計(jì)算書(shū)
評(píng)論
0/150
提交評(píng)論