Distributed Systems笔记-middlewares
来源:互联网 发布:最新论坛群发软件 编辑:程序博客网 时间:2024/04/20 22:27
CMU 95702 Distributed Systems 笔记。简单介绍分布式系统中解决 interoperability concern 的几种方案 Cobra’s CDR, Java serialization 和 XML/JSON。这章整理的比较简单。
一言以蔽之,middleware 是为了更好的与 remote server 交流。
Interoperability concern
分布式系统里的互操作性问题。
- Big/Little Endian byte ordering may differ
- Floating point representation may differ
- Binary vs Unicode
如果 j=3, binary 表示就是 00…011,而 unicode 表示是 0000000000110011,如果两端没有达成一致,那么就会出错。
The receiver had better know which one we are using。
假设我们用 C++ 写了 TCP server,那么我们可以写个 JAVA TCP connection 来连接 server 吗?可以!
C++ 和 JAVA 都知道怎么 open 一个 TCP connection。
假设 client 把一个 java object 发给了 server,这个 object 的内容可以重新被封装成 c++ 的 object 吗?不可以!
三种解决方案
CORBA’s CDR
双方都知道 message 的 data type 和 order。双方在交流前都有一个 IDL(Interface description language 接口描述语言),这和 google 的 protocol buffers 差不多。XML, XSDL, WSDL 都可以作为 IDL。
如下面一段 C 的代码。
12345
struct Person {string name;string place;long year;}
我们可以让 CORBA Interface Compiler 来做合适的 marshalling 和 unmarshalling operation,无论是 C 还是 JAVA。
CORBA’s CDR 的特点是 - 非常快!所以传送的信息不包括 data type,只有表格中的右边一栏数据。
Java serialization
Java’s serialization 本身可以用来 marshal 和 unmarshal,所以并不需要 IDL。双方事先也不知道 data type。
如下面一段 Java 的代码。
123456789
public class Person implements Serializable{string name;string place;long year;public Person(String nm,place,year) {nm=name;this.place=place;this.year=year;}// more methods}
Java 序列化的特点是有很多 data (如 class name, version number, data type 等)来 describe 真正的 data。
Web Service use of XML
格式:
12345
<p:person xmlns:p=“http://www.andrew.cmu.edu/~mm6”><p:name>Smith</p:name><p:place>London</p:place><p:year>1934</p:year></p:person>
- 相对前两种方法来说会比较慢。因为它是 text 形式而前两种方法是 binary 形式。
- HTTP header 需要声明 Content-Type: text/xml; charset: ISO-8859-1
- 可以表示任何 binary message,因为 binary data(图片和其它加密的元素)可以被表示成 Base64
- 必须遵循 XSDL 的语法。
- 支持各平台。
Web Service use of JSON
格式:
1234
{ “person” : { “name” : “Smith”“place”:”London”“year”:”1934”}}
- 可以表示任何 binary message,因为 binary data(图片和其它加密的元素)可以被表示成 Base64
- 必须遵循 JSON 的语法。
比较
- Marshalling and external data representation
binary, xml/json text - Interoperability
corba flexibility, java requires both sides, xml/json interoperable - Security
- Reliability
TCP: reliable as it checks if the message is arrived
UDP: not reliable - Performance
corba > java > xml/json(package and unpackage) - Remote references
- Full OOP
- Describe how the protocols of the internet allow for heterogeneity
- Describe how middleware allows for heterogenity
hides low level implementation
Pass pointers
在分布式的 OOP 中,我们需要传送 pointers,包括以下信息。
UDP Based Request-Reply Protocol
直接上图和代码。
代码:
123456789101112131415
Client side:public byte[] doOperation (RemoteObjectRef o, int methodId, byte[] arguments)sends a request message to the remote object and returns the reply.The arguments specify the remote object, the method to be invoked and thearguments of that method.Server side:public byte[] getRequest ();acquires a client request via the server port.coolOperationselect object, execute, methodpublic void sendReply (byte[] reply, InetAddress clientHost, int clientPort);sends the reply message reply to the client at its Internet address and port.
Failure model
doOperation 可能在 waiting 的时候 timeout,我们要做什么?
- 返回给 caller 一个错误信息
- response 可能会丢失,所以我们告诉 client 让 client try and try 直到确认服务器挂了。这带来的结果是 client 可能会收到同样的信息。
Handle duplicates
根据 client 的 acknowledgement 来清空历史。
Request-Reply Message Structure
12345
messageType: int (0=Request, 1=Reply)requestId: intobjectReference: RemoteObjectRefmethodId: int or Methodargument: array of bytes
原文地址: http://www.shuang0420.com/2016/11/02/Web-service-middlewares/
- Distributed Systems笔记-middlewares
- Distributed Systems笔记-Cryptographic Protocols
- Distributed Systems笔记-NFS、AFS、GFS
- Distributed Systems笔记-Web Service Design Patterns
- 转 -A Distributed Systems Reading List
- middlewares
- Introduction to Distributed Systems
- Distributed Systems Topologies
- Distributed Systems with ZeroMQ
- distributed cache systems summary
- Distributed Systems-Basics
- Distributed Systems-Paxos
- Replication models in distributed systems
- A Distributed Systems Reading List
- A Distributed Systems Reading List
- Designing Distributed Systems - A Conversation with Ken Arnold, Part III 阅读笔记
- 论文阅读笔记 - Chubby: The Chubby lock service for loosely-coupled distributed systems
- Architecting Distributed Systems with Web Services
- TensorFlow 实战 MINST
- 推荐系统--用户行为和实验设计
- 袖珍电子书,雄心壮志永不变
- Distributed Systems笔记-Web Service Design Patterns
- 324. Wiggle Sort II
- Distributed Systems笔记-middlewares
- Distributed Systems笔记-Cryptographic Protocols
- gcc编译动态库与静态库
- Distributed Systems笔记-NFS、AFS、GFS
- CMU 11642 Search Engines - 大纲梳理
- LIS问题(POJ - 3903 Stock Exchange)
- Java post请求发送json数据在filter中解析方法
- 16. 3Sum Closest
- [LeetCode] 394. Decode String 解题报告