分布式系统中的通信
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Client-Server Interaction using TCP
将发送请求当作连接的建立 标志(一个消息包含三条信息) 客户启动 连接建立 过程1,2,3
2-4
告诉服务器 关闭该连接 确认已收到客户的请求 要求客户 释放连接 服务器执行 请求的操作
把送回结果当作 连接的关闭标志 确认连接的终止
Application Application protocol Presentation protocol Session protocol Transport protocol Network protocol 7 6 5 4 3
Presentation
Session Transport
Network
Passing Value Parameters (1)
2-8
Steps involved in doing remote computation through RPC
Passing Value Parameters (2)
Problem: different machines
have different
Conventional Procedure Call
调用方 (主程序) 把参数、返回地 址反序压入堆栈
a) b)
Parameter passing in a local procedure call: the stack before the call to read(fd, buf, nbytes) The stack while the called procedure is active(执行时)
Binding
Problem: how does a client locate a server?
(Client要发送消息到服务器,它需要知道服务器的地址)
- Use Bindings Server - Export server interface during initialization - Send name, version #, unique identifier, handle (address) to binder Client (第一次调用远程过程,还没有绑定到一个Server) - First RPC: send msg to binder to import server interface - Binder: check to see if some server has exported the interface • Return handle and unique identifier to client
RPC
In Distributed systems: the callee may be on a different system
- Remote Procedure call (RPC,允许程序调用位于其它机器上的进程) - NO EXPLICIT MESSAGE PASSING(对编程人员)
Call by Copy/restore: 首先由调用者将变量拷贝到Stack,调用完成之后,
将堆栈中的变量复制回去覆盖调用方该变量原先的值。参数从客户发送到服务 器,在那里修改,然后发送回客户,覆盖原来的值。
Marshalling(编组,即把参数打包进消息中发送到服务器): transform parameters/results into a byte stream
Problem: how do we pass pointers?
(指针只在它被使用的进程的地址空间里面是有意义的)
- If it points to a well-defined data structure, pass a copy to
the server and the server stub passes(使用) a pointer to the local copy (来调用服务器程序) What about data structures containing pointers? - Prohibit - Copy/restore, machine independent representation
分布式系统中的通信
进程间通信是一切分布式系统的核心。 分布式系统中的通信都是基于底层网
络提供的低层消息传递机制的。 通过消息传递来描述通信过程比使用 基于共享存储器的原语来描述要更困 难。
4种广泛使用的通信模型
远程过程调用 (remote procedure call, RPC) 远程方法调用 (remote method invocation, RMI) 面向消息的中间件 (message-oriented middleware, MOM) 面向流的通信 (stream-oriented communication)
A calls B ->A suspended, B executes ->B returns, A executes • Information from A (caller) to B (callee) transferred using parameters • Somewhat easier since both caller and callee execute in the same address space
client kernel
file server process server terminal server
kernel
kernel
kernel
Remote Procedure Call (RPC)
Client-Server provides a mechanism for services in distributed systems BUT - requires explicit communication (send-receive) Q: How do we make “distributed computing look like traditional (centralized) computing”? Can we use procedure calls?
Communication Protocols
由于没有共享存储器,分布式系统中的所有通信都是基于(低层)消息交换的。
Protocols are agreements/rules on communication Protocols could be connection-oriented or connectionless
从而达到隐藏通信(send和receive),实现分布式系统中的访问透明性
Goal: Make RPC look (as much as possible) like local procedure call
- allow remote services to be called as procedures - caller should not be aware of the fact that the callee is (executing) on a different machine (or vice versa)
a) b)
Normal operation of TCP(常规TCP的许多开销都耗费在连接的管理上). Transactional TCP(更经济的方式).
Middleware Protocols
Middleware:
- An application that logically lives in the application layer - Contains many general-purpose protocols that warrant(代表) their own layers - (会话层和表示层由一个单一的中间件层代替)
Application Middleware Transport Application protocol Middleware protocol Transport protocol Network protocol 6 5 4 3
Network
Data link Physical
Data link protocol
client kernel
file server process server terminal server
kernel
kernel
kernel
Client-Server Communication Model
Based on a request/response paradigm - Clients send a request asking for service (e.g., a file block) - Server processes and replies with result (or error) Techniques: - Socket, Remote Procedure Calls (RPC), Remote Method Invocation (RMI)
data formats - Intel: little endian, SPARC: big endian Solution: use a standard representation - Example: external data representation (XDR)
Marshalling: Reference Parameters
客户通过执行普通的(本地)过程调用来访问远程服务,它并不需要直接调用 Send和Receive,消息传递的所有细节都隐藏在双方的库过程(Stub,Skeleton)中。
Steps of a remote procedure call
1.
2. 3. 4. 5. 6. 7.
8.
9. 10.
Client procedure calls client stub in normal way Client stub builds message, calls local OS Client’s OS sends message to remote OS Remote OS gives message to server stub Server stub unpacks parameters, calls server Server does work, returns result to the stub Server stub packs it in message, calls local OS Server’s OS sends message to client’s OS Client’s OS gives message to client stub Stub unpacks result, returns to client
Physical protocol
2
1
Network
Client-Server Com百度文库unication Model
Structure: group of servers offering service to clients - Servers: offer services to the users called “clients” - Clients: applications requiring services from servers - Example: Web Server/clients, File server … Why use client-server model - simplicity - low(er) overheads
Although no message passing (at user level), parameters must still be passed & results must still be returned!
Client and Server Stubs
Principle of RPC between a client and server program.
Data link Physical
Data link protocol
Physical protocol
2
1
Network
Layered Protocols
2-2
A typical message as it appears on the network.
Data Link Layer
2-3
Discussion between a receiver and a sender in the data link layer.