为什么要用Thrift
Why Thrift, Why not HTTP RPC(JSON+gzip)
https://stackoverflow.com/questions/9732381/why-thrift-why-not-http-rpcjsongzip
A few reasons other than speed:
-
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.
- Thrift生成的代码,包含传递数据的数据结构。不用费劲地写客户端处理器,参数和返回值都被自动化实现验证,你可以很方便地对你的数据做常规的检查。
-
Thrift is more compact than HTTP, and can easily be extended to support things like encryption, compression, non blocking IO, etc.
- Thrift比HTTP协议更紧凑,很容易扩展去支持一些东西:加密,压缩,非阻塞的IO。
-
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)
- Thrift能够简单设置为使用HTTP协议和JSON协议,如果你需要这么做(比如说你的客户端运行在因特网的某个地方,需要穿越防火墙)。
-
Thrift supports persistent connections and avoids the continuous TCP and HTTP handshakes that HTTP incurs.
- 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: