Apache Thrift和谷歌的协议缓冲区最大的优点和缺点是什么?


当前回答

正如我在“节俭vs协议缓冲区”主题中所说:

参考Thrift vs Protobuf vs JSON的比较:

Thrift supports out of the box AS3, C++, C#, D, Delphi, Go, Graphviz, Haxe, Haskell, Java, Javascript, Node.js, OCaml, Smalltalk, Typescript, Perl, PHP, Python, Ruby, ... C++, Python, Java - in-box support in Protobuf Protobuf support for other languages (including Lua, Matlab, Ruby, Perl, R, Php, OCaml, Mercury, Erlang, Go, D, Lisp) is available as Third Party Addons (btw. Here is SWI-Prolog support). Protobuf has much better documentation and plenty of examples. Thrift comes with a good tutorial Protobuf objects are smaller Protobuf is faster when using "optimize_for = SPEED" configuration Thrift has integrated RPC implementation, while for Protobuf RPC solutions are separated, but available (like Zeroc ICE ). Protobuf is released under BSD-style license Thrift is released under Apache 2 license

此外,对于这些解决方案,还有许多有趣的附加工具可用,这可能会决定。以下是Protobuf的示例:Protobuf-wireshark, protobufeditor。

其他回答

首先,protobuf并不是一个完整的RPC实现。它需要像gRPC这样的东西来配合。

与Thrift相比,gPRC非常慢:

http://szelei.me/rpc-benchmark-part1/

与python上的protobuff相比,我能够使用基于文本的协议获得更好的性能。然而,没有类型检查或其他花哨的utf8转换等…这是protobuff提供的。

因此,如果序列化/反序列化是您所需要的,那么您可能可以使用其他方法。

http://dhruvbird.blogspot.com/2010/05/protocol-buffers-vs-http.html

我认为基本的数据结构是不同的

协议缓冲区使用变长整数,即变长数字编码,将固定长度的数字转换为变长数字以节省空间。 Thrift提出了不同类型的序列化格式(称为“协议”)。 事实上,Thrift有两种不同的JSON编码和不少于三种不同的二进制编码方法。

总之,这两个库是完全不同的。Thrift喜欢一站式服务,为您提供完整的集成RPC框架和许多选项(支持跨语言),而Protocol Buffers更倾向于“只做一件事并做好它”。

Protobuf序列化对象大约比Thrift小30%。 你可能想用protobuf对象做的大多数操作(创建、序列化、反序列化)都比thrift慢得多,除非你打开optimize_for = SPEED选项。 Thrift具有更丰富的数据结构(Map, Set) Protobuf API看起来更干净,尽管生成的类都打包为内部类,这不是很好。 节俭枚举不是真正的Java枚举,也就是说,它们只是整数。Protobuf有真正的Java枚举。

要进一步了解差异,请查看这个开放源代码项目的源代码差异。

这里有一些很好的观点,我要再补充一个,以防有人在这里遇到。

Thrift gives you an option to choose between thrift-binary and thrift-compact (de)serializer, thrift-binary will have an excellent performance but bigger packet size, while thrift-compact will give you good compression but needs more processing power. This is handy because you can always switch between these two modes as easily as changing a line of code (heck, even make it configurable). So if you are not sure how much your application should be optimized for packet size or in processing power, thrift can be an interesting choice.

PS:请看thekvs的这个优秀的基准测试项目,它比较了许多序列化器,包括thrift-binary, thrift-compact和protobuf: https://github.com/thekvs/cpp-serializers

PS:有另一个名为YAS的序列化器也提供了这个选项,但它是无模式的,参见上面的链接。