第2章 分布式通信
中国科技大学软件学院
丁箐
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信
2
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信
3
通信基础
开放式系统:使用标准化规则与其它开放系统
通信的系统
协议:进程间通信所必须遵循的规则,消息的
格式、内容和意义
协议的种类
– 面向连接、非面向连接
分层协议
– ISO OSI参考模型
– Internet
4
OSI参考模型分层协议
进程A 进程B
5
The Internet 协议
Network
IP
TCP UDP
Application
Transport
Datagrams
Messages (UDP)
Streams (TCP)
6
典型消息结构
7
网络技术的发展(1)
分组交换协议
– (MIT),1962
TCP/IP协议
– (MIT,ARPA),V,Cerf(UCB,Stanford),
– 《IEEE通信》974
CDMA协议与Ethernet
– (HU,MIT,PARC),1973
– 3COM,以太网适配器
8
网络技术的发展(2)
ARPANET与Internet
– IPTO,(1960),(1966)
– (MIT),BBN公司
– ARPANET(1969,UCB,SRI)
Stanford校园网与LAN
– ,(Stanford),1980-1983
– Cisco(1984),Cisco路由器
9
ATM网络技术
分组交换、线路交换和信元交换
信元(cell):
– 小的、定长的单元
信元交换:
– 同时支持点到点(point-point)和多播(multicast)
功能
10
ATM参考模型
物理层:
– SONET
– OC-1(),
– OC-3c(155M)
ATM层:
– 信元传输和路由
适配层:
– VBR,CBR
上面各层
适配层
ATM层
物理层
11
信元头格式
12
ATM交换网络及交换机内部构造
13
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信14
客户/服务器模型
服务器:为用户提供服务的一组协同进程
客户:代理用户
15
客户/服务器(1-1)
Server
Client
Client
invocation
result
Serverinvocation
result
16
客户-服务器交互 (I)
•Remote procedure call
17
客户-服务器交互(II)
•多层结构
18
客户-服务器交互(III)
•异步 remote procedure call
19
客户/服务器(1-N)
20
Example: Web proxy server
21
客户-服务器交互(IV)
22
Peer-to-Peer 合作
23
Mobile Code Example: Applet
24
瘦客户
Thin
Client
Application
Process
Network computer or PC
Compute server
network
25
消息格式
struct message {
long source; /* 发送者标识*/
long dest; /* 接受者标识 */
long opcode; /* 操作码:读、写、创建、删除 */
long result; /* 返回结果代码 :成功、失败*/
long offset; /* 读写位置 */
long count; /* 读写计数 */
char filename[MAX_PATH}; /* 文件名*/
char data[BUF_SIZE]; /* 数据区*/
}
26
服务器程序
void main(void){
struct message m1,m2; /* 输入、输出的消息 */
int r; /* 返回的执行结果 */
while (1) {
receive(FILE_SERVER,&m1); /* 等待客户请求 */
case() { /* 执行请求的操作 */
case READ: r = do_read(&m1,&m2); break;
:
default: r = E_BAD_OPCODE;
}
= r;
send(,&m2); /* 返回结果 */
}
}
27
客户程序
int read(char *file, int position , int nbytes, char *buf){
struct message m1; /* 消息缓冲区 */
= READ; /* 设置参数 */
= position; /* 读位置 */
= nbytes; /* 读长度 */
strcpy(&,src) /* 文件名 */
send(FILE_SERVER, &m1); /* 发送请求 */
receive(CLIENT,&m1); /* 等待服务器应答 */
if( == OK) strcpy(buf, &); /* 置缓冲区 */
return(); /* 返回结果 */
}
}
28
寻址方式(Addressing)
1、机器号+本地标识号
例:UNIX
– 机器IP地址
– 端口号(port)
/* Socket address, internet style. */
struct sockaddr_in {
short sin_family; /*AF_INET*/
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
29
2、广播定位进程
–全局唯一标识号
30
3、ASCII码进程名
–名字服务器
31
阻塞与非阻塞原语
(1)阻塞发送原语
– 同步原语
(2)非阻塞发送原语
– 异步原语
–在消息被发送之前,
发送者不能修改消息
缓冲区
时间
时间
32
有缓冲与无缓冲型接收
无缓冲区
发送比接收先发生 ?
– 直接丢弃消息
– 暂存“意外”消息
有缓冲区
– 邮箱(mailbox):
– 缓存所有的输入消息
– “溢出”问题
33
可靠的和非可靠的发送和接收
非可靠的收发
– 可能丢失消息
– 由用户负责确认
独立的确认消息
– 内核-内核确认
应答用作请求的确认消息
– 客户内核确认
– 折衷方法
服务器端设置计时器,超时后,发确认消息
34
35
实现技术小结
项目 选择1 选择2 选择3
寻址 机器+进程 共享进程地址 ASCII名字通过服务器
查找
阻塞 阻塞原语 具有拷贝到核的非
阻塞
具有中断的非阻塞
原语 无缓冲,丢
弃不期望的
消息
无缓冲,临时保持
不期望的消息
邮箱
可靠性 非可靠 请求-应答确认
36
客户/服务器协议中的包类型
代码 包类型 来源 至 说明
REQ 请求 客户 服务器 客户要求服务
REP 应答 服务器 客户 服务器对客户的应答
ACK 确认 服务器、客户 其他 前面的包已到达
AYA 你在这里吗? 客户 服务器 查看服务器是否崩溃
IAA 我在这里 服务器 客户 服务器没有崩溃
TA 再试一次? 服务器 客户 服务器没有空间
AU 地址未知 服务器 客户 没有进程在使用此地
址
37
包交换举例
38
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信39
套接字socket
• socket通信的基本原理
• socket通信的工作过程
40
一个socket在逻辑上有三
个特征(三要素):
–网域
–类型
–规程
41
网域:表明一个socket用于哪一种网络
或说哪一族网络规程。各种网络对节点
地址的命名方法不同,又称“地址族”
或“规程族”。
– AF_INET表示Internet网插口,故各节点使用IP地
址 。 AF_IPX为 Novell的 IPX网 插 口 , AF_X25为
网插口,等等。其中的特殊,不走网络而在
同 一 台 计 算 机 上 用 于 进 程 通 信 , BSD称 为
AF_UNIX, 在 POSIX标 准 里 定 义 了 一 种
AF_LOCAL域名。
42
类型:表明网络中通信所遵循的模式
– “面向连接”:又叫“虚电路”模式,通信双方先要在互
相之间建立起一种虚拟连接(线路),再通过虚拟线路进行
通信。在通信过程中,所有报文传递保持原来次序,所以,
报文之间是有关联的,每个报文都不是孤立的。在这种模
式中,所有报文的传递都是可靠的,由网络中物理线路引
入差错控制来保证。
– “无连接”:事先不必建立虚线路,直接可发送和接收报
文。但报文是孤立的,正确性没有保证,甚至可能丢失。
由于网络延迟或路径不同,接收端收到报文的次序可能与
发送端发送报文的次序不一样。这种模式传递的报文是不
可靠的,无保证的。也没有“流量控制”手段,进程从系
统调用返回时仅表明该socket会把报文发送去,并不表明
报文已到达了接收方的socket。
43
规程:表明具体网络规程。一般来说,
网域与类型结合作一起就大体上决定
了规程。如网域为AF_INET,而类型
为“无连接”,则规程大致为UDP了。
但有时,还会有其他选择。
44
Berkeley Sockets API
Socket primitives for TCP/IP.
Primitive Meaning
Socket Create a new communication endpoint
Bind Attach a local address to a socket
Listen Announce willingness to accept connections
Accept Block caller until a connection request arrives
Connect Actively attempt to establish a connection
Send Send some data over the connection
Receive Receive some data over the connection
Close Release the connection
45
基本的socket调用
recv
send
socket
bind localhost
sockaddr_in()
listen
accept peer
sockaddr_in()
socket
connect
recv
send
peer
sockaddr_in()
SERVER CLIENT
46
服务器方 客户方
socket()建立数据报式套
接字,返回套接字号
socket()建立数据报式套
接字,返回套接字号
bind()把套接字s与本地地
址相连接
bind()把套接字s与本地地
址相连接
recvfrom()/sendto()在s上
读写数据,直至结束
recvfrom()/sendto()在s上
读写数据,直至结束
closesocket()关闭套接字,
服务结束
closesocket()关闭套接字,
结束对话
无连接协议的套接字调用时序
47
面向连接的套接字调用时序
accept()接收连接,并
得到第二个套接字ns
recev()/send()在ns上
读写数据,直到结束
Closesocket()关闭套接
字s,结束TCP/IP对话
服务器方
客户方
socket()建立流式套接
字,返回套接字号s
bind()把套接字s与本
地地址相连
listen()通知TCP/IP,服
务器准备好接收连接
closesocket()关
闭套接字ns
closesocket()关
闭最初套接字s
socket()建立流式套
接字,返回套接字号
s
connect()把套接字s
与远程主机相连
send()/recev()在ns上
读写数据,直到结束
建立连接
服务请求
服务响应
48
Berkeley Sockets调用
Connection-oriented communication pattern using
sockets.
49
数据流 (1)
Setting up a stream between two processes across a network.
50
数据流(2)
Setting up a stream directly between two devices.
51
数据流(3)
An example of multicasting a stream to several receivers.
52
定义 QoS (1)
A flow specification.
Characteristics of the Input Service Required
•maximum data unit size (bytes)
•Token bucket rate (bytes/sec)
•Toke bucket size (bytes)
•Maximum transmission rate
(bytes/sec)
•Loss sensitivity (bytes)
•Loss interval (sec)
•Burst loss sensitivity (data units)
•Minimum delay noticed (sec)
•Maximum delay variation (sec)
•Quality of guarantee
53
定义 QoS (2)
The principle of a token bucket algorithm.
54
配置流
The basic organization of RSVP for resource reservation in a
distributed system.
55
同步机制 (1)
The principle of explicit synchronization on the level data units.
56
同步机制 (2)
The principle of synchronization as supported by high-level
interfaces.
2-41
57
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信58
远程过程调用
允许程序去调用位于其它机器上的过程
– 调用者和被调者都不用考虑消息通信
举例:
– int read(int fd, char * buf, int nbytes);
– count = read(fd, buf, nbytes);
参数传递
– call-by-value
– call-by-reference
59
传统的过程调用
a) 本地过程调用中的参数传递:调用读前的堆栈
b) 调用过程激活时的堆栈
60
软件层
Applications and Services
RPC and RMI
request-reply protocol
marshalling and external data representation
UDP and TCP
m
id
d
le
w
a
re
RPC is more than a (transport) protocol:
a structuring mechanism for distributed systems
61
RPC中的调用与消息
客户机
客户存根客户应用
客户
OS内核
本地调用
客户
打包
参数
拆包
参数
返回结果
OS内核
服务器
本地调用
服务存根 服务应用
服务过
程
打包
参数
拆包
参数
返回结果
OS内核
网络消息
传送
1
2
3
4
5
6
7
8
9
10
62
RPC执行的主要步骤
1.客户过程以普通方式调用相应的客户存根。
2.客户存根建立消息并激活内核陷阱。
3.内核将消息发送到远程内核。
4.远程内核将消息送到服务器存根。
5.服务器存根取出消息中的参数后调用服务器的过程。
6.服务器完成工作后将结果返回至服务器存根。
7.服务器存根将它打包并激活内核陷阱。
8.远程内核将消息发送至客户内核。
9.客户内核将消息交给客户存根。
10.客户存根从消息中取出结果返回给客户。
63
客户和服务Stubs
Principle of RPC between a client & server program.
64
异步RPC (I)
65
异步RPC (II)
66
编写Client和Server的步骤
67
RPC编程举例
/* 生成RPC程序 */
rpcgen
==〉编译结果
/* 参数定义 */
/* 服务器端程序 */
/* server存根 */
/* 服务器模版程序 */
/* 客户端程序 */
/* client存根 */
/* 客户模版程序 */
68
RPC申明--
#define RPC_ARGSIZE 256
#define RPC_RETSIZE 256
/* the interface version number */
#define uSERVERVERS 1
/* program number range established
by ONC */
#define uSERVERPROG 0x20000051
struct CallArg_t {
char body[RPC_ARGSIZE];
}; /* RPC's arg data form */
struct Return_t {
char body[RPC_RETSIZE];
}; /* RPC's arg data form */
/* program definition*/
program SERVERPROG {
version SERVERVERS {
Return_t FILE_CREATE(CallArg_t) =
1;
Return_t FILE_READ(CallArg_t) = 2;
Return_t FILE_WRITE(CallArg_t) = 3;
Return_t FILE_DEL(CallArg_t) = 2;
} = uSERVERVERS;
} = uSERVERPROG;
69
RPC服务端程序 --
.....
void main2() {
SVCXPRT *transp;
transp = svcudp_create(RPC_ANYSOCK);
svc_register(transp, SERVERPROG,
SERVERVERS, serverprog_1,
IPPROTO_UDP); /* 注册 */
transp = svctcp_create(RPC_ANYSOCK, 0, 0);
svc_register(transp, SERVERPROG,
SERVERVERS, serverprog_1,
IPPROTO_TCP)) ; /* 注册 */
svc_run(); // 启动RPC
exit(1);
}
static void serverprog_1(struct svc_req *
rqstp, SVCXPRT * transp) {
union { CallArg_t file_create_1_arg;
CallArg_t file_read_1_arg;
:
} argument;
switch (rqstp->rq_proc) {
:
case FILE_READ:
xdr_argument = xdr_CallArg_t;
xdr_result = xdr_Return_t;
local = (char *(*)(char *,struct svc_req
*)) file_read_1_svc;
break;
:
default:
svcerr_noproc(transp);
return; }
}70
RPC客户端程序 --
.....
/* Default timeout can be changed using clnt_control() */
static struct timeval TIMEOUT = { 25, 0 };
Return_t * file_read_1(CallArg_t *argp, CLIENT *clnt)
{ static Return_t res;
bzero((char *)&res, sizeof(res));
if (clnt_call(clnt, FILE_READ, xdr_CallArg_t, argp, xdr_Return_t, &res, TIMEOUT)
!= RPC_SUCCESS)
return (NULL);
}
return (&res);
}
.....
71
基本RPC操作
(a)调用read之前的栈; b)调用过程处于激活
状态时的栈; (c)返回调用者之后的栈
值参调用和变参调用
call-by-copy/restore
72
参数定义和产生Stub
procedure Corresponding message73
参数传递
• 参数编组(marshalling):将
参数装入消息
• 例:add(i,j)远程计算
74
参数传递问题
• 编码表示:ASCII, EDBIC
• 数字表示:小末端、大末端
规范形式:整形、字符型、布尔型、浮点型等
指针参数:
copy/restore
dereference
75
参数传递问题
(a)486中的原始消息;
(b)在SPARC上接受到的消息;
(c)经过翻译之后的消息;(框中的小数字表明
了每一个字节的地址)
76
建立表示基本数据类型的标准
77
参数传递问题
如何传递 指针 ?
– 只有在特定地址空间才有意义!
已知长度的数组和结构
– Copy/restore 语义
– IN/OUT/INOUT 标签
到任意数据结构的指针 ?
– 没有一般的解决办法
– 通常:
把指针传递给它的 “源”
78
客户如何定位服务器呢?
将服务器的网络地址固化到客户机中
动态捆绑
79
动态捆绑
绑定、调用
客户
绑定器 服务器
注册、取消
查找
80
绑定(SUN RPC)
Port Mapper (rpcbind) listens at UDP port 111
Server registers program ID & version
– rpcinfo -p -> display all registered RPC servers
When client issues clnt_create, the port mapper is
contacted:
– program-to-port number mapping
arguments: (program ID, version, protocol)
response: server’s port number
81
绑定(DCE)
82
绑定接口
句柄(handle): 如IP地址
唯一标识(ID):程序号
认证:身份标识
调用 输 入 输 出
注册 名字、版本、句柄、唯一id
注销 名字、版本、唯一id
查找 名字、版本 句柄、唯一id
83
RPC故障处理
1. 客户不能定位服务器
a) 返回错误号errno
b) 产生例外:SIG_NOSERVER
2. 丢失请求信息
a) 超时重发
3. 丢失应答信息
a) 等幂性请求
b) 序号
84
RPC故障处理
4. 服务器崩溃解决
a) 至少一次语义 (重发请求 )
b) 至多一次语义 (立即放弃并报告失败)
c) 不做任何保证
d) 恰好一次?
(a)正常状态;(b)执行后崩溃;(c)执行前崩溃
85
RPC故障处理
5. 客户崩溃
– 孤儿问题:资源浪费、资源封锁
– 解决方案:
根除(日志文件 )
再生(epochs,所有远程计算被终止 )
温和再生(试图去找到该远程计算的调用者 )
过期(标准时间段T )
86
RPC实现技术
RPC可以使用哪些协议?
– TCP 提供可靠传输
ACKs, timeouts, retransmissions
– UDP 不提供可靠传输,但RPC执行RETRANSMIT
timeout
– 因此在total timeout后,无论使用TCP或UDP都重复请求
– TCP需要建立连接
对于一些短的RPCs,有额外开销
– 专门协议
– 信包和报文的长度
87
RPC实现技术
确认
停等(stop-and-waitt)协议(b)
爆发 (blast)协议©
差错控制
流量控制:数据溢出(overrun)
88
RPC实现技术
3. 关键路径
客户机
调用存根过程
准备消息缓冲区
将参数编排进缓冲区
填写消息头
陷入内核
将上下文切换到内核
将消息复制到内核
确定目的地址
将地址写入消息头
设置网络接口
启动计时器
服务器
执行服务
调用服务器
在堆栈上设置参数
解析参数
将上下文切换到存根
将消息复制到存根
检查存根是否在等待
确定使用哪个服务器存根
检查消息包的有效性
处理中断
89
RPC实现技术
4. 拷贝
– DMA
– 分散-聚集(scatter-gather)
– 虚拟内存映射
客户存根 网络
内核 内核
服务器存根
90
RPC实现技术
5. 计时器管理
– 计时器列表
– 扫描算法(sweep
algorithms)
(a)排序表中的时间片耗
尽;
(b)进程表中的时间片耗
尽
91
RPC实现技术
6. 存在的问题
– 全局变量的共享
– 弱数据类型的传
递,数组?
– 指针传递
– 管道:读驱动、
写驱动
(a)管道
(b)读驱动方法
(c)写驱动方法
92
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信93
Web Services
“Web services” is an effort to build a
distributed computing platform for the Web.
94
Web Services 框架
可以用术语描述为:
– What goes “on the wire”:
Formats and protocols.
– What describes what goes on the wire:
Description languages.
– What allows us to find these descriptions:
Discovery of services.
95
Web-Services 体系结构
SOAP消息
服务提供方
服务请求方
服务代理方
WSDL docs
使用 e-
services的应
用
2
创建业务/服务
1
发现业务/服务
4
3
7
调用服务
8
UDDI
Registry
XSD docs
Servlets,
CGI, Perl
65
检索 WSDL文档
96
XML Messaging: SOAP
SOAP defined:
– An XML envelope for XML messaging,
Headers + body
– An HTTP binding for SOAP messaging.
SOAP is “transport independent”.
– A convention for doing RPC.
– An XML serialization format for structured data
SOAP Attachments adds
– How to carry and reference data attachments using in a
MIME envelope and a SOAP envelope.
97
The SOAP Envelope
<SOAP-ENV:Envelope
xmlns="
< SOAP-ENV:Header>
...
</ SOAP-ENV:Header>
< SOAP-ENV:Body>
...
</ SOAP-ENV:Body>
...
</ SOAP-ENV: Envelope>
98
What goes on the wire
Internet-scale integration needs
a lingua-franca
– XML messaging protocol
over HTTP: SOAP
Intra-enterprise integration
needs to allow alternates:
– CORBA, RMI
– Messaging
– In-memory method calls
SOAP
Security
Attachments
Reliability
Routing
Transactions
Context
W
3C
99
Descriptions: Meta-data
Integration requires
interoperable machine-
understandable descriptions
Enables dynamic, delayed
binding of components.
Language extensibility provides
support for different levels of
application integration.
Interface
Service QoS
Service
Public Flows
Flows and
Composition
Agreements
W
S
D
L
W
S
FL
XML Schema10
0
Web Services Description Language
Provides functional description of network services:
– IDL description
– Protocol and deployment details
– Platform independent description.
– Extensible language.
A short history:
– WSDL , 9/2000
– WSDL submitted to W3C 3/2001.
– A de facto industry standard.
10
1
WSDL Structure
portType
– Abstract definition of a
service (set of operations)
Multiple bindings per
portType:
– How to access it
– SOAP, JMS, direct call
Ports
– Where to access it
Service
Port
(. http://host/svc)
Binding
(. SOAP)
Abstract interface
portType
operation(s)
inMesage outMessage
Port
Binding
10
2
Using WSDL
1. As extended IDL: WSDL allows tools to generate compatible
client and server stubs.
Tool support for top-down, bottom-up and “meet in the middle”
development.
2. Allows industries to define standardized service interfaces.
3. Allows advertisement of service descriptions, enables
dynamic discovery and binding of compatible services.
Used in conjunction with UDDI registry
4. Provides a normalized description of heterogeneous
applications.
10
3
Client Proxy
object
RMI-
IIOP
JMS/
MQ
SOAP/
HTTP
Client invocation
Single stub can invoke services over different bindings
– Depends only on abstract interface.
Are independent of binding (but pluggable).
– Add new bindings without recompiling/redeploying stub
Allows optimisations
based on the bindings of service.
Will support extended
services models if described
In WSDL
10
4
WSFL Overview
WSFL describes Web
Service compositions.
1. Usage patterns of Web
Services: describes
workflow or business
processes.
2. Interaction patterns:
describes overall partner
interactions.
A
B
C
[ WS]
[ WS]
10
5
WSFL Flow Models
Activities represent
units of processing.
Flow of data is
modeled through
data links.
[ WS]
Activities can be
mapped to the flow
interface
Control links define
execution flow as a
directed acyclic graph
Activities are associated
with specific typed
service providers
10
6
Using Flow Models
“Public flows” provide a representation of the service behavior as
required by its users.
– Typically, an abstraction of the actual flow begin executed
– Defines a “behavioral contract” for the service.
– Internal implementation need not be flow-based.
– Flows are reusable: specify components types, but not what specific
services should be used!
“Private flows” are the flows executed in practice.
– WSFL serves as a “portable flow implementation language”
Same language is used in WSFL to represent both types of processes.
10
7
Global Models
Global models describe how the
composed Web Services interact.
RosettaNet automated.
Like an ADL.
Interactions are modeled as links
between endpoints of two
service interfaces (WSDL
operations).
An essentially distributed
description of the interaction.
A
B
C
10
8
Discovery: Finding Meta-data
Static binding requires
service “libraries”.
Dynamic binding requires
runtime discovery of meta-
data
Inspection
Directory
ADS,
DISCO
UDDI
10
9
UDDI Overview
UDDI defines the operation of a service registry:
– Data structures for registering
Businesses
Technical specifications: tModel is a keyed reference to a
technical specification.
Service and service endpoints: referencing the supported
tModels
– SOAP Access API
– Rules for the operation of a global registry
“private” UDDI nodes are likely to appear, though.
11
0
UDDI Relationships
Web Service
Web Service
SIC CODE
NAICS
DUNS Numbers
Thomas Registry ID
Rosetta-Net
BASDA
Schemas,
Interchange specification
businessEntitybusinessEntitybusinessEntity
businessServicebusinessService
bindingTemplatebindingTemplate
InstanceDetailsInstanceDetails
categoryBag
keyedReferencekeyedReference
identifierBag
keyedReferencekeyedReference
tModels
11
1
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信
11
2
消息队列
四种松散组合的通信使用队列
11
3
消息队列原语
Primitive Meaning
Put Append a message to a specified queue
Get Block until the specified queue is nonempty, and remove the first message
Poll Check a specified queue for messages, and remove the first. Never block.
Notify Install a handler to be called when a message is put into the specified queue.
11
4
消息队列的一般结构 (I)
队列层地址和网络层地址间的关系
11
5
消息队列的一般结构(II)
2-29
11
6
消息代理
The general organization of a message broker in a
message-queuing
system.
11
7
IBM MQSeries
11
8
Channels
Some attributes associated with message channel agents.
Attribute Description
Transport type Determines the transport protocol to be used
FIFO delivery Indicates that messages are to be delivered in the order they are sent
Message length Maximum length of a single message
Setup retry count Specifies maximum number of retries to start up the remote MCA
Delivery retries Maximum times MCA will try to put received message into queue
11
9
消息传输 (I)
使用路由表和别名表
12
0
消息传输 (II)
IBM MQSeries MQI原语
Primitive Description
MQopen Open a (possibly remote) queue
MQclose Close a queue
MQput Put a message into an opened queue
MQget Get a message from a (local) queue
12
1
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信
12
2
分布式对象
12
3
Binding a Client to an Object
a) 使用global references不明确绑定
b) 使用global and local references明确绑定
Distr_object* obj_ref; //Declare a systemwide object reference
obj_ref = …; // Initialize the reference to a distributed object
obj_ref-> do_something(); // Implicitly bind and invoke a method
(a)
Distr_object objPref; //Declare a systemwide object reference
Local_object* obj_ptr; //Declare a pointer to local objects
obj_ref = …; //Initialize the reference to a distributed object
obj_ptr = bind(obj_ref); //Explicitly bind and obtain a pointer to the local proxy
obj_ptr -> do_something(); //Invoke a method on the local proxy
(b)
12
4
参数传递
The situation when passing an object by reference or by value.
Local vs remote object references
12
5
DCE分布式对象模型
a) Distributed dynamic objects in DCE.
b) Distributed named objects
12
6
主要内容
通信基础
客户/服务器模型
套接字socket
远程过程调用
Web Service
消息队列
分布式对象
组通信
12
7
组通信:通信涉及到多个进程
组:由系统或用户确定的若干个进程的集合
– 组的成员籍(membership)
通信方式:
– 点到点通信(point-to-point):单播(unicast)
– 一到多通信(one-to-many) : 多播(multicast)、广播
(broadcast)
12
8
设计的问题
封闭组与开放组
12
9
设计的问题
对等组与分层组
参与者
13
0
设计的问题
组的成员籍
(membership)
– 组服务器
– 分布式管理
组的寻址
– 组地址
– 目的地址列表
– 谓词寻址(predicate
addressing)
13
1
设计的问题
发送和接收原语
– group_send
– group_receive
– 单程(one-way)模型
原子性
– 原子性广播:一个消息被所有成员接收到,或者,
一个也没有接收到。
13
2
设计的问题
消息的顺序
– 全局时间顺序(global
time ordering)
– 一致性时间顺序
(consistent time
ordering)
13
3
组通信的设计
重叠组
– 不同组之间的
协调
可伸缩性
– 互联网络
– 网关
13
4
ISIS中的组通信
ISIS:康奈尔大学开发的
工具集(1987)
同步类型:
– 同步、弱同步、虚拟同步
13
5
ISIS中的组通信
事件类型:
– 因果相关的
– 并发的
ISIS广播原语
– ABCAST:弱同步
两段提交协议
– CBCAST:虚拟同步
– GBCAST:管理组成员的ABCAST通信
13
6
CBCAST协议
n个进程设置n维向量
13
7
CBCAST应用举例
13
8