MessagePack: The Missing Serializer
MessagePack in a nutshell
Greetings! We are kicking off the Treasure Data blog with MessagePack, the efficient, blazing fast serializer at the core of our technology.
The best way to describe MessagePack is “JSON on steroids”. It supports an almost identical set of data types as JSON —Nil, Boolean, Integer, Float, String, Array, and Associative Array— but runs much faster and requires a fraction of space.
The gory details
MessagePack is fast and space-efficient for a couple of reasons.
- Stream deserializer.
MessagePack’s protocol is designed so that one can start deserializing the buffered databefore all the data is received. The user simply appends new data to the buffer and start deserializing them right away. The real benefit of stream deserializer is pipelining; by overlapping deserialization and data reception, one can cut down the total time drastically.
- “zero-copy” serialize/deserializer.
MessagePack’s dramatic speedup comes from “zero-copy” serialization (currently implemented only in the C++ and D library). As the name suggests, “zero-copy” serialization copies no data. Well, almost.
Instead of the entire data, the library keeps track of just enough metadata to recover the object for read operations. “zero-copy” deserialization works similarly but the other way around. The absence of copy operations speeds up serialization/deserialization, especially for large data.
- Being smart about serialization schema.
Like many other efficient messaging protocols, MessagePack is a binary protocol. Furthermore, it is optimized to store common data types compactly. Here is a quick comparison with JSON.
- Community, Community, Community.
Since the inception of the MessagePack project, we have had the fortune of havingexperts implement the library for each programming language. Instead of asking them to write a simple wrapper around the core C implementation, we encouraged them to go as low-level and hardcore as possible to squeeze in as many implementation-specific optimizations.
For example, the Ruby library has “zero-copy” deserialization implemented. This blog post shows how the Python’s implementation of MessagePack runs circles around every other serialization library. The community is active and growing, and the performance of each library continues to improve.
And this is only the beginning
Treasure Data eliminates obstacles for analyzing Big Data. All of your time should go into data analysis, not management. We are here to build powerful tools to help you do that.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)