4 Replies Latest reply on Apr 25, 2010 2:52 PM by Pimenov Oleg

    Hessian or AMF

    Pimenov Oleg Level 1

      Hi !


      "Simple" question , what use for serialization Java Class - Hessian or AMF (jar from BlazeDS) ?


      Some test:



      but I`m not sure what this test is correct.

        • 1. Re: Hessian or AMF
          Ansury Level 3

          It's not really a simple question.  :)


          I'd still wager AMF w/Flex but I do want to look at this some more.  I suspect that the benchmark has some flaws.


          On the 'previous' post I notice James Ward (he wrote this AMF benchmark) was the first response with this:


          Interesting stats. How does client side parse time differ between AMF and Hessian?


          This was the first thing I wondered as well.  Then the response came back:


          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.


          I might challenge the "I think that the most important things..." statement.


          • Most important according to who, and what requirements?  "Most" seems to be a personal opinion.
          • Assumption that server time and bandwidth are most significant, this isn't always the case. (Actually I'm curious as to how real these savings are?)
          • The benchmark sounds like it only tests a portion of a real life example.  If the data hasn't been parsed yet, it's of no use.  Before the application can make any use of the data and have it benefit the user, it must be parsed.  Did this benchmark leave that aspect of the testing out completely? 
          • If it's only a partial test, it's like testing the bottom three layers of the OSI model and declaring victory over a different implementation of the entire stack.  Who cares - the data hasn't reached it's final destination yet!


          All that said, it may turn out that parsing isn't very significant.  I think it's too early to tell.


          But thanks for posting this, I may take some time looking at the topic a little.  It just may turn out that the difference in practice is insignificant enough that either one is as good as the other, but at the speeds we're talking about, the choice may not matter much.  At some point you reach a performance plateau and they both may be there.



          On the final recommendation, since they're pretty close (and this test seems pretty limited) I'd still stick with AMF since it's the most commonly used protocol for a Flex app.  If nothing else, at least you're doing things the same way the rest of us are, which is a good thing.

          1 person found this helpful
          • 2. Re: Hessian or AMF
            Pimenov Oleg Level 1

            Thanks !! It's very helpful answer !


            P.S. I`m using this protocol only for serialization (on socket connection).

            • 3. Re: Hessian or AMF
              Ansury Level 3

              Yeah he's definitely doing a less complete test than James Ward is doing.  Not pointless, but I wouldn't count on this translating fully to real life experience, take it with a grain of salt (and I think even the writer may agree with that).  I'd like to see the results of a more end-to-end benchmark.  I think he's also using a more limited set of test data, expanding the test data coverage was mentioned, and the type of data was also mentioned as a factor.  Interesting stuff...


              This is all the AMF test does for example.  It's basically testing Blaze's java side implementation.


                  public static byte[] testAMF(List data,boolean print) throws Exception{
                      SerializationContext serializationContext = new SerializationContext();
                      serializationContext.instantiateTypes = true;
                      ByteArrayOutputStream baos = new ByteArrayOutputStream(64*1024);
                      Amf3Output amf3Output = new Amf3Output(serializationContext);
                      long t1 = System.nanoTime();
                      long t2 = System.nanoTime();
                      if (print){
                          System.out.println("Compressed size:"+baos.toByteArray().length);            
                          System.out.println(convert(t2 - t1));
                      return baos.toByteArray();

              • 4. Re: Hessian or AMF
                Pimenov Oleg Level 1

                I do some test and....



                Compressed size:53

                TIME Hessian: 55315


                Compressed size:50

                TIME AMF : 14522



                My time counts -



                long t1 = System.nanoTime();
                long t2 = System.nanoTime();


                ByteArrayOutputStream bos = new ByteArrayOutputStream();         Hessian2Output out = new Hessian2Output(bos);         try {                                     out.startMessage();             long t1 = System.nanoTime();             out.writeObject(objout);             long t2 = System.nanoTime();             out.completeMessage();                                               System.out.println("Compressed size:"+bos.toByteArray().length);                     System.out.println("TIME Hessian: " + (t2 - t1)/1000);                     System.out.println("--------------");                    } catch (IOException e)         {             e.printStackTrace();         }             


                Class serialization :


                public class UserVO implements Serializable


                        public String firstName;

                        public String lastName;



                        public UserVO()


                            this.firstName = "Bean";

                            this.lastName = "Jackson";




                        public UserVO getInstance()


                            return this;