json,serialize,msgpack比较

Posted jianfengye110

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json,serialize,msgpack比较相关的知识,希望对你有一定的参考价值。

速度

在redis中存入同样的压缩数据,取操作执行两个操作:

1 从redis中取

2 解压

3 统一json压缩后放出

 

ab测试:

[yejianfeng@openstack ~/httpd/usr/bin]$ ./ab -n 10000 -c 10 http://10.16.15.118:7701/location/testGet?type=json
Requests per second:    265.11 [#/sec] (mean)
Requests per second:    267.58 [#/sec] (mean)

Requests per second:    275.48 [#/sec] (mean)

Requests per second:    263.11 [#/sec] (mean)

Requests per second:    264.99 [#/sec] (mean)

 

[yejianfeng@openstack ~/httpd/usr/bin]$ ./ab -n 10000 -c 10 http://10.16.15.118:7701/location/testGet?type=serialize
Requests per second:    297.52 [#/sec] (mean)

Requests per second:    322.57 [#/sec] (mean)
Requests per second:    303.59 [#/sec] (mean)

Requests per second:    289.89 [#/sec] (mean)

Requests per second:    317.26 [#/sec] (mean)

 

[yejianfeng@openstack ~/httpd/usr/bin]$ ./ab -n 10000 -c 10 http://10.16.15.118:7701/location/testGet?type=msgpack

Requests per second:    288.07 [#/sec] (mean)
Requests per second:    306.73 [#/sec] (mean)

Requests per second:    313.61 [#/sec] (mean)

Requests per second:    289.49 [#/sec] (mean)

Requests per second:    307.84 [#/sec] (mean)

 

压缩比例:

[yejianfeng@test34x-nova /tmp]$ ll -h test*
-rw-r--r-- 1 server server 29K Jan  3 21:40 testjson
-rw-r--r-- 1 server server 22K Jan  3 21:40 testmsgpack
-rw-r--r-- 1 server server 31K Jan  3 21:40 testserialize

 

[yejianfeng@test34x-nova /tmp]$ ll test*   
-rw-r--r-- 1 server server 28942 Jan  3 21:40 testjson
-rw-r--r-- 1 server server 21993 Jan  3 21:40 testmsgpack
-rw-r--r-- 1 server server 31537 Jan  3 21:40 testserialize

 

msgpack是serizalize的69%

json是serizalize的91.8%

以上是关于json,serialize,msgpack比较的主要内容,如果未能解决你的问题,请参考以下文章

Python下Json和Msgpack序列化比较

MsgPack/Json性能数据

PHP 启动:无法加载动态库 php_msgpack_serialize

kafka-msgpack-json: 将msgpack和protobuf转化成json

msgpack 能否提供更好的性能和与 python 的 struct.pack() 相同的功能?

msgpack可以提供更好的性能和相同的python的struct.pack()功能吗?