SlideShare uma empresa Scribd logo
1 de 28
http://Jiaqing.me
      2012-03-13
大纲

 Thrift简介
 Thrift设计




             2
Thrift简介
 Thrift是什么
 Thrift解决什么问题
 简单示例




                 3
What:Introduction of Thrift

 实现跨语言的服务访问框架
 是一种IDL,定义了数据结构和服务描述
 自动生成指定语言的客户端、服务端

 opensource by




                              4
What:Features

 接口定义语言(IDL)
 多语言支持:C/C++/Java/PHP/Perf/Ruby..
 名字空间支持
 通用数据类型
 支持容器类型
 支持自定义异常
…



                                     5
What:Non-features

 循环依赖
 继承
 多态
 重载
 混合数据类型的集合
 返回null




                    6
Why:the Problem FB Encountered

 各技术体系间的统一桥梁
 性能需求




                                 7
How:A Sample

 下载源码包和代码编译器
 http://thrift.apache.org/download/




                                      8
How:A Sample

 编译,生成基础jar包




                9
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()

     }

                                                10
How:A Sample

 生成客户端/服务端代码




                11
How:A Sample

 编写客户端




               12
How:A Sample

 服务具体实现




               13
How:A Sample

 编写服务端




               14
Thrift设计
 总体架构
 主要功能
 处理流程




           15
Arch

 提供通用的传输层、协议层、I/O层(红色以下)
 通过工具生成客户端/服务端读写逻辑(红色)
 RD只需关注业务逻辑(黄色)




                          16
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: 对应服务的类                                17
Protocols

 TBinaryProtocol
                :二进制编码格式
 TCompactProtocol: 高效率、密集的二进制编码格式
 TJSONProtocol : JSON 的数据编码协议
 TSimpleJSONProtocol : 只提供 JSON 只写的协议,
 适用于通过脚本语言解析




                                          18
Transport

 Tsocket:使用阻塞式 I/O 进行传输
 TFramedTransport :非阻塞,按块大小传输
 TNonblockingTransport :非阻塞,用于异步客户端




                                       19
Servers

 TSimpleServer:单线程服务端,阻塞式 I/O
 TThreadPoolServer:多线程服务端,阻塞式 I/O
 TNonblockingServer:多线程服务端,非阻塞式 I/O




                                       20
Hello.java




             21
Process:Client




                 22
Process:Server




                 23
comparing:Size Comparison




                http://jnb.ociweb.com/jnb/jnbJun2009.html
                                                            24
Comparing : Performance




                 http://jnb.ociweb.com/jnb/jnbJun2009.html
                                                             25
Comparing:Performance




               http://jnb.ociweb.com/jnb/jnbJun2009.html
                                                           26
参考资料

 官网      http://thrift.apache.org/

 wiki   http://wiki.apache.org/thrift/FrontPage

 论文      http://thrift.apache.org/static/thrift-20070401.pdf




                                                                27
http://Jiaqing.me
      2012-03-13
          -END-

Mais conteúdo relacionado

Destaque

Old Greens Vs Almost
Old Greens Vs AlmostOld Greens Vs Almost
Old Greens Vs Almostpaobazzi
 
Crew, Foia, Documents 008692 - 008793
Crew, Foia, Documents 008692 - 008793Crew, Foia, Documents 008692 - 008793
Crew, Foia, Documents 008692 - 008793Obama White House
 
Crew, Foia, Documents 011528 - 011622
Crew, Foia, Documents 011528 - 011622Crew, Foia, Documents 011528 - 011622
Crew, Foia, Documents 011528 - 011622Obama White House
 
SADI SWSIP '09 'cause you can't always GET what you want!
SADI SWSIP '09  'cause you can't always GET what you want!SADI SWSIP '09  'cause you can't always GET what you want!
SADI SWSIP '09 'cause you can't always GET what you want!Mark Wilkinson
 
Rest In Peace Tribute Tour 7 23 09
Rest In Peace Tribute Tour 7 23 09Rest In Peace Tribute Tour 7 23 09
Rest In Peace Tribute Tour 7 23 09pageway
 
Ms.Nl.9031 Smoelenboek Wpc Final2
Ms.Nl.9031 Smoelenboek Wpc Final2Ms.Nl.9031 Smoelenboek Wpc Final2
Ms.Nl.9031 Smoelenboek Wpc Final2Renataadelino
 
La apatía
La apatíaLa apatía
La apatíacampir
 
21st Century Skills Pp
21st Century Skills Pp21st Century Skills Pp
21st Century Skills Ppheyjohnreese
 
Websense Hosted Email Security
Websense Hosted Email SecurityWebsense Hosted Email Security
Websense Hosted Email Securityfartur
 
Supervision - Replacing Carrots and Sticks
Supervision - Replacing Carrots and SticksSupervision - Replacing Carrots and Sticks
Supervision - Replacing Carrots and Stickspsalvet
 
ARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CIARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CICosmin Poieana
 
What google tells_you
What google tells_youWhat google tells_you
What google tells_youbwebster719
 
Almost vs San Juan2009
Almost vs San Juan2009Almost vs San Juan2009
Almost vs San Juan2009paobazzi
 
4826 201211071011
4826 2012110710114826 201211071011
4826 201211071011Anita S
 
Internet Pr
Internet PrInternet Pr
Internet PrPRT
 
Crew, Foia, Documents 008159 - 008236
Crew, Foia, Documents 008159 - 008236Crew, Foia, Documents 008159 - 008236
Crew, Foia, Documents 008159 - 008236Obama White House
 
Crew documents 020334 - 020392
Crew documents 020334 - 020392Crew documents 020334 - 020392
Crew documents 020334 - 020392Obama White House
 

Destaque (20)

Old Greens Vs Almost
Old Greens Vs AlmostOld Greens Vs Almost
Old Greens Vs Almost
 
Crew, Foia, Documents 008692 - 008793
Crew, Foia, Documents 008692 - 008793Crew, Foia, Documents 008692 - 008793
Crew, Foia, Documents 008692 - 008793
 
Crew, Foia, Documents 011528 - 011622
Crew, Foia, Documents 011528 - 011622Crew, Foia, Documents 011528 - 011622
Crew, Foia, Documents 011528 - 011622
 
SADI SWSIP '09 'cause you can't always GET what you want!
SADI SWSIP '09  'cause you can't always GET what you want!SADI SWSIP '09  'cause you can't always GET what you want!
SADI SWSIP '09 'cause you can't always GET what you want!
 
Rest In Peace Tribute Tour 7 23 09
Rest In Peace Tribute Tour 7 23 09Rest In Peace Tribute Tour 7 23 09
Rest In Peace Tribute Tour 7 23 09
 
F I L O S O F I A2
F I L O S O F I A2F I L O S O F I A2
F I L O S O F I A2
 
Social Story Roshen
Social Story   RoshenSocial Story   Roshen
Social Story Roshen
 
Ms.Nl.9031 Smoelenboek Wpc Final2
Ms.Nl.9031 Smoelenboek Wpc Final2Ms.Nl.9031 Smoelenboek Wpc Final2
Ms.Nl.9031 Smoelenboek Wpc Final2
 
Crm User Training Chinese
Crm User Training ChineseCrm User Training Chinese
Crm User Training Chinese
 
La apatía
La apatíaLa apatía
La apatía
 
21st Century Skills Pp
21st Century Skills Pp21st Century Skills Pp
21st Century Skills Pp
 
Websense Hosted Email Security
Websense Hosted Email SecurityWebsense Hosted Email Security
Websense Hosted Email Security
 
Supervision - Replacing Carrots and Sticks
Supervision - Replacing Carrots and SticksSupervision - Replacing Carrots and Sticks
Supervision - Replacing Carrots and Sticks
 
ARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CIARGUS - THE OMNISCIENT CI
ARGUS - THE OMNISCIENT CI
 
What google tells_you
What google tells_youWhat google tells_you
What google tells_you
 
Almost vs San Juan2009
Almost vs San Juan2009Almost vs San Juan2009
Almost vs San Juan2009
 
4826 201211071011
4826 2012110710114826 201211071011
4826 201211071011
 
Internet Pr
Internet PrInternet Pr
Internet Pr
 
Crew, Foia, Documents 008159 - 008236
Crew, Foia, Documents 008159 - 008236Crew, Foia, Documents 008159 - 008236
Crew, Foia, Documents 008159 - 008236
 
Crew documents 020334 - 020392
Crew documents 020334 - 020392Crew documents 020334 - 020392
Crew documents 020334 - 020392
 

Semelhante a Thrift

Accelerating or Complicating PHP execution by LLVM Compiler Infrastructure
Accelerating or Complicating PHP execution by LLVM Compiler Infrastructure Accelerating or Complicating PHP execution by LLVM Compiler Infrastructure
Accelerating or Complicating PHP execution by LLVM Compiler Infrastructure National Cheng Kung University
 
Rpc原理与实现
Rpc原理与实现Rpc原理与实现
Rpc原理与实现wavefly
 
千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7javatwo2011
 
C1000K高性能服务器构建技术
C1000K高性能服务器构建技术C1000K高性能服务器构建技术
C1000K高性能服务器构建技术Feng Yu
 
Bluemix Node-Red Part I
Bluemix Node-Red Part IBluemix Node-Red Part I
Bluemix Node-Red Part IJoseph Chang
 
Hcsm lect-20120913
Hcsm lect-20120913Hcsm lect-20120913
Hcsm lect-20120913lusecheng
 
Google protocol buffers简析
Google protocol buffers简析Google protocol buffers简析
Google protocol buffers简析wavefly
 
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509tidesq
 
