erlang序列化工具性能对比(erlang protobuf和term_to_binary对比)

公司内部最近做了一个性能测试,发现逻辑处理服务的加解包速度不行,于是做了简单的benchmark,比对了公司用的protobuf库和term_to_binary的性能差异。想看看性能如何。

测试的protobuf是basho的erlang_protobuffs ,挺旧的了,而且已经不再维护。

先贴测试结果,本测试在我的mac上,用fusion虚拟的1核2g的ubuntu12.04,erlang16R3,跑的结果还是蛮惊人的。


(elogic@johnzeng-virtual-machine)1> logic_worker:test_util().
Protobuffer encoding 1000000 cost time is :9.698853 , that's 103104.97540276154 msg per second
Protobuffer decoding 1000000 cost time is :16.459741 , that's 60754.29740966154 msg per second
binary_to_term 1000000 terms cost time is :1.75269 , that's 570551.5521854977 msg per second
term_to_binary 1000000 terms cost time is :0.017986000000000002 , that's 55598799.06594017 msg per second
mqtt decoding 1000000 bianry cost time is :1.5215139999999998 , that's 657240.0911197664 msg per second
mqtt encoding 1000000 bianry cost time is :1.3142470000000002 , that's 760891.9784484955 msg per second

这个代码非常简单,就是针对同一个protobuf的binary数据,跑100w次,测量时间,然后计算平均ops。可以看到protobuf的组包速度,比解包速度要快很多。超不多是0.8倍的差异。但是更加惊人的是term_to_binary的性能,是protobuf的20倍速度。公司已经决定后面要换用term_to_binary了23333。

后面一个是mqtt的包序列化和反序列化,这个如果不感兴趣可以不管。

最后附上代码。由于结构体属于公司内部文件,不能po上来,但是大概意思大家知道就行了。这个文章后面会陆续补上其他序列化工具的性能分析。


test_util() ->
    test_util(1000000).
test_util(Time) ->
    Package = <<8,132,194,194,224,10,16,219,14,24,0,32,0,42,9,108,111,
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值