![分布式系統(tǒng)中的通信課件_第1頁](http://file4.renrendoc.com/view/a0f98cc08b987939a79890439608c272/a0f98cc08b987939a79890439608c2721.gif)
![分布式系統(tǒng)中的通信課件_第2頁](http://file4.renrendoc.com/view/a0f98cc08b987939a79890439608c272/a0f98cc08b987939a79890439608c2722.gif)
![分布式系統(tǒng)中的通信課件_第3頁](http://file4.renrendoc.com/view/a0f98cc08b987939a79890439608c272/a0f98cc08b987939a79890439608c2723.gif)
![分布式系統(tǒng)中的通信課件_第4頁](http://file4.renrendoc.com/view/a0f98cc08b987939a79890439608c272/a0f98cc08b987939a79890439608c2724.gif)
![分布式系統(tǒng)中的通信課件_第5頁](http://file4.renrendoc.com/view/a0f98cc08b987939a79890439608c272/a0f98cc08b987939a79890439608c2725.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
分布式系統(tǒng)中的通信進(jìn)程間通信是一切分布式系統(tǒng)的核心。分布式系統(tǒng)中的通信都是基于底層網(wǎng)絡(luò)提供的低層消息傳遞機制的。通過消息傳遞來描述通信過程比使用基于共享存儲器的原語來描述要更困難。分布式系統(tǒng)中的通信進(jìn)程間通信是一切分布式系統(tǒng)的核心。14種廣泛使用的通信模型遠(yuǎn)程過程調(diào)用(remoteprocedurecall,RPC)遠(yuǎn)程方法調(diào)用(remotemethodinvocation,RMI)面向消息的中間件(message-orientedmiddleware,MOM)面向流的通信(stream-orientedcommunication)4種廣泛使用的通信模型2CommunicationProtocols
由于沒有共享存儲器,分布式系統(tǒng)中的所有通信都是基于(低層)消息交換的。Protocolsareagreements/rulesoncommunicationProtocolscouldbeconnection-orientedorconnectionlessApplicationPresentationSessionTransportNetworkDatalinkPhysicalApplicationprotocolPresentationprotocolSessionprotocolTransportprotocolNetworkprotocolDatalinkprotocolPhysicalprotocolNetwork7654321CommunicationProtocols由于沒3LayeredProtocolsAtypicalmessageasitappearsonthenetwork.2-2LayeredProtocolsAtypicalmes4DataLinkLayerDiscussionbetweenareceiverandasenderinthedatalinklayer.2-3DataLinkLayerDiscussionbetw5Client-ServerInteractionusingTCPNormaloperationofTCP(常規(guī)TCP的許多開銷都耗費在連接的管理上).TransactionalTCP(更經(jīng)濟(jì)的方式).2-4服務(wù)器執(zhí)行請求的操作告訴服務(wù)器關(guān)閉該連接客戶啟動連接建立過程1,2,3要求客戶釋放連接將發(fā)送請求當(dāng)作連接的建立標(biāo)志(一個消息包含三條信息)把送回結(jié)果當(dāng)作連接的關(guān)閉標(biāo)志確認(rèn)連接的終止確認(rèn)已收到客戶的請求Client-ServerInteractionusin6MiddlewareProtocolsMiddleware:-Anapplicationthatlogicallylivesintheapplicationlayer-Containsmanygeneral-purposeprotocolsthatwarrant(代表)
theirownlayers-(會話層和表示層由一個單一的中間件層代替)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í)行時)調(diào)用方(主程序)把參數(shù)、返回地址反序壓入堆棧ConventionalProcedureCallPar11RPCInDistributedsystems:thecalleemaybeonadifferentsystem
-RemoteProcedurecall(RPC,允許程序調(diào)用位于其它機器上的進(jìn)程)-NOEXPLICITMESSAGEPASSING(對編程人員)
從而達(dá)到隱藏通信(send和receive),實現(xiàn)分布式系統(tǒng)中的訪問透明性Goal:MakeRPClook(asmuchaspossible)likelocalprocedurecall
-allowremoteservicestobecalledasprocedures-callershouldnotbeawareofthefactthatthecalleeis(executing)onadifferentmachine(orviceversa)Althoughnomessagepassing(atuserlevel),parametersmuststillbepassed&resultsmuststillbereturned!RPCInDistributedsystems:the12ClientandServerStubsPrincipleofRPCbetweenaclientandserverprogram.
客戶通過執(zhí)行普通的(本地)過程調(diào)用來訪問遠(yuǎn)程服務(wù),它并不需要直接調(diào)用Send和Receive,消息傳遞的所有細(xì)節(jié)都隱藏在雙方的庫過程(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
(來調(diào)用服務(wù)器程序)Whataboutdatastructurescontainingpointers?-Prohibit-Copy/restore,
machineindependentrepresentationCallbyCopy/restore:
首先由調(diào)用者將變量拷貝到Stack,調(diào)用完成之后,將堆棧中的變量復(fù)制回去覆蓋調(diào)用方該變量原先的值。參數(shù)從客戶發(fā)送到服務(wù)器,在那里修改,然后發(fā)送回客戶,覆蓋原來的值。
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)程過程,還沒有綁定到一個Server)-FirstRPC:sendmsgtobindertoimportserverinterface-Binder:checktoseeifsomeserverhasexportedtheinterface
?ReturnhandleanduniqueidentifiertoclientBinder充當(dāng)一個注冊服務(wù)器的角色。BindingProblem:howdoesacli18Binding:CommentsMethodflexible-canhandlemultipleserverswithsameinterface-bindercanpollaservertoseeifitisupandmayderegisteritifitisdownforfaulttolerance-canenforceauthentication(notgivinginterfacetousernotonlist)ExportingandimportingincursoverheadsBindercanbeabottleneck-UsemultiplebindersBindercandoloadbalancing
隨機地擴(kuò)展(散播)Clients到這些Servers來平衡負(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)程過程調(diào)用和遠(yuǎn)程對象調(diào)用都有助于隱藏分布式系統(tǒng)中的通信,也就是說增強了訪問透明性。不幸的是,這兩種機制并不總是適用的。特別是當(dāng)無法保證發(fā)出請求時接收端一定正在執(zhí)行的情況下,就必須有其他的通信服務(wù)。同時,RPC和RMI的同步特性也會造成客戶在發(fā)出的請求得到處理之前被阻塞,因而有時也需要采取其他辦法。這里所說的“其他方法”就是消息傳遞機制。面向消息的通信遠(yuǎn)程過程調(diào)用和遠(yuǎn)程對象調(diào)用都有助于隱藏分布式系30Message-orientedcommunication-Persistenceandsynchronicity-Message-orientedtransientcommunication
?Berkeleysocket
?MPI-Message-orientedpersistentcommunicationmessage?MessagequeuingsystemsMessage-orientedcommunication31持久通信與暫時通信持久(persistent)通信需要傳輸?shù)南⒃谔峤恢笥赏ㄐ畔到y(tǒng)來存儲,直到將其交付給接收者為止。即在將消息成功交付給下一個通信服務(wù)器之前,消息一直存儲在通信服務(wù)器中。其典型例子是電子郵件系統(tǒng)。暫時(transient)通信通信系統(tǒng)只在發(fā)送和接收消息的應(yīng)用程序的運行期間存儲消息。更準(zhǔn)確地說,如果通信服務(wù)器無法將消息遞送到下一個服務(wù)器或者接收者,消息將會被簡單地丟棄。持久通信與暫時通信持久(persistent)通信32異步通信與同步通信異步通信發(fā)送者把要傳輸?shù)南⑻峤恢罅⒓蠢^續(xù)執(zhí)行其其他程序,這意味著該消息存儲在位于發(fā)送端主機的本地緩沖區(qū)中,或者存儲在送達(dá)的第一個通信服務(wù)器上的緩沖區(qū)中。同步通信發(fā)送者在提交消息之后會被阻塞,直到消息已經(jīng)到達(dá)并存儲在接收主機的本地緩沖區(qū)中以后,也就是消息確實已經(jīng)傳送到接收者之后,才會繼續(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-支持那些時間要求較為寬松的消息傳輸,比如那些要求幾分鐘完成的傳輸,而適用于那些必須在幾秒內(nèi)甚至幾微秒內(nèi)完成的傳輸。(不同于Socket及MPI)Message-orientedPersistentCo38Message-QueuingModel(1)Communicatebyinsertingmessagesinqueues消息由一系列通信服務(wù)器依次進(jìn)行轉(zhuǎn)發(fā),最終送達(dá)目的地。即使在消息發(fā)送過程中接受者的機器未處于運行狀態(tài),消息也能送到。原則上,每一個應(yīng)用程序都擁有歸其私有的消息隊列,其他應(yīng)用程序可以發(fā)送消息到該隊列中。隊列只能由相應(yīng)的(也就是擁有該隊列的應(yīng)用程序)讀取,但是也可能有多個應(yīng)用程序共享單個隊列。Senderisonlyguaranteedthatmessagewillbeeventuallyinsertedinrecipient'squeue-NoguaranteesonwhenarrivingorifthemessagewillbereadMessage-QueuingModel(1)Commu39Message-QueuingModel(2)Fourcombinationsforloosely-coupledcommunicationsusingqueues.2-26Looselycoupledcommunication
消息進(jìn)入接收者的消息隊列時,接收者不必處于運行狀態(tài);即使發(fā)送者沒有運行,接收者也可以讀出發(fā)送給它的消息。發(fā)送者和接收者可以彼此完全獨立地運行。Message-QueuingModel(2)Four40Message-QueuingModel(3)Basicinterfacetoaqueueinamessage-queuingsystem.PrimitiveMeaningPutAppendamessagetoaspecifiedqueueGetBlockuntilthespecifiedqueueisnonempty,andremovethefirstmessagePollCheckaspecifiedqueueformessages,andremovethefirst.Neverblock.NotifyInstallahandlertobecalledwhenamessageisputintothespecifiedqueue.Message-QueuingModel(3)Basic41Example:CommunicationSystem主機通過網(wǎng)絡(luò)相連的通信系統(tǒng)的一般組織結(jié)構(gòu)Example:CommunicationSystem主42消息隊列系統(tǒng)消息由(發(fā)送者的)源隊列向(接收者的)目的隊列傳輸。全部隊列的集合是分布在多臺機器上的,因此,對于要傳輸消息的消息隊列系統(tǒng)來說,他應(yīng)該維護(hù)一個由隊列到其所在網(wǎng)絡(luò)位置之間的映射關(guān)系,即維護(hù)一個存儲網(wǎng)絡(luò)位置(IP地址)所對應(yīng)的隊列名的數(shù)據(jù)庫。消息隊列系統(tǒng)消息由(發(fā)送者的)源隊列向(接收者的)目的隊列傳43GeneralArchitectureofaMessage-QueuingSystem(1)Therelationshipbetweenqueue-leveladdressingandnetwork-leveladdressing.GeneralArchitectureofaMess44隊列由隊列管理器來管理。一般來說,隊列管理器與發(fā)送或者接收消息的應(yīng)用程序直接交互。然而,也有一些特殊的隊列管理器發(fā)揮了路由器或者中繼器的作用:他們將輸入的消息轉(zhuǎn)發(fā)給其他的隊列管理器。一種解決方案是,使用若干了解網(wǎng)絡(luò)拓?fù)涞穆酚善?。如果發(fā)送者A將目的地為B的消息放入其本地隊列中,該消息將會首先傳輸?shù)阶钹徑穆酚善鳎撀酚善髦廊绾螌⒃撓⑼鵅的方向轉(zhuǎn)發(fā)。GeneralArchitectureofaMessage-QueuingSystem(2)隊列由隊列管理器來管理。一般來說,隊列管理器與發(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(等時)
transmissionmode:dataunitsaretransferredontime,haveamaximumandminimumend-to-enddelayDataStreamAdatastreamisa48
(a)通過網(wǎng)絡(luò)在兩個進(jìn)程間建立流連接(b)在兩個設(shè)備間直接建立流連接分布式系統(tǒng)中的通信課件49ReadingMaterials
“DistributedSystems:PrinciplesandParadigms”byTanenbaumandVanSteen,PrenticeHall2002“DistributedSystems:ConceptsandDesign”byGeorgeCoulourisetc.,Addison-Wesley2001(Thirdedition)分布式系統(tǒng)設(shè)計,(美)JieWu著,高傳善等譯,機械工業(yè)出版社,2001分布式操作系統(tǒng),AndrewS.Tanenbaum著,電子工業(yè)出版社,1999ReadingMaterials50分布式系統(tǒng)中的通信進(jìn)程間通信是一切分布式系統(tǒng)的核心。分布式系統(tǒng)中的通信都是基于底層網(wǎng)絡(luò)提供的低層消息傳遞機制的。通過消息傳遞來描述通信過程比使用基于共享存儲器的原語來描述要更困難。分布式系統(tǒng)中的通信進(jìn)程間通信是一切分布式系統(tǒng)的核心。514種廣泛使用的通信模型遠(yuǎn)程過程調(diào)用(remoteprocedurecall,RPC)遠(yuǎn)程方法調(diào)用(remotemethodinvocation,RMI)面向消息的中間件(message-orientedmiddleware,MOM)面向流的通信(stream-orientedcommunication)4種廣泛使用的通信模型52CommunicationProtocols
由于沒有共享存儲器,分布式系統(tǒng)中的所有通信都是基于(低層)消息交換的。Protocolsareagreements/rulesoncommunicationProtocolscouldbeconnection-orientedorconnectionlessApplicationPresentationSessionTransportNetworkDatalinkPhysicalApplicationprotocolPresentationprotocolSessionprotocolTransportprotocolNetworkprotocolDatalinkprotocolPhysicalprotocolNetwork7654321CommunicationProtocols由于沒53LayeredProtocolsAtypicalmessageasitappearsonthenetwork.2-2LayeredProtocolsAtypicalmes54DataLinkLayerDiscussionbetweenareceiverandasenderinthedatalinklayer.2-3DataLinkLayerDiscussionbetw55Client-ServerInteractionusingTCPNormaloperationofTCP(常規(guī)TCP的許多開銷都耗費在連接的管理上).TransactionalTCP(更經(jīng)濟(jì)的方式).2-4服務(wù)器執(zhí)行請求的操作告訴服務(wù)器關(guān)閉該連接客戶啟動連接建立過程1,2,3要求客戶釋放連接將發(fā)送請求當(dāng)作連接的建立標(biāo)志(一個消息包含三條信息)把送回結(jié)果當(dāng)作連接的關(guān)閉標(biāo)志確認(rèn)連接的終止確認(rèn)已收到客戶的請求Client-ServerInteractionusin56MiddlewareProtocolsMiddleware:-Anapplicationthatlogicallylivesintheapplicationlayer-Containsmanygeneral-purposeprotocolsthatwarrant(代表)
theirownlayers-(會話層和表示層由一個單一的中間件層代替)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í)行時)調(diào)用方(主程序)把參數(shù)、返回地址反序壓入堆棧ConventionalProcedureCallPar61RPCInDistributedsystems:thecalleemaybeonadifferentsystem
-RemoteProcedurecall(RPC,允許程序調(diào)用位于其它機器上的進(jìn)程)-NOEXPLICITMESSAGEPASSING(對編程人員)
從而達(dá)到隱藏通信(send和receive),實現(xiàn)分布式系統(tǒng)中的訪問透明性Goal:MakeRPClook(asmuchaspossible)likelocalprocedurecall
-allowremoteservicestobecalledasprocedures-callershouldnotbeawareofthefactthatthecalleeis(executing)onadifferentmachine(orviceversa)Althoughnomessagepassing(atuserlevel),parametersmuststillbepassed&resultsmuststillbereturned!RPCInDistributedsystems:the62ClientandServerStubsPrincipleofRPCbetweenaclientandserverprogram.
客戶通過執(zhí)行普通的(本地)過程調(diào)用來訪問遠(yuǎn)程服務(wù),它并不需要直接調(diào)用Send和Receive,消息傳遞的所有細(xì)節(jié)都隱藏在雙方的庫過程(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
(來調(diào)用服務(wù)器程序)Whataboutdatastructurescontainingpointers?-Prohibit-Copy/restore,
machineindependentrepresentationCallbyCopy/restore:
首先由調(diào)用者將變量拷貝到Stack,調(diào)用完成之后,將堆棧中的變量復(fù)制回去覆蓋調(diào)用方該變量原先的值。參數(shù)從客戶發(fā)送到服務(wù)器,在那里修改,然后發(fā)送回客戶,覆蓋原來的值。
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)程過程,還沒有綁定到一個Server)-FirstRPC:sendmsgtobindertoimportserverinterface-Binder:checktoseeifsomeserverhasexportedtheinterface
?ReturnhandleanduniqueidentifiertoclientBinder充當(dāng)一個注冊服務(wù)器的角色。BindingProblem:howdoesacli68Binding:CommentsMethodflexible-canhandlemultipleserverswithsameinterface-bindercanpollaservertoseeifitisupandmayderegisteritifitisdownforfaulttolerance-canenforceauthentication(notgivinginterfacetousernotonlist)ExportingandimportingincursoverheadsBindercanbeabottleneck-UsemultiplebindersBindercandoloadbalancing
隨機地擴(kuò)展(散播)Clients到這些Servers來平衡負(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)程過程調(diào)用和遠(yuǎn)程對象調(diào)用都有助于隱藏分布式系統(tǒng)中的通信,也就是說增強了訪問透明性。不幸的是,這兩種機制并不總是適用的。特別是當(dāng)無法保證發(fā)出請求時接收端一定正在執(zhí)行的情況下,就必須有其他的通信服務(wù)。同時,RPC和RMI的同步特性也會造成客戶在發(fā)出的請求得到處理之前被阻塞,因而有時也需要采取其他辦法。這里所說的“其他方法”就是消息傳遞機制。面向消息的通信遠(yuǎn)程過程調(diào)用和遠(yuǎn)程對象調(diào)用都有助于隱藏分布式系80Message-orientedcommunication-Persistenceandsynchronicity-Message-orientedtransientcommunication
?Berkeleysocket
?MPI-Message-orientedpersistentcommunicationmessage?MessagequeuingsystemsMessage-orientedcommunication81持久通信與暫時通信持久(persistent)通信需要傳輸?shù)南⒃谔峤恢笥赏ㄐ畔到y(tǒng)來存儲,直到將其交付給接收者為止。即在將消息成功交付給下一個通信服務(wù)器之前,消息一直存儲在通信服務(wù)器中。其典型例子是電子郵件系統(tǒng)。暫時(transient)通信通信系統(tǒng)只在發(fā)送和接收消息的應(yīng)用程序的運行期間存儲消息。更準(zhǔn)確地說,如果通信服務(wù)器無法將消息遞送到下一個服務(wù)器或者接收者,消息將會被簡單地丟棄。持久通信與暫時通信持久(persistent)通信82異步通信與同步通信異步通信發(fā)送者把要傳輸?shù)南⑻峤恢罅⒓蠢^續(xù)執(zhí)行其其他程序,這意味著該消息存儲在位于發(fā)送端主機的本地緩沖區(qū)中,或者存儲在送達(dá)的第一個通信服務(wù)器上的緩沖區(qū)中。同步通信發(fā)送者在提交消息之后會被阻塞,直到消息已經(jīng)到達(dá)并存儲在接收主機的本地緩沖區(qū)中以后,也就是消息確實已經(jīng)傳送到接收者之后,才會繼續(xù)執(zhí)行其它程序。異步通信與同步通信異步通信83PersistenceandSynchronicity:CommentsTransientsynchronouscomm:response-based=>weakerforms,suchasdelivery-basedandreply-basedTransientasynchronouscomm:message-passingsystemsPersistentcomm:developingofmiddlewareforlarge-scaleinterconnectednetworks;failuremaskingandrecoveryPersistenceandSynchronicity:84Message-orientedTransientComm.Manydistributedsystemsbuiltontopofsimplemessage-orientedmodel-Example:Berkeleysockets-AsocketisanabstractrepresentationofacommunicationendpointPrimitiveMeaningSocketCreateanewcommunicationendpointBindAttachalocaladdresstoasocketListenAnnouncewillingnesstoacceptconnectionsAcceptBlockcalleruntilaconnectionrequestarrivesConnectAc
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2025學(xué)年七年級數(shù)學(xué)上冊第一章豐富的圖形世界1.4從三個方向看物體的形狀教案新版北師大版
- 蓋房子申請書
- 他哭了范文800字(81篇)
- 生產(chǎn)流程再造與成本控制的融合
- 休學(xué)休學(xué)申請書
- 2025年度洗車連鎖品牌加盟承包合同
- 2025年度廢棄物處理設(shè)施環(huán)保驗收與運維服務(wù)合同
- 訓(xùn)練隊申請書
- 退出申請書格式
- 貧困生補助申請書800字
- 中考數(shù)學(xué)計算題練習(xí)100道(2024年中考真題)
- 中國慢性腎臟病早期評價與管理指南2023
- 中藥材倉儲標(biāo)準(zhǔn)化與信息化建設(shè)
- 陰囊常見疾病的超聲診斷
- 2024屆高考數(shù)學(xué)高考總復(fù)習(xí):集合與常用邏輯用語集合的概念與運算
- DZ∕T 0051-2017 地質(zhì)巖心鉆機型式與規(guī)格系列(正式版)
- 《行業(yè)標(biāo)準(zhǔn)-太陽能光熱發(fā)電技術(shù)監(jiān)督導(dǎo)則》
- 壓力管道穿(跨)越施工工藝規(guī)程2015
- 業(yè)主授權(quán)租戶安裝充電樁委托書
- 建筑工人實名制管理制度及實施方案
- 《養(yǎng)老護(hù)理員》-課件:協(xié)助老年人穿脫簡易矯形器
評論
0/150
提交評論