Remoting, XML, AMF, Hessian and Deflate algorithm
Posted by cornel | Filed under Flex, Java
I’m a big fan of using remote calling whenever possible to bring the data from a Java server into a Flex application, not only for performance reasons but also because the code is much cleaner. Yesterday, I implemented a quick benchmark to test both approaches (remote versus a service returning xml) – results are bellow. You can also download the project here (it’s created in Intellij, and you will also need Java persistence libraries). It’s a quick benchmark and not a benchmark framework so the code is no production quality. I’ve tried to eliminate the time spent by the garbage collector and the times for the benchmark are taken into consideration only after the Hotspot optimizations of the code.
Some details about my benchmark: I have three objects (Company objects havea bidirectional 1-n relation with an Employee objects and the Employee has a n-1 relation with a Town object). I read the data from a MySql database using Hibernate(I have about 3 Companies, 1000 Employees, and 5 Towns).
For the XML case I’m doing a conversion from the Java objects to XML, and optionally I have also included a ZIP compression. For the remote case I tested both AMF3 compression and Hessian. I tested only the algorithms (not the time spent the data from the application server) because I think that’s the most important thing.
The results are interesting, the most time is spent in XML conversion (using DOM4J). I will try to use also another XML library, maybe that time can be reduced a little . The results prove again that the binary formats (AMF3 and Hessian) are a very good option when sending data to the Flex client…note that even the compressed XML is not much smaller than the binary format.
Results table below. My system is a Lenovo laptop, CORE 2 Duo, 2.4Ghz
| Avg Time (microseconds) | Data size (kbytes) | |
| AMF3 | 9945 | 28 |
| Hessian | 4675 | 29 |
| XML | 22064 | 158 |
| XML+Deflate | 27336 | 18 |
Note: the difference between AMF and Hessian depends a lot on the input data. For example if you have more repetitive data then AMF tends to be more efficient than Hessian on data size. I will try in the future to create a mini benchmark framework with different sets of data.
April 3rd, 2009 at 12:44 am
Interesting stats. How does client side parse time differ between AMF and Hessian?
-James
April 6th, 2009 at 1:45 pm
The client parsing time is faster for AMF (as is expected, it’s a native feature from Flash Player compared with the hessian case where you have an external library) but I do not have the exact times. I also think that the most important things are the server time and bandwith savings, at least for most applications.
April 8th, 2009 at 4:02 pm
[...] I wrote in a previous post Hessian serialization from the server side is faster than the AMF one, and the compressed data [...]
July 20th, 2009 at 11:30 am
[...] never thought about it and I did nor performed any tests. Now I extended my mini-benchmark from my previous post and I also serialized the objects using Java serialization. The results are below, and you can see [...]
September 6th, 2010 at 7:19 am
[...] You could also choose the „hessian-3.1.3.jar“ instead the „amf-serializer-2.2.jar“ if you would want to use the Hessian-Protocol instead of AMF. I prefer AMF. Checkout this post: http://cornelcreanga.com/2009/02/remoting-xml-amf-hessian-and-deflate-algorithm/ [...]