My thoughts on MessagePack
21–28 of 28 posts
Re: My thoughts on MessagePack
#22cheald has an excellent comment regarding MessagePack, JSON, and Protocol Buffers in the post from 15 hours ago: http://news.ycombinator.com/item?id=4091051 MessagePack is not smaller than gzip'd JSON MessagePack is not faster than JSON when a browser is involved Other comments from that post include: MessagePack is not human readable MessagePack has issues with UTF-8 Small packets also have significant TCP/IP overhe…
Although the original blog post focuses on JavaScript and browsers, MessagePack itself doesn't mainly focus on them. A major use case of MessagePack is to store serialized objects in memcached. A blog post written by Pinterest describes this use case ( http://engineering.pinterest.com/posts/2012/memcache-games/ ). They use MessagePack with Python which is faster than one with JavaScript. They could store more objects…
* RPC communication between servers where binary data is exchanged and its structure is not always the same (ie. difficult to use something that requires an IDL).
* Serialization and storage of objects that will be sent over the network (note: you can batch MessagePack objects just by concatenating them).
* Communication between a server and a native mobile application. Native applications live in a binary world whereas Web applications live in a text-based world where JSON is better.
The human readability argument is poor: the JSON that is sent over a network is not usually human readable, so you would use a prettyfier to read it anyway. Moreover a MessagePack message is standalone / self-describing, ie. you don't need an IDL description to read it. So in both case, reading the message is just adding another block to a pipeline...
Re: My thoughts on MessagePack
#23Re: My thoughts on MessagePack
#24Earlier quoted context omitted.
As nice as Message Pack might be, 'The best way of serialization' I'm not sure is a very helpful statement. It can't be 'the best' because 'the best' depends on the specifics of what you are doing. As noted in the OP: "...its pros and cons should be carefully considered, and there are many situations where it simply does not offer enough advantage...". I, for instance, am still using the much-less-cool yaml, because…
Isn't JSON a subset of YAML? So isn't it, quite literally, that YAML > JSON?
Re: My thoughts on MessagePack
#25What if you take compression and deserialization out of the picture? For example, in my server I have a hash like data structure that gets turned into JSON for browsers and byte array for mobile clients.
For example, because the data has to be transferred at fast rates and will be going over mobile networks. The size of the packet matters because every millisecond counts.
Then to read the data, I simply read the stream of bytes and build the objects I need on the client. This has to happen mostly without allocations for example on Android to avoid the GC.
So a few questions: Does deserializing JSON cause any memory allocations? If you're not tokenizing the data and don't need to parse it, will it be a significant gain over s serialized byte protocol or JSON?
In any case, I'll experiment on my end and perhaps blog about my own findings.
Re: My thoughts on MessagePack
#26Very interesting discussion. I work on a 2D MMORPG for Android. This is extremely relevant to me. I have a few questions though. What if you take compression and deserialization out of the picture? For example, in my server I have a hash like data structure that gets turned into JSON for browsers and byte array for mobile clients. For example, because the data has to be transferred at fast rates and will be going ove…
As for strings, JSON has to allocate memory and copy to deserialize strings because strings are escaped.
MessagePack does't have to allocate/copy because the serialized format of strings is same as the format in memory. But it depends on the implementation whether actually it doesn't allocate/copy.
C++ and Ruby implementations try to suppress allocation and copying (zero-copy). But Java implementation doesn't support zero-copy feature so far (we have plan to do so. Here is "TODO" comment: https://github.com/msgpack/msgpack-java/blob/master/src/main...).
As for the other types, C++ implementation (and new Ruby implementation which is under development) has memory pool which optimizes those memory allocations petterns. But it's hard to implement such optimizations for Java because JVM (and Dalvik VM) doesn't allow to hook object allocation.
Re: My thoughts on MessagePack
#27Very interesting discussion. I work on a 2D MMORPG for Android. This is extremely relevant to me. I have a few questions though. What if you take compression and deserialization out of the picture? For example, in my server I have a hash like data structure that gets turned into JSON for browsers and byte array for mobile clients. For example, because the data has to be transferred at fast rates and will be going ove…
Disclaimer: I'm authoer of MessagePack for C++/Ruby and committer of one for Java. As for strings, JSON has to allocate memory and copy to deserialize strings because strings are escaped. MessagePack does't have to allocate/copy because the serialized format of strings is same as the format in memory. But it depends on the implementation whether actually it doesn't allocate/copy. C++ and Ruby implementations try to s…
But MsgPack looks interesting as well and, if anything, these blog posts have brought it into the light for me.
I looked at the java class and what might help is if you can set a buffer size and use that buffer to store the data in the buffer and expand it if necessary. But that seems like a lot of work. But yeah, not sure if you can optimize based on usage patterns due to the constraint you said. In any case, great stuff and thanks for the info.
Re: My thoughts on MessagePack
#28We're using MessagePack in a Rails application to log user behaviors and analyze them. Compared with other serialization libraries such as Protocol Buffers, Avro or BSON, one of the advantages of MessagePack is compatibility with JSON. (In spite of its name, BSON has special types which cause incompatibility with JSON) It means we can exchange objects sent from browsers (in JSON format) between servers written in dif…
If JSON compatibility is an issue, have you looked at UBJSON? http://ubjson.org/ May be a bit bigger than msgpack but is damn-near human readable even in its binary format and really easy to encode/decode. Also 1:1 compatibility with JSON. Compatibility and simplicity were the core design tenantes. It may not be the right choice, just throwing it out there incase it helps. Disclaimer: I am the author of the spec.
Another one is that it doesn't use the value space of tags as efficiently as message pack. I would use the unused space to encode small string size in the tag since objects (associative arrays) have generally many short identifier strings as keys.
I sent these as comments and requests for change but didn't receive any response yet. I don't know how open its design process is.