协议缓冲相对于 JSON 或 BSON

有没有人知道协议缓冲和 BSON (二进制 JSON)或者一般的 jSON 的性能特征?

  • 电线尺寸
  • 序列化速度
  • 反序列化速度

这些似乎是通过 HTTP 使用的好的二进制协议。我只是想知道从长远来看,对于 C # 环境来说,哪一个更好。

这是我在 BSON协议缓冲上读到的一些信息。

59472 次浏览

protocol buffers is designed for the wire:

  1. very small message size - one aspect is very efficient variable sized integer representation.
  2. Very fast decoding - it is a binary protocol.
  3. protobuf generates super efficient C++ for encoding and decoding the messages -- hint: if you encode all var-integers or static sized items into it it will encode and decode at deterministic speed.
  4. It offers a VERY rich data model -- efficiently encoding very complex data structures.

JSON is just text and it needs to be parsed. hint: encoding a "billion" int into it would take quite a lot of characters: Billion = 12 char's (long scale), in binary it fits in a uint32_t Now what about trying to encode a double ? that would be FAR FAR worse.

Thrift is another Protocol Buffers-like alternative as well.

There are good benchmarks from the Java community on serialization/deserialization and wire size of these technologies: https://github.com/eishay/jvm-serializers/wiki

In general, JSON has slightly larger wire size and slightly worse DeSer, but wins in ubiquity and the ability to interpret it easily without the source IDL. The last point is something that Apache Avro is trying to solve, and it beats both in terms of performance.

Microsoft has released a C# NuGet package Microsoft.Hadoop.Avro.

This post compares serialization speeds and sizes in .NET, including JSON, BSON and XML.

alt text

alt text

http://james.newtonking.com/archive/2010/01/01/net-serialization-performance-comparison.aspx

Here are some recent benchmarks showing the performance of popular .NET Serializers.

The Burning Monks benchmarks show the performance of serializing a simple POCO whilst the comprehensive Northwind benchmarks show the combined results of serializing a row in every table of Microsoft's Northwind dataset.

enter image description here

Basically protocol buffers (protobuf-net) is around 7x quicker than the fastest Base class library Serializer in .NET (XML DataContractSerializer). Its also smaller than the competition as it is also 2.2x smaller than Microsofts most compact serialization format (JsonDataContractSerializer).

ServiceStack's Text serializers are the closest to matching the performance of the binary protobuf-net where its Json Serializer is only 2.58x slower than protobuf-net.