[转]序列化框架比较

转自https://github.com/eishay/jvm-serializers/wiki

 

Benchmarks (2011-11-28)

WARNING: Benchmarks can be misleading.

  • These tests use a specific data value (TestValue). A different data value will yield different results.
  • The tools don’t all do the exact same thing (ToolBehavior). Some of them take shortcuts to improve performance; some of them require the programmer to do more work, etc.
  • Different hardware and software environments will yield different results.
  • We don’t take memory usage into account.

In short, before you make a decision on which tool to use, make sure you try it out in an environment you care about. To start, download the benchmark code and run it on your hardware with data values you care about.

Setup

Hardware: AMD Athlon II X4 640 3.00GHz
Software: Java Version 1.6.0_22, OpenJDK Runtime Environment (IcedTea6 1.10.4), Ubuntu 11.04 running on VirtualBox VM
JVM options: -Xmx16m -server

Data value being tested: TestValue.

Version of the benchmarking code: Git tree

Methodology:

  • Before taking measurements, we warm things up by running the test several times.
  • For a test, measure the time taken to perform 2000 operations (serialization, deserialization, etc.). Then divide the result by 2000.
  • Run each test 500 times and report the best result.
  • Look at the code for more details. BenchmarkRunner.java

Tool Versions ( lib/):

Charts

Note: Since the total combined sized of the chart labels and data points results in URIs that are too long for the Google Chart Tools API, the serialization APIs under test were split into two groups, resulting in two charts for each section below.

Total Time (“total”)

Create an object, serialize it to a byte array, then deserialize it back to an object.

Serialization Time (“ser”)

Create an object, serialize it to a byte array.

  • Java’s built-in serializer faithfully represents arbitrary object graphs, which hurts performance. All the other serializers flatten the structure out to a tree.

Deserialization Time (“deser+deep”)

Often the most expensive operation. To make a fair comparison, all fields of the deserialized instances are accessed – this forces lazy deserializers to really do their work. The raw data below shows additional measurements for deserialization.

Serialized Size (“size”)

The size of the serialized data. These numbers may vary depending on the exact data value being used.

  • Java’s built-in serializer stores the full class name in serialized form. So you don’t need to know ahead of time what kind of object you’re reading in.
  • The ‘scala’ test, which uses Java’s built-in serialization, yields a larger serialized representation because it usually creates more Java classes under the hood.

Serialization Compressed Size (“size+dfl”)

The size of the serialized data compressed with Java’s built-in implementation of DEFLATE (zlib).

Object Creation Time (“create”)

Object creation is not so meaningful since it takes in average 100 nano to create an object. However, the different tools vary in how “fancy” their objects are. Some just create a plain Java class and let you access fields directly, while others have set/get methods, while others use the “builder” pattern.

  • Protobuf and Thrift use the “builder” pattern to create objects, which makes the operation more expensive.
  • Avro stores Strings in UTF8 form. The time taken to convert from Java “String” values to UTF-8 is included under “create”, “ser”, “deser+shal”, and “deser+deep”, which isn’t quite representative of real-world usage. Real code that uses Avro might be able to keep strings in UTF-8 form, thus avoiding the need to convert back and forth (in which case the “ser+same” and “deser” results might be more accurate reflections of Avro’s performance).

Numbers

Times are in nanoseconds, sizes are in bytes.

                                create     ser   +same   deser   +shal   +deep   total   size  +dfl
