中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

php MessagePack介紹

1,今天在hacknews上看到很多人對(duì)messagepack的爭(zhēng)論。首先了解什么是MessagePack:MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.

2,MessagePack的主要用途,作者解釋說(shuō)有兩大用途:一是Space-efficient storage for Memcache entries (Pinterest),節(jié)省空間類型的mamcache應(yīng)用;另一個(gè)是用于RPC傳輸, This use case is fairly close to my original intent. When one is designing an RPC system, one of the first tasks is to specify and implement a communication protocol. This process can get pretty hairy as you need to worry about a lot of low-level issues like Endian-ness. By using MessagePack, one can skip designing and implementing a communication protocol entirely and accelerate development.

3,爭(zhēng)議的地方是MessagePack的benchmark說(shuō),他比protocolBuffer,Json快很多倍。但是有人不相信,做個(gè)Javasript下的測(cè)試(json與messagePack)。發(fā)現(xiàn)MessagePack僅是壓縮后的數(shù)據(jù)比json少10%左右,而壓縮和解壓時(shí)間則和json的解析器比起來(lái)要費(fèi)時(shí)很多。

4,“MsgPack vs. JSON: Cut your client-server exchange traffic by 50% with one line of code”這篇文章使用了messagePack做服務(wù)器的優(yōu)化,降低服務(wù)器的數(shù)據(jù)量,更加合理的利用帶寬。作者強(qiáng)調(diào)了他們寧愿浪費(fèi)客戶端的0.5ms―1ms,但是服務(wù)器使用ruby的MessagePack解析器,效率能夠比JSON快5倍。

The difference to JSON is, that MsgPack is binary-based - this gives the possibility to make the exchanged data a) smaller and use less bytes, I guess we all know the advantages of that, however there is an even bigger advantage: b) It is faster to parse and encode, having a parser parse 40 bytes takes about twice as long as parsing 20 bytes.

復(fù)制代碼 代碼如下:
myJSONString = JSON.stringify(myObject);
myObject = JSON.parse(myJSONString);
var myByteArray = msgpack.pack(myObject);
myObject = msgpack.unpack(myByteArray);

MessagePack作者也認(rèn)為MessagePack may not be the best choice for client-side serialization as described by the blog author.引用2的作者有點(diǎn)小悲劇。

5,BSon是Json的二進(jìn)制形式,但是與JSon有語(yǔ)法不兼容的地方。但是MessagePack保證語(yǔ)義上能夠做到一致。

6,場(chǎng)景需求不同,導(dǎo)致技術(shù)的應(yīng)用有所差異。

php試用MessagePack

It's like JSON. but fast and small.

這句吸引了我,去瞧了下。

官網(wǎng):http://msgpack.org

官方的安裝方法忽悠人,msgpack目錄下根本沒php目錄...只看到csharp,erlang,go,Java,ruby等目錄。

復(fù)制代碼 代碼如下:
git clone https://github.com/msgpack/msgpack.git
cd msgpack/php
phpize
./configure && make && make install


還是在php官網(wǎng)擴(kuò)展找到了:http://pecl.php.NET/package/msgpack
最后更新時(shí)間:2012-09-14,昨天的版本。
附安裝過程:

復(fù)制代碼 代碼如下:
wget http://pecl.php.NET/get/msgpack-0.5.2.tgz
tar zxf msgpack-0.5.2.tgz
cd msgpack-0.5.2
/usr/local/hx/php/bin/phpize
./configure --with-php-config=/usr/local/hx/php/bin/php-config
make && make install


然后把msgpack.so加到php.ini里,重啟php,完成安裝。

開始測(cè)試:
$data = array(0=>'abcdefghijklmnopqrstuvwxyz',1=>'廈門','abc'=>'1234567890');

分別對(duì)其msgpack_pack,json_encode,serialize,長(zhǎng)度為:50,62,87
然后分別執(zhí)行10000次,耗時(shí):9.95 毫秒,17.45 毫秒,8.85 毫秒
解開執(zhí)行10000次,耗時(shí):14.76 毫秒,23.93 毫秒,14.61 毫秒

msgpack的性能至少超過json50%,雖然和serialize其實(shí)速度差不多,但serialize占用空間明顯比較多。

另外,GBK的程序方便了,中文也可以msgpack_pack,用json的話還要批量轉(zhuǎn)換成utf-8之后才能json_encode。

引用:

1,MessagePack官方網(wǎng)站

2,MsgPack vs. JSON: Cut your client-server exchange traffic by 50% with one line of code

HN評(píng)論地址:http://news.ycombinator.com/item?id=4090831

3,My thoughts on MessagePack

HN評(píng)論地址:http://news.ycombinator.com/item?id=4092969

4 JS下MessagePack與JSON性能對(duì)比

HN評(píng)論地址:http://news.ycombinator.com/item?id=4091051

php技術(shù)php MessagePack介紹,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 在线免费国产视频 | av黄色在线观看 | 欧美性极品xxxx做受 | 久久国产精品-国产精品 | 日本欧美在线观看视频 | 蜜桃视频一区二区三区 | 成年人在线观看视频 | 91精品国产综合久久久久久 | 国产一级免费视频 | 成人国内精品久久久久一区 | 亚洲精品日韩精品 | 日本精品一区二区三区在线观看视频 | 91久久综合| 在线视频 亚洲 | 日本三级电影免费观看 | 免费观看www7722午夜电影 | 亚洲成人免费观看 | 亚洲综合精品 | 色视频网站 | 中文一区二区 | 日本偷偷操 | 精品久久久久久久久久久久 | 久久久资源 | 一级电影免费看 | 黄色一级大片视频 | 久久久久久色 | 欧美日一区二区 | 国产探花在线观看视频 | 婷婷精品 | 欧美日韩精品一区二区三区四区 | 亚洲福利一区二区 | 婷婷桃色网 | 国产乱码精品一区二区三区忘忧草 | 国产在线麻豆精品入口 | 日韩欧美手机在线 | 日韩电影中文字幕 | 日韩精品久久久久 | 国产欧美日韩视频 | 日本精品久久 | 欧美亚洲激情 | 亚洲精品视频在线看 |