about thrift
DESCRIPTION
TRANSCRIPT
THRIFThttp://Jiaqing.me
2012-03-13
2
大纲
Thrift 简介Thrift 设计
3
Thrift简介
1 Thrift 是什么 Thrift 解决什么问题 简单示例
4
What: Introduction of Thrift
实现跨语言的服务访问框架是一种 IDL ,定义了数据结构和服务描述自动生成指定语言的客户端、服务端
opensource by
5
What: Features
接口定义语言( IDL )多语言支持: C/C++/Java/PHP/Perf/Ruby..
名字空间支持通用数据类型支持容器类型支持自定义异常…
6
What:Non-features
循环依赖继承多态重载混合数据类型的集合返回 null
7
Why: the Problem FB Encountered各技术体系间的统一桥梁性能需求
8
How: A Sample
下载源码包和代码编译器 http://thrift.apache.org/download/
9
How: A Sample
编译,生成基础 jar 包
10
How: A Sample
编写 .thrift 定义文件 : hello.thrift
namespace java service.demo service Hello { string helloString(1:string para) i32 helloInt(1:i32 para) bool helloBoolean(1:bool para) void helloVoid() string helloNull() }
11
How: A Sample
生成客户端 / 服务端代码
12
How: A Sample
编写客户端
13
How: A Sample
服务具体实现
14
How: A Sample
编写服务端
15
Thrift设计
2 总体架构 主要功能 处理流程
16
Arch
提供通用的传输层、协议层、 I/O 层(红色以下)
通过工具生成客户端 / 服务端读写逻辑(红色)
RD 只需关注业务逻辑(黄色)
17
DataType
基本类型 bool : 布尔值, true 或 false ,对应 Java 的 boolean byte : 8 位有符号整数,对应 Java 的 byte i16 : 16 位有符号整数,对应 Java 的 short i32 : 32 位有符号整数,对应 Java 的 int i64 : 64 位有符号整数,对应 Java 的 long double : 64 位浮点数,对应 Java 的 double string : 未知编码文本或二进制字符串,对应 Java 的 String
结构体类型 struct :定义公共的对象( JavaBean 、 C 中的结构体)
容器类型: list : 对应 Java 的 ArrayList set : 对应 Java 的 HashSet map : 对应 Java 的 HashMap
异常类型: exception :对应 Java 的 Exception
服务类型: service : 对应服务的类
18
Protocols
TBinaryProtocol :二进制编码格式
TCompactProtocol : 高效率、密集的二进制编码格式
TJSONProtocol : JSON 的数据编码协议
TSimpleJSONProtocol : 只提供 JSON 只写的协议,适用于通过脚本语言解析
19
Transport
Tsocket :使用阻塞式 I/O 进行传输
TFramedTransport :非阻塞,按块大小传输
TNonblockingTransport :非阻塞,用于异步客户端
20
Servers
TSimpleServer :单线程服务端,阻塞式 I/O
TThreadPoolServer :多线程服务端,阻塞式 I/O
TNonblockingServer :多线程服务端,非阻塞式 I/O
21
Hello.java
22
Process: Client
23
Process: Server
24
comparing: Size Comparison
http://jnb.ociweb.com/jnb/jnbJun2009.html
25
Comparing : Performance
http://jnb.ociweb.com/jnb/jnbJun2009.html
26
Comparing: Performance
http://jnb.ociweb.com/jnb/jnbJun2009.html
27
参考资料
官网 http://thrift.apache.org/
wiki http://wiki.apache.org/thrift/FrontPage
论文 http://thrift.apache.org/static/thrift-20070401.pdf
THRIFThttp://Jiaqing.me
2012-03-13
-END-