kryo                                164    2241    2115    2688    2640    2811    5052    233   147
kryo-opt                            165    2021    1808    2289    2447    2646    4667    219   135
kryo-manual                         164    1635    1329    1924    1723    1937    3572    219   132
wobly                               106    2269    2281    1269    1377    1444    3713    251   151
wobly-compact                       112    2330    2219    1398    1409    1429    3760    225   139
protobuf                            298    3884    1939    1906    2112    2248    6132    239   149
protobuf/activemq+alt               280    3959       0       0    1175    2388    6346    239   149
protostuff                          242    1119     923    1691    1826    2073    3192    239   150
protostuff-manual                   168    1074     878    1737    1808    1889    2963    239   150
protostuff-runtime                  169    1250    1139    1878    1976    1976    3226    241   151
protobuf/protostuff                 240    1198     920    1865    1948    2001    3199    239   149
thrift                              295    4089    3815    2287    2392    2511    6600    349   197
thrift-compact                      295    3646    3422    2343    2301    2515    6160    240   148
avro                                196    3614    3426    2003    3132    4047    7661    221   133
avro-generic                        824    4348    3476    1935    2850    4250    8598    221   133
msgpack                             169    2366    2183    2272    2491    2568    4934    233   146
java-built-in                       172   14462   13420   57397   57639   57709   72171    889   514
java-manual                         172    1543    1577    1369    1427    1560    3103    255   147
scala/java-built-in                 421   21730   19689   83366   83408   83756  105486   1312   700
scala/sbinary                       420    4139    3606    2788    3040    3541    7680    255   147
hessian                             170   10483    9640   12505   12552   12574   23057    501   313
json/jackson/manual                 170    2491    2416    2986    2994    3172    5663    468   253
json/jackson/databind               172    3847    3625    5810    5900    6016    9863    485   261
json/jackson/databind-strings       173    5670    5516    6889    6766    7202   12871    485   261
json/jackson/db-afterburner         172    3135    2979    3950    4063    4162    7297    485   261
json/jackson/tree                   172    5398    5210    6243    6316    6382   11780    485   259
json/jackson/tree-strings           171    6809    6624    8250    8344    8479   15288    485   259
json/protostuff-manual              172    3286    3085    4101    4175    4249    7535    449   233
json/protostuff-runtime             172    3764    3522    4828    4930    5007    8771    469   243
json/google-gson/manual             173   12904   12825   12663   12938   12875   25779    468   253
json/google-gson/manual/tree        173   17420   17158   21642   22002   22110   39530    485   259
json/google-gson/databind           171   99935   99387  105321  105604  106145  206081    486   259
json/svenson-databind               172   10579   10378   31591   31950   32159   42738    495   268
json/flexjson/databind              173   44363   44048  137022  137692  137855  182218    503   273
json/json-lib-databind              172   73748   74263  208391  208863  209026  282774    485   263
json/fastjson/databind              172    4868    4623    1825    1937    2051    6919    468   255
json/json.simple/manual             171   15971   15753   19604   19583   19768   35739    495   269
json/json.simple/manual/tree        172   16063   15832   21627   21957   21992   38054    495   269
json/json-smart/manual/tree         173   13036   12856    9288    9328    9485   22522    495   269
json/org.json/manual/tree           172   16281   16047   19768   20029   20141   36421    485   259
json/jsonij-jpath                   172   71419   70695   31073   31310   31473  102892    478   254
json/jsonij-manual/tree             173   71735   70961   16644   16750   16809   88545    478   254
json/argo-manual/tree               171  177185  176366   36569   36886   36634  213819    485   263
json/jsonpath/json.simple           172   16042   15763  484450  485555  486958  503000    495   269
smile/jackson/manual                176    2085    1878    2167    2195    2320    4405    341   244
smile/jackson/databind              176    3110    2848    3866    4127    4145    7255    338   241
smile/jackson/db-afterburner        176    2458    2340    2761    2843    2900    5358    352   252
smile/protostuff-manual             176    2628    2384    2822    2970    3040    5668    321   229
smile/protostuff-runtime            177    2919    2657    3491    3544    3645    6564    335   235
bson/jackson/manual                 176   12523   12396   11103   11421   11475   23998    495   278
bson/jackson/databind               177   14898   14415   13886   14034   14127   29025    506   286
bson/mongodb                        175    9734    9584   39213   39405   39329   49063    495   278
xml/woodstox-manual                 176    8613    8443   11995   12213   12175   20788    653   304
xml/aalto-manual                    178    5281    5044    7049    7157    7133   12414    653   304
xml/fastinfo-manual                 176   15011   14786   14179   14361   14355   29366    377   284
xml/xstream+c                       177   16010   15085   52366   53277   53051   69061    487   244
xml/xstream+c-woodstox              177   12264   11561   26795   26838   27312   39576    525   273
xml/xstream+c-aalto                 178    8900    8164   17961   18178   18315   27215    525   273
xml/xstream+c-fastinfo              178   16347   15090   19698   19842   20094   36441    345   264
xml/jackson/databind-aalto          178    7290    7089   10983   11198   11355   18645    683   286
xml/javolution                      174   11376   10805   17558   17999   18147   29523    504   263

Columns:

  • create: create an object (using the classes specified by the serialization tool)
  • ser: create an object and serialize it
  • +same: serialize the same object (i.e. doesn’t include creation time)
  • deser: deserialize an object
  • +shal: deserialize an object and access the top-level fields
  • +deep: deserialize an object and access all the fields
  • total: create + serialize + deserialize and access all fields
  • size: the size of the serialized data
  • +dfl: the size of the serialized data compressed with Java’s built-in implementation of DEFLATE (zlib)

Tests run with the following commands.

./run -trials=500 -chart -include=kryo,kryo-opt,kryo-manual,wobly,wobly-compact,protobuf,protobuf/activemq+alt,protostuff,protostuff-manual,protostuff-runtime,protobuf/protostuff,thrift,thrift-compact,avro,avro-generic,msgpack data/media.1.cks

./run -trials=500 -chart -include=java-built-in,java-manual,scala/java-built-in,scala/sbinary,hessian,json/jackson/manual,json/jackson/databind,json/jackson/databind-strings,json/jackson/db-afterburner,json/jackson/tree,json/jackson/tree-strings,json/protostuff-manual,json/protostuff-runtime,json/google-gson/manual,json/google-gson/manual/tree,json/google-gson/databind,json/svenson-databind,json/flexjson/databind,json/json-lib-databind,json/fastjson/databind,json/json.simple/manual,json/json.simple/manual/tree,json/json-smart/manual/tree,json/org.json/manual/tree,json/jsonij-jpath,json/jsonij-manual/tree,json/argo-manual/tree,json/jsonpath/json.simple,smile/jackson/manual,smile/jackson/databind,smile/jackson/db-afterburner,smile/protostuff-manual,smile/protostuff-runtime,bson/jackson/manual,bson/jackson/databind,bson/mongodb,xml/woodstox-manual,xml/aalto-manual,xml/fastinfo-manual,xml/xstream+c,xml/xstream+c-woodstox,xml/xstream+c-aalto,xml/xstream+c-fastinfo,xml/jackson/databind-aalto,xml/javolution data/media.1.cks

posted on 2012-02-05 10:21  Vincent_Q  阅读(298)  评论(0编辑  收藏  举报

导航