Introduction to C++ over CLI
Introduction to C++ over CLIIntroduction to C++ over CLI
Introduction to C++ over CLI建興 王
 
美团点评技术沙龙13-前端工程化开发方案app-proto介绍
美团点评技术沙龙13-前端工程化开发方案app-proto介绍美团点评技术沙龙13-前端工程化开发方案app-proto介绍
美团点评技术沙龙13-前端工程化开发方案app-proto介绍美团点评技术团队
 
Baidu LSP and DISQL for Log Analysis
Baidu LSP and DISQL for Log AnalysisBaidu LSP and DISQL for Log Analysis
Baidu LSP and DISQL for Log AnalysisXiaoming Chen
 
Effective.enterprise.java中文版
Effective.enterprise.java中文版Effective.enterprise.java中文版
Effective.enterprise.java中文版Peter Fan
 
OPOA in Action -- 使用MagixJS简化WebAPP开发
OPOA in Action -- 使用MagixJS简化WebAPP开发OPOA in Action -- 使用MagixJS简化WebAPP开发
OPOA in Action -- 使用MagixJS简化WebAPP开发leneli
 
深入浅出Netty l.t
深入浅出Netty   l.t深入浅出Netty   l.t
深入浅出Netty l.toleone
 
Hbase在淘宝的应用与优化 修改
Hbase在淘宝的应用与优化 修改Hbase在淘宝的应用与优化 修改
Hbase在淘宝的应用与优化 修改yp_fangdong
 
System verilog简介
System verilog简介System verilog简介
System verilog简介wujianping
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvementsXinchen Hui
 
Node.js在淘宝的应用实践
Node.js在淘宝的应用实践Node.js在淘宝的应用实践
Node.js在淘宝的应用实践taobao.com
 
Windows 8 apps dev.整理及分享
Windows 8 apps dev.整理及分享Windows 8 apps dev.整理及分享
Windows 8 apps dev.整理及分享Liyao Chen
 

Semelhante a Thrift (20)

Accelerating or Complicating PHP execution by LLVM Compiler Infrastructure
Accelerating or Complicating PHP execution by LLVM Compiler Infrastructure Accelerating or Complicating PHP execution by LLVM Compiler Infrastructure
Accelerating or Complicating PHP execution by LLVM Compiler Infrastructure
 
Rpc原理与实现
Rpc原理与实现Rpc原理与实现
Rpc原理与实现
 
千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7
 
C1000K高性能服务器构建技术
C1000K高性能服务器构建技术C1000K高性能服务器构建技术
C1000K高性能服务器构建技术
 
Bluemix Node-Red Part I
Bluemix Node-Red Part IBluemix Node-Red Part I
Bluemix Node-Red Part I
 
Hcsm lect-20120913
Hcsm lect-20120913Hcsm lect-20120913
Hcsm lect-20120913
 
Google protocol buffers简析
Google protocol buffers简析Google protocol buffers简析
Google protocol buffers简析
 
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
 
Introduction to C++ over CLI
Introduction to C++ over CLIIntroduction to C++ over CLI
Introduction to C++ over CLI
 
LLVM introduction
LLVM introductionLLVM introduction
LLVM introduction
 
美团点评技术沙龙13-前端工程化开发方案app-proto介绍
美团点评技术沙龙13-前端工程化开发方案app-proto介绍美团点评技术沙龙13-前端工程化开发方案app-proto介绍
美团点评技术沙龙13-前端工程化开发方案app-proto介绍
 
Baidu LSP and DISQL for Log Analysis
Baidu LSP and DISQL for Log AnalysisBaidu LSP and DISQL for Log Analysis
Baidu LSP and DISQL for Log Analysis
 
Effective.enterprise.java中文版
Effective.enterprise.java中文版Effective.enterprise.java中文版
Effective.enterprise.java中文版
 
OPOA in Action -- 使用MagixJS简化WebAPP开发
OPOA in Action -- 使用MagixJS简化WebAPP开发OPOA in Action -- 使用MagixJS简化WebAPP开发
OPOA in Action -- 使用MagixJS简化WebAPP开发
 
深入浅出Netty l.t
深入浅出Netty   l.t深入浅出Netty   l.t
深入浅出Netty l.t
 
Hbase在淘宝的应用与优化 修改
Hbase在淘宝的应用与优化 修改Hbase在淘宝的应用与优化 修改
Hbase在淘宝的应用与优化 修改
 
System verilog简介
System verilog简介System verilog简介
System verilog简介
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvements
 
Node.js在淘宝的应用实践
Node.js在淘宝的应用实践Node.js在淘宝的应用实践
Node.js在淘宝的应用实践
 
Windows 8 apps dev.整理及分享
Windows 8 apps dev.整理及分享Windows 8 apps dev.整理及分享
Windows 8 apps dev.整理及分享
 

Thrift