protobuf和thrift对比

protobuf和thrift对比

数据类型

protobuf

thrift

protobuf

thrift

protobuf

thrift

protobuf

thrift

double

double

float

byte

i16

int32

i32

int64

i64

uint32

uint64

sint32

sint64

fixed32

fixed64

sfixed32

sfixed64

bool

bool

string

string

bytes

binary

message

struct

enum

enum

service

service

综合对比

protobuf

thrift

功能特性

主要是一种序列化机制

提供了全套rpc解决方案,包括序列化机制、传输层、并发处理框架等

支持语言

C++/Java/Python

C++, Java, Python, Ruby, Perl, PHP, C#, Erlang, Haskell

易用性

语法类似,使用方式等类似

生成代码的质量

可读性都还过得去,执行效率另测

升级时版本兼容性

均支持向后兼容和向前兼容

学习成本

功能单一,容易学习

功能丰富、学习成本高

文档&社区

官方文档较为丰富,google搜索protocol buffer有2000W+结果,google group被墙不能访问

官方文档较少,没有API文档,google搜索apache thrift仅40W结果,邮件列表不怎么活跃

性能对比 由于thrift功能较protobuf丰富,因此单从序列化机制上进行性能比较,按照序列化后字节数、序列化时间、反序列化时间三个指标进行,对thrift的二进制、压缩、protobuf三种格式进行对比。

测试方法:取了15000+条样本数据,分别写了三个指标的测试程序,在我自己的电脑上执行,其中时间测试循环1000次,总的序列化/反序列化次数1500W+。

平均字节数:

thrift二进制

535

thrift压缩

473

protobuf

477

序列化(1500W次)时间(ms):

thrift二进制

306034

thrift压缩

304256

protobuf

177652

反序列化(1500W次)时间(ms):

thrift二进制

287972

thrift压缩

315991

protobuf

157192

thrift的时间测试可能不是很准,由于thrift产生代码的复杂性,编写的测试代码为了适应其接口,在调用堆栈上可能有一些额外开销。

相关推荐

电脑键盘如何打出顿号
365bet英国

电脑键盘如何打出顿号

📅 07-04 👁️ 8654