为什么是 Thrift,为什么不是 HTTP RPC(JSON+gzip)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9732381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:13:48  来源:igfitidea点击:

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

jsonthrift

提问by jebbthe

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,

Thrift 的主要目标是实现跨编程语言的高效可靠通信。但我认为 HTTP-RPC 也可以做到这一点,Web 开发人员几乎每个人都知道如何在 http 上工作,而且实现 HTTP-RPC(json) 比 Thrift 更容易,

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

也许Thrift-RPC更快,那么谁能告诉我它们之间的性能差异?

回答by Not_a_Golfer

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.

  1. Thrift 完全生成客户端和服务器代码,包括您传递的数据结构,因此除了编写处理程序和调用客户端之外,您无需处理任何其他事情。包括参数和返回在内的所有内容都会自动验证和解析。所以您可以免费对您的数据进行健全性检查。

  2. Thrift 比 HTTP 更紧凑,并且可以轻松扩展以支持加密、压缩、非阻塞 IO 等内容。

  3. 如果你愿意,Thrift 可以很容易地设置为使用 HTTP 和 JSON(比如你的客户端在互联网上的某个地方并且需要通过防火墙)

  4. Thrift 支持持久连接并避免 HTTP 引起的连续 TCP 和 HTTP 握手。

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

就个人而言,当我需要来自外部的连接时,我将 thrift 用于内部 LAN RPC 和 HTTP。

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

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

It has links to a few other alternatives to thrift.

它链接到其他一些节俭的替代品。

回答by Wildfire

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

这是关于不同序列化器性能比较的好资源:https: //github.com/eishay/jvm-serializers/wiki/

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

特别说一下 Thrift 与 JSON:Thrift 的性能可以与最好的 JSON 库(Hymanson、protostuff)相媲美,而序列化的大小要小一些。

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

IMO,最大的节俭优势是方便的可互操作的 RPC 调用和方便的二进制数据处理。