8 Replies Latest reply on Jul 6, 2006 6:25 PM by Clebert Suconic

    JBoss Serialization is very slow?

    Dan Liu Apprentice

      I'm using JBossObjectOutputStream and use writeObject(...) to a FielOutputStream. The result show sun provided serialization is about 4 times faster than jboss's.

      Here is my code(very simple code):

      FileOutputStream fileOutputStream=new FileOutputStream(file);
      final ObjectOutputStream out = new JBossObjectOutputStream(fileOutputStream);
      final MyObject event = new MyObject(new Long(9999),new Date(),new Date(),"string1","string2",123,234,true,345);
      
      long firstTimeStamp=System.currentTimeMillis();
      
       for(int i=0;i<20000;i++){
      
       out.reset();
       out.writeObject(event);
       out.flush();
       }
      
      
      long timeSpent=System.currentTimeMillis()-firstTimeStamp;
      System.out.println(timeSpent);
      


      Any ideas? Is there anything i'm doing wrong?

        • 1. Re: JBoss Serialization is very slow?
          Clebert Suconic Master

          You are measuring ClassLoading time of JBossSerialization also.

          You should do something like:

          FileOutputStream fileOutputStream=new FileOutputStream(file);
          final ObjectOutputStream out = new JBossObjectOutputStream(fileOutputStream);
          final MyObject event = new MyObject(new Long(9999),new Date(),new Date(),"string1","string2",123,234,true,345);
          
          long firstTimeStamp=0;
          
           for(int i=0;i<20000;i++){
           if (i==1000)
           {
           firstTimeStamp=System.currentTimeMillis();
           }
           out.reset();
           out.writeObject(event);
           out.flush();
           }
          
          
          long timeSpent=System.currentTimeMillis()-firstTimeStamp;
          System.out.println(timeSpent);
          



          What really matters in a sytem is a steady state. If you need to measure Loading Time there is no way to compete with Sun JDK's, as I can't modify the JVM to pre-load JBossSerialization.

          • 2. Re: JBoss Serialization is very slow?
            Dan Liu Apprentice

            I've modified my code as you suggested that start counting from 1000th call. Here is the average result I get (The Sun Jdk is about 4 times faster):

            JBoss Serialization...
            5625 ms

            Sun Serialization...
            1415 ms

            I'm using jdk1.4.2_08 + jboss-serialization-1.0.0.GA

            Any ideas?

            • 3. Re: JBoss Serialization is very slow?
              Dan Liu Apprentice

              tried jboss-serialization-1.0.1.GA and still no luck.

              • 4. Re: JBoss Serialization is very slow?
                Clebert Suconic Master

                You need to use a BufferedOutputStream
                Even javaSerialization works better with the Buffer.

                This is because JavaSErialization has an internal buffer. JBossSErialization not.

                jboss=330
                java=351



                public class MyTest extends TestCase
                {
                
                 static class MyObject implements Serializable
                 {
                
                 Long along;
                 Date adate;
                 Date anotherdate;
                 String astring;
                 String anotherstring;
                 int a;
                 int b;
                 boolean somea;
                 int c;
                 public int getA() {
                 return a;
                 }
                 public void setA(int a) {
                 this.a = a;
                 }
                 public Date getAdate() {
                 return adate;
                 }
                 public void setAdate(Date adate) {
                 this.adate = adate;
                 }
                 public Long getAlong() {
                 return along;
                 }
                 public void setAlong(Long along) {
                 this.along = along;
                 }
                 public Date getAnotherdate() {
                 return anotherdate;
                 }
                 public void setAnotherdate(Date anotherdate) {
                 this.anotherdate = anotherdate;
                 }
                 public String getAnotherstring() {
                 return anotherstring;
                 }
                 public void setAnotherstring(String anotherstring) {
                 this.anotherstring = anotherstring;
                 }
                 public String getAstring() {
                 return astring;
                 }
                 public void setAstring(String astring) {
                 this.astring = astring;
                 }
                 public int getB() {
                 return b;
                 }
                 public void setB(int b) {
                 this.b = b;
                 }
                 public int getC() {
                 return c;
                 }
                 public void setC(int c) {
                 this.c = c;
                 }
                 public boolean isSomea() {
                 return somea;
                 }
                 public void setSomea(boolean somea) {
                 this.somea = somea;
                 }
                 public MyObject(Long along, Date adate, Date anotherdate, String astring, String anotherstring, int a, int b, boolean somea, int c) {
                 super();
                 this.along = along;
                 this.adate = adate;
                 this.anotherdate = anotherdate;
                 this.astring = astring;
                 this.anotherstring = anotherstring;
                 this.a = a;
                 this.b = b;
                 this.somea = somea;
                 this.c = c;
                 }
                 }
                
                 public static boolean useBuffer=true;
                
                 public void testJBoss() throws Exception
                 {
                 File file=new File("/tmp/jboss.ser");
                 FileOutputStream fileOutputStream=new FileOutputStream(file);
                 BufferedOutputStream buffOut = new BufferedOutputStream(fileOutputStream);
                 ObjectOutputStream out = null;
                 if (useBuffer)
                 {
                 out = new JBossObjectOutputStream(buffOut);
                 }
                 else
                 {
                 out = new JBossObjectOutputStream(fileOutputStream);
                 }
                 final MyObject event = new MyObject(new Long(9999),new Date(),new Date(),"string1","string2",123,234,true,345);
                
                 long firstTimeStamp=0;
                
                 for(int i=0;i<20000;i++){
                 if (i==1000)
                 {
                 firstTimeStamp = System.currentTimeMillis();
                 }
                 out.reset();
                 out.writeObject(event);
                 out.flush();
                 }
                
                
                 long timeSpent=System.currentTimeMillis()-firstTimeStamp;
                 System.out.println("jboss="+timeSpent);
                
                
                
                 }
                 public void testJava() throws Exception
                 {
                 File file=new File("/tmp/java.ser");
                 FileOutputStream fileOutputStream=new FileOutputStream(file);
                 BufferedOutputStream buffOut = new BufferedOutputStream(fileOutputStream);
                 ObjectOutputStream out = null;
                 if (useBuffer)
                 {
                 out = new ObjectOutputStream(buffOut);
                 }
                 else
                 {
                 out = new ObjectOutputStream(fileOutputStream);
                 }
                 final MyObject event = new MyObject(new Long(9999),new Date(),new Date(),"string1","string2",123,234,true,345);
                
                 long firstTimeStamp=0;
                
                 for(int i=0;i<20000;i++){
                 if (i==1000)
                 {
                 firstTimeStamp = System.currentTimeMillis();
                 }
                 out.reset();
                 out.writeObject(event);
                 out.flush();
                 }
                
                
                 long timeSpent=System.currentTimeMillis()-firstTimeStamp;
                 System.out.println("java=" + timeSpent);
                
                
                
                 }
                }
                


                • 5. Re: JBoss Serialization is very slow?
                  Dan Liu Apprentice

                  Changing to use BufferedOutputStream and it now flys. JBoss Serialization runs 70% faster than sun jdk's. Great stuff ! Thanks Clebert.

                  Are there any other JBoss Serialization performance turning tips? I can hardly find any document talking about this at moment.

                  • 6. Re: JBoss Serialization is very slow?
                    Clebert Suconic Master

                    Thanks a lot for your post.

                    I'm preparing a docbook for JBossSerialization. Should be ready soon. (in two or three weeks probably). After JBossWorld. (I'm kind of too busy now becuase of that).


                    Meanwhile I have my blog post aboug jboss serialization:

                    http://jboss.org/jbossBlog/blog/clebert/

                    • 7. Re: JBoss Serialization is very slow?
                      slump slump Newbie

                      Hi, clebert:

                      I just copy your code and run the test
                      but the result is:
                      jboss=644
                      java=557

                      I have run it more than 10 times , the reuslt is similar

                      I use RHEL4 and jdk 1.5.0_06

                      is there something I missed?

                      and I found that if there isn't log4j.properties, the jboss code become very slow (2333ms), so I think you should put the note in the README