54

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?

jebbthe
  • 543
  • 1
  • 5
  • 4

2 Answers2

98

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.

Vishal Verma
  • 842
  • 8
  • 18
Not_a_Golfer
  • 40,006
  • 7
  • 115
  • 81
  • 1
    Great answer Dvir! I am also very fond if Thrift and prefer it in most cases. The biggest difficulty is getting the Thrift compiler installed, but once done and combined with the appropriate maven plugin, you're set to go. The compact server/client code that is needed is incredibly sexy! – Jaco Van Niekerk Mar 16 '12 at 13:32
  • 1
    @JacoVanNiekerk thanks, I've compiled thrift so many times it seems trivial to me :). The biggest disadvantage in my perspective is that python servers don't play so nicely with thrift, with the GIL limitations (Actually one of the python servers in thrift is a conrtibution I made, that tries to tackle this). but for C++ or Java it's just awesome. – Not_a_Golfer Mar 16 '12 at 13:39
  • 2
    Most HTTP clients also support keep-alives :) – Xorlev Apr 19 '13 at 22:37
  • No. 4 can be easily mitigated by using keep-alive which all HTTP clients support. One can also POST binary (though it's not RESTful) which will help with compact over-the-wire transmission. – jeffreyveon Aug 12 '15 at 06:39
5

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.

Wildfire
  • 6,140
  • 2
  • 29
  • 50