2012年9月26日

為什麼要用Thrift?

在看ElasticSearch時候發現Thrift可以替代HTTP RPC
Thrift is a software framework, for scalable cross-language services development

但是HTTP是我們比較熟悉的,為什麼需要Thrift?


搜尋發現這篇 Why Thrift, Why not HTTP RPC(JSON+gzip) 

A few reasons other than speed:

1. thrift generates the client and server code completetly, 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 is more compact than HTTP, and can be easily extended to support things like encryption, compression, non blocking IO, etc.

3. actually thrift can be set up to use HTTP and JSON pretty easily if you want it (say if your client is somewhere on the interent and needs to pass firewalls)

4. thrift supporst persitent connections and avoids the continuous TCP and HTTP handshakes that HTTP incurs.