1. 程式人生 > >為什麽要用Thrift

為什麽要用Thrift

wall enc compress don personal more text sta mat

Why Thrift, Why not HTTP RPC(JSON+gzip)

https://stackoverflow.com/questions/9732381/why-thrift-why-not-http-rpcjsongzip

89down voteaccepted

A few reasons other than speed:

  1. Thrift generates the client and server code completely, including the data structures you are passing, so you don‘t have to deal with anything other than writing the handlers and invoking the client. and everything, including parameters and returns are automatically validated and parsed. so you are getting sanity checks on your data for free.

  2. Thrift生成的代碼,包含傳遞數據的數據結構。不用費勁地寫客戶端處理器,參數和返回值都被自動化實現驗證,你可以很方便地對你的數據做常規的檢查。
  3. Thrift is more compact than HTTP, and can easily be extended to support things like encryption, compression, non blocking IO, etc.

  4. Thrift比HTTP協議更緊湊,很容易擴展去支持一些東西:加密,壓縮,非阻塞的IO。
  5. Thrift can be set up to use HTTP and JSON pretty easily if you want it (say if your client is somewhere on the internet and needs to pass firewalls)

  6. Thrift能夠簡單設置為使用HTTP協議和JSON協議,如果你需要這麽做(比如說你的客戶端運行在因特網的某個地方,需要穿越防火墻)。
  7. Thrift supports persistent connections and avoids the continuous TCP and HTTP handshakes that HTTP incurs.

  8. Thrift支持持久化連接,並且能夠避免並不斷的TCP和HTTP握手操作,這些操作常在HTTP協議裏發生。

Personally, I use thrift for internal LAN RPC and HTTP when I need connections from outside.

I hope all this makes sense to you. You can read a presentation I gave about thrift here:

為什麽要用Thrift