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。

其他回答

它们都提供了许多相同的功能;然而,有一些不同之处:

节俭支持“例外” 协议缓冲区有更好的文档/示例 Thrift有一个内置的Set类型 协议缓冲区允许“扩展”——你可以扩展一个外部原型来添加额外的字段,同时仍然允许外部代码对这些值进行操作。在节俭中没有办法做到这一点 我发现协议缓冲区更容易阅读

基本上,它们是相当等效的(从我读到的内容来看,协议缓冲区的效率略高)。

正如我在“节俭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。

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

协议缓冲区: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运行时不能在Windows上运行。

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

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