Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

json

thrift

Thrift's primary goal is to enable efficient and reliable communication across programming languages. but I think HTTP-RPC can also do that, web developer almost everyone knows how to work on http and it is easier to implement HTTP-RPC(json) than Thrift,

Maybe Thrift-RPC is faster, then who can tell me the difference in perfermance between them?

like image 688
jebbthe Avatar asked Mar 16 '12 05:03

jebbthe


People also ask

Does Thrift use HTTP?

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 supports persistent connections and avoids the continuous TCP and HTTP handshakes that HTTP incurs.

Is Thrift an RPC?

Thrift is a lightweight, language-independent software stack with an associated code generation mechanism for RPC. Thrift provides clean abstractions for data transport, data serialization, and application level processing. Thrift was originally developed by Facebook and now it is open sourced as an Apache project.

How does Thrift RPC work?

Apache Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages.

What is thrift protocol?

Thrift is an interface definition language and binary communication protocol used for defining and creating services for numerous programming languages. It was developed at Facebook for "scalable cross-language services development" and as of 2020 is an open source project in the Apache Software Foundation.


2 Answers

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 is more compact than HTTP, and can easily be extended to support things like encryption, compression, non blocking IO, etc.

  3. 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)

  4. Thrift supports persistent connections and avoids the continuous TCP and HTTP handshakes that HTTP incurs.

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:

http://www.slideshare.net/dvirsky/introduction-to-thrift

It has links to a few other alternatives to thrift.

like image 141
Not_a_Golfer Avatar answered Sep 24 '22 20:09

Not_a_Golfer


Here is good resource on performance comparison of different serializers: https://github.com/eishay/jvm-serializers/wiki/

Speaking specifically of Thrift vs JSON: Thrift performance is comparable to the best JSON libraries (jackson, protostuff), and serialized size is somewhat lower.

IMO, strongest thrift advantages are convenient interoperable RPC invocations and convenient handling of binary data.

like image 27
Wildfire Avatar answered Sep 21 '22 20:09

Wildfire