1 2 Previous Next 26 Replies Latest reply: May 15, 2008 3:16 PM by Patrick Martin RSS

jboss serialization performance

dave irving Newbie

Hi,

Im having real problems with the performance of standard java serialization.
I need to turn fairly large and complex objects in to an on-the-wire format using a (fairly) transparent mechanism (e.g: java serialization).

After observing rubbish performance from standard java serialization, I turned to jboss serialization.

However - for my usage, this is showing up as 30% slower than standard java serialization.

Am I maybe using it incorrectly?

If anyone could help me out I'd greatly appreciate it.

Regards,

Dave

  • 1. Re: jboss serialization performance
    Clebert Suconic Master

    All my testcases are showing 2x faster.


    Please, can you provide a testcase?


    I'm the jboss-serialization lead, and I would really appreciate any input and I would really like to see what you have.


    Thanks,


    Clebert

  • 2. Re: jboss serialization performance
    Clebert Suconic Master

    I was trying to reproduce the behavior you identified in a huge object, and JBossSerialization was always faster.


    Look at org.jboss.serial.benchmarks.SingleThreadBenchmarkTestCase

    It will execute a benchmark for every class under org.jboss.serial.data.Test* conditions.


    I tried to reproduce your behavior with TestHugeData, and I got these numbers:


    Starting org.jboss.serial.data.TestHugeData...........................:
    Total time for doTtestJbossSerializationMeasure(org.jboss.serial.data.TestHugeData) = 471 (this is smart cloning)
    Total time for doTestJbossSerializationUsingByteArrayMeasure(org.jboss.serial.data.TestHugeData) = 11036
    Total time for doTestJavaSerializationMeasure(org.jboss.serial.data.TestHugeData) = 31004




    Maybe you are doing the test for a one time only, and probably considering meta-data discovery for both Java and JBossSerialization.

    You have to start measuring it after you've get steady state. (after few messages).


    If you still think JBossSerialization is slower for your class, I would like to take a look on what behavior you are dealing with.


    Clebert

  • 3. Re: jboss serialization performance
    dave irving Newbie

    Hi,

    Thanks for getting back to me!
    Yeah - Im the same guy from the sun forums :o)

    Here's an example type I came up with to test with - which - for me - is serialized much faster with standard serialization than with jboss serialization:




    class DomainObject implements Serializable {
    
     private static final int CHILD_COUNT = 100;
    
     private DomainObject[] children;
     private long aLong = 45;
     private String aString = "test";
     private int anInt = 4;
    
     DomainObject() {
     this (true);
     }
    
     private DomainObject(boolean hasChildren) {
     if (hasChildren) {
     children = new DomainObject[CHILD_COUNT];
     for (int i=0; i<CHILD_COUNT; ++i) {
     children = new DomainObject(false);
     }
     }
     }
     }
    



    It doesn't seem to matter whether I re-use a stream, or create a stream for each request - java serialization is beating jboss serialization in my environment every time with the above class (by a long way).

    Im using java 1.5.0_04.

    Any help would be appreciated...

    Dave

  • 4. Re: jboss serialization performance
    dave irving Newbie

     

    "clebert.suconic@jboss.com" wrote:


    Maybe you are doing the test for a one time only, and probably considering meta-data discovery for both Java and JBossSerialization.

    You have to start measuring it after you've get steady state. (after few messages).


    If you still think JBossSerialization is slower for your class, I would like to take a look on what behavior you are dealing with.


    Clebert


    Sorry - I forgot address that point in my post...

    I "warm up" with over 1000 (de)serializations before I start timing.
    I then record the time taken to perforn n iterations of serializing and then de-serializing an object of the above type.


  • 5. Re: jboss serialization performance
    Clebert Suconic Master

    One important point:

    JavaSerialization has a internal buffer like "BufferOutputStream".

    I use just raw outputStream. So, if you are not using and BufferedOutputStream and BufferedInputStream, you will have your streaming slower with JBossSerialization not because JavaSerialization is faster, but just because I don't buffer my streaming internally.


    Can you test it with an ObjectOutputStream?


    Also...


    Can you provide an example, just to make sure you are using it properly?

    (I know it's easy and you won't probably miss it... but just to double check it)



    Clebert

  • 6. Re: jboss serialization performance
    Clebert Suconic Master

    BTW: I will do a test with your class today

  • 7. Re: jboss serialization performance
    dave irving Newbie

    Hi,

    I should probably provide you with some more context.
    The serialized objects are being sent over JMS (not JBoss, Im afraid ;o)
    The provider really doesn't do ObjectMessages very well (forces serialization to be synchronized - even though its a CPU only task - and I run on a 4 CPU machine....).
    So, what I have to do is serialize myself and then use the resultant bytes to create a byte array (so I can stuff it in a simple JMS MapMessage or whatever).
    Each message is "one-shot" and straight in to memory - there is no underlying IO - this is completely CPU bound stuff.

    So, what I do is:

    ByteArrayOutputStream baos = new ByteArrayOutputStream(someAppropriateInitialSize);
    ObjectOutputStream out = new ObjectOutputStream(baos) / JBossOutputStream(baos);
    out.write(myObject);
    out.close();
    byte[] wireFormat = baos.toByteArray();
    


    Doing it this way, with the example type I posted above, I see much faster results with standard Java serialization than JBoss serialization.

    Hope this is of help,

    Cheers,

    Dave

  • 8. Re: jboss serialization performance
    Clebert Suconic Master

    There is some "problem" in the way I'm doing reflection for arrays.


    I'll find the bottleneck, fix and get back to you through this forum.



    Thanks, this is being very helpful.


    Clebert

  • 10. Re: jboss serialization performance
    dave irving Newbie

     

    "clebert.suconic@jboss.com" wrote:
    There is some "problem" in the way I'm doing reflection for arrays.


    I'll find the bottleneck, fix and get back to you through this forum.



    Thanks, this is being very helpful.


    Clebert


    Thank you for taking the time to look in to this!

    Its quite interesting - about a month ago I spent a day or so trying to write my own custom serialization mechanism myself. I was kicking Java serialization all over the place until I hit arrays :o)

    I was using Array#set and Array#get and it was killing me...
    Not sure whether there's a faster way to get at this in sun.misc.Unsafe.

    Thanks again for looking in to this - if there's anything I can help with this end then please ask.

    Regards,

    Dave

  • 11. Re: jboss serialization performance
    Clebert Suconic Master

    If you would like to be a contributor on JBossSerialization, I would be glad to give you an overal on the design. It's not that complicated and since you know reflection.... ;-)


    If you are interested, let me know.

    Clebert

  • 12. Re: jboss serialization performance
    dave irving Newbie

     

    "clebert.suconic@jboss.com" wrote:
    If you would like to be a contributor on JBossSerialization, I would be glad to give you an overal on the design. It's not that complicated and since you know reflection.... ;-)


    If you are interested, let me know.

    Clebert


    Hi Celbert,

    Yes - Im certainly interested.
    Im going home for the evening now (based in the UK), but I'll probably pop in to the office tomorrow - so I'll catch up on anything which comes through then.

    You can email me directly at irvingd ~a~t~ logicacmg ~d~o~t com.

    I look forward to hearing from you and contributing :o)

    Many thanks,

    Dave

  • 13. Re: jboss serialization performance
    dave irving Newbie

    Ooops,

    make that irvingd at logica.com

  • 14. Re: jboss serialization performance
    Clebert Suconic Master

    I'm doing some tests and using Object[] loops instead of Array.getInstance navigation is being much faster.

    Unfortunately later I will have to write on array persister for each primitive value. But that's okay. Then I realized regular ObjectOutputStream and ObjectInputStream does the same way.



    Clebert

1 2 Previous Next