1. On hacknews today, many people are arguing about messagepack. First understand what is MessagePack: MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between ages like JSON. But unlike JSON, it is very fast and small.
2. The main use of MessagePack is explained by the author. The first is Space-efficient storage for Memcache entries (Pinterest), which saves Space for mamcache applications; the other is for RPC transmission. 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. The controversy lies in benchmark of MessagePack. He is much faster than protocolBuffer and Json. But some people don't believe it. Do a test under javasrept (json and messagePack ). It is found that MessagePack only compresses about 10% less data than json, while the compression and decompression time is much time-consuming compared with the json parser.
4. "MsgPack. JSON: Cut your client-server exchange traffic by 50% with one line of code "This article uses messagePack to optimize the server, reduce the server data volume, and make more reasonable use of bandwidth. The author stressed that they would rather waste 0.5 ms-1 ms of the client, but the server uses the ruby MessagePack parser, which is 5 times faster than JSON.
The differenceJSONIs, that MsgPack isBinary-based-This gives the possibility to make the exchanged dataA) 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 parseAndEncode, Having a parser parse 40 bytes takes about twice as long as parsing 20 bytes.
Copy codeThe Code is as follows:
MyJSONString = JSON. stringify (myObject );
MyObject = JSON. parse (myJSONString );
Var myByteArray = msgpack. pack (myObject );
MyObject = msgpack. unpack (myByteArray );
The authors of MessagePack also think that MessagePack may not be the best choice for client-side serialization as described by the blog author. References 2 are a little tragic.
5. BSon is a binary form of Json, but it is not compatible with JSon syntax. However, MessagePack ensures semantic consistency.
6. Different scenarios lead to different technical applications.
Try MessagePack in PHP
It's like JSON. but fast and small.
This sentence attracted me and gave me a look.
Official Website: http://msgpack.org
The official installation method is confusing. There is no php Directory under the msgpack directory... only the directories such as csharp, erlang, go, java, and ruby are displayed.
Copy codeThe Code is as follows:
Git clone https://github.com/msgpack/msgpack.git
Cd msgpack/php
Phpize
./Configure & make install
Still found in PHP official website Extension: http://pecl.php.net/package/msgpack
Last Updated:, yesterday's version.
Installation Process:
Copy codeThe Code is as follows:
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
Add msgpack. so to php. ini, restart php, and complete the installation.
Start test:
$ Data = array (0 => 'abcdefhijklmnopqrstuvwxy', 1 => 'xiamen ', 'abc' => '123 ');
Msgpack_pack, json_encode, and serialize are respectively set to 50, 62, and 87.
Then execute the command 10000 times, respectively. The time consumed is 9.95 milliseconds, 17.45 milliseconds, and 8.85 milliseconds.
Unlocks 10000 executions, time consumed: 14.76 milliseconds, 23.93 milliseconds, 14.61 milliseconds
Msgpack has a performance of at least over json50%. Although it is similar to the speed of serialize, the space occupied by serialize is much higher.
In addition, the GBK program is convenient. msgpack_pack can also be used in Chinese. If json is used, it must be converted to UTF-8 in batches before json_encode can be used.
Reference:
1. MessagePack Official Website
2, MsgPack vs. JSON: Cut your client-server exchange traffic by 50% with one line of code
HN comment: http://news.ycombinator.com/item? Id = 4090831
3, My thoughts on MessagePack
HN comment: http://news.ycombinator.com/item? Id = 4092969
4. Performance Comparison Between MessagePack and JSON in JS
HN comment: http://news.ycombinator.com/item? Id = 4091051