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。

其他回答

协议缓冲区似乎有一个更紧凑的表示,但这只是我从阅读节俭白皮书中得到的印象。用他们自己的话来说:

我们决定反对一些极端的存储优化(即包装 小整数转换成ASCII或使用7位延续格式) 为了代码的简单性和清晰度。这些改变 当我们遇到一个性能关键的问题时,可以很容易地做出什么 需要它们的用例。

此外,这可能只是我的印象,但协议缓冲区似乎有一些更厚的抽象结构版本控制。Thrift确实提供了一些版本控制支持,但是要做到这一点需要付出一些努力。

另一个重要的区别是默认支持的语言。

协议缓冲区:Java, Android Java, c++, Python, Ruby, c#, Go, Objective-C, Node.js 节俭:Java、c++、Python、Ruby、c#、Go、Objective-C、JavaScript、Node.js、Erlang、PHP、Perl、Haskell、Smalltalk、OCaml、Delphi、D、Haxe

两者都可以扩展到其他平台,但这些都是现成的语言绑定。

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

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的序列化器也提供了这个选项,但它是无模式的,参见上面的链接。

我认为大多数观点都忽略了一个基本事实,那就是Thrift是一个RPC框架,它恰好能够使用各种方法(二进制、XML等)序列化数据。

协议缓冲区是纯粹为序列化而设计的,它不像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。