###About thrift----The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.總體而言,就是開源的、跨平台的、無縫串連的開源架構。一般用於系統內個語言之間的RPC通訊。[原始碼位置](https://git-wip-us.apache.org/repos/asf/thrift)###為什麼產生了thrift---- 目前主流的資料轉送格式: xml與JSON相比體積太大,但是xml傳統,也不算複雜。 json 體積較小,新穎,但不夠完善。 thrift 體積超小,使用起來比較麻煩,不如前兩者輕便,但是對於 1.高並發 2.資料轉送量大 3.多語言環境 滿足其中2點使用 thrift還是值得的。 和其他協議對比(引用自https://www.liuhe36.cn/2013/07/introduction-of-thrift/): 其實有很多技術能支撐遠程調用,如常見的REST-JSON方式、REST-XML或RMI等,但REST方式的效率上確實不夠高,下面引用了幾張圖片,可以直觀的說明一些問題。 使用Thrift和其他方式的所產生的內容大小比較結果如下:](http://https://www.liuhe36.cn/wp-content/uploads/2013/07/thrift-size.png "在這裡輸入圖片標題")](https://www.liuhe36.cn/wp-content/uploads/2013/07/thrift-size.png "在這裡輸入圖片標題") 在中我們能明顯看出,最臃腫的是RMI,其次是xml,使用Thrift的TCompactProtocol協議和Google 的 Protocol Buffers 相差的不算太多,相比而言還是Google 的 Protocol Buffers效果最佳。 使用Thrift 中的協議和其他方式的所產生的運行開銷比較結果如下:](https://www.liuhe36.cn/wp-content/uploads/2013/07/thrift-load.png "在這裡輸入圖片標題") 在中我們能明顯看出,最佔資源是REST2中協議,使用Thrift的TCompactProtocol協議和Google 的 Protocol Buffers 相差的不算太多,相比而言Thrift的TCompactProtocol協議效果最佳。###資料類型####基本類型: bool:布爾值,true 或 false,對應 Java 的 boolean PHP bool byte:8 位有符號整數,對應 Java 的 byte PHP int i16:16 位有符號整數,對應 Java 的 short PHP int i32:32 位有符號整數,對應 Java 的 int PHP int i64:64 位元有符號整數,對應 Java 的 long PHP int double:64 位元浮點數,對應 Java 的 double PHP double string:未知編碼文本或二進位字串,對應 Java 的 String PHP string####結構體類型: struct:定義公用的對象,類似於 C 語言中的結構體定義,在 Java 中是一個 JavaBean,在PHP裡是一個類####容器類型: list:對應 Java 的 ArrayList PHP array set:對應 Java 的 HashSet PHP array map:對應 Java 的 HashMap PHP array####異常類型: exception:對應 Java 的 Exception PHP 的 Exception####服務類型: service:對應服務的類