[jboss-cvs] JBossCache/tests/perf/org/jboss/cache/marshall ...

Manik Surtani manik at jboss.org
Tue Mar 27 11:42:11 EDT 2007


  User: msurtani
  Date: 07/03/27 11:42:11

  Modified:    tests/perf/org/jboss/cache/marshall 
                        VersionAwareMarshallerPerfTest.java
  Log:
  JBCACHE-937
  
  Revision  Changes    Path
  1.3       +146 -60   JBossCache/tests/perf/org/jboss/cache/marshall/VersionAwareMarshallerPerfTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: VersionAwareMarshallerPerfTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/marshall/VersionAwareMarshallerPerfTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- VersionAwareMarshallerPerfTest.java	15 Jan 2007 18:10:56 -0000	1.2
  +++ VersionAwareMarshallerPerfTest.java	27 Mar 2007 15:42:11 -0000	1.3
  @@ -7,6 +7,7 @@
   package org.jboss.cache.marshall;
   
   import junit.framework.TestCase;
  +import org.jboss.cache.Fqn;
   import org.jboss.cache.RegionManager;
   import org.jboss.cache.misc.TestingUtil;
   
  @@ -15,6 +16,8 @@
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
   import java.util.HashMap;
  +import java.util.LinkedList;
  +import java.util.List;
   import java.util.Map;
   import java.util.Random;
   
  @@ -28,13 +31,22 @@
      private Random random = new Random();
   
      // Tune as necessary
  -   private static final int NUM_TIMES_PER_THREAD = 1;
  -   private static final int NUM_THREADS = 1;
  +   // ignore the first IGNORE_LOOPS loops when collecting timing data.  This is because hotspot VMs need to "warm up" before coming up to speed.
  +   private static final int IGNORE_LOOPS = 1000;
  +   private static final int NUM_TIMES_PER_THREAD = 10000;
  +   private static final int NUM_THREADS = 10;
      private static final String threadNamePrefix = "TesterThread-";
   
      private long[] write = new long[NUM_THREADS * NUM_TIMES_PER_THREAD];
      private long[] read = new long[NUM_THREADS * NUM_TIMES_PER_THREAD];
  -   private long[] size = new long[NUM_THREADS * NUM_TIMES_PER_THREAD];
  +   private int size;
  +
  +   private Map<Type, Result> results = new HashMap<Type, Result>();
  +
  +   private enum Type
  +   {
  +      VAM_JBOSS_SERIALIZATION, VAM_JDK_SERIALIZATION, JDK_SERIALIZATION
  +   }
   
      protected void setUp() throws Exception
      {
  @@ -47,28 +59,62 @@
         TestingUtil.sleepThread(1000);
      }
   
  -   public void testStandardSerialization()
  +   public void testAllCombinations() throws Exception
      {
  -      run('S', "Standard Java Serialization");
  +      doStandardSerialization();
  +      tearDown();
  +      doVamJavaSerialization();
  +      tearDown();
  +      doVamJBossSerialization();
  +
  +      // now for some assertions
  +      Result jdkSer = results.get(Type.JDK_SERIALIZATION);
  +      Result vamJdkSer = results.get(Type.VAM_JDK_SERIALIZATION);
  +      Result vamJBossSer = results.get(Type.VAM_JBOSS_SERIALIZATION);
  +
  +      assertTrue("JDK serialization should, on average, produce larger output than VAM streams", jdkSer.size > vamJBossSer.size);
  +      assertTrue("JDK serialization should, on average, produce larger output than VAM streams", jdkSer.size > vamJdkSer.size);
  +
  +      assertTrue("JDK serialization should, on average, be slower for writing", jdkSer.writeAverageTime > vamJBossSer.writeAverageTime);
  +      assertTrue("JDK serialization should, on average, be slower for writing", jdkSer.writeAverageTime > vamJdkSer.writeAverageTime);
  +
  +      assertTrue("JDK serialization should, on average, be slower for reading", jdkSer.readAverageTime > vamJBossSer.readAverageTime);
  +      assertTrue("JDK serialization should, on average, be slower for reading", jdkSer.readAverageTime > vamJdkSer.readAverageTime);
  +
  +      // don't bother pitting JBoss Serialization against Java Serialization for now since this is pretty poor - we may be dropping JBoss Serialization.
      }
   
  -   public void testVamJavaSerialization()
  +   /**
  +    * Run this manually if you need to just run this test specifically.
  +    */
  +   private void doStandardSerialization()
  +   {
  +      run(Type.JDK_SERIALIZATION);
  +   }
  +
  +   /**
  +    * Run this manually if you need to just run this test specifically.
  +    */
  +   private void doVamJavaSerialization()
      {
         System.setProperty("serialization.jboss", "false");
         ObjectSerializationFactory.factory = new JavaObjectStreamFactory();
         ObjectSerializationFactory.useJBossSerialization = false;
  -      run('V', "Version Aware AbstractMarshaller - with Java Serialization");
  +      run(Type.VAM_JDK_SERIALIZATION);
      }
   
  -   public void testVamJBossSerialization() throws Exception
  +   /**
  +    * Run this manually if you need to just run this test specifically.
  +    */
  +   private void doVamJBossSerialization() throws Exception
      {
         System.setProperty("serialization.jboss", "true");
         ObjectSerializationFactory.factory = (ObjectStreamFactory) Class.forName("org.jboss.cache.marshall.JBossObjectStreamFactory").newInstance();
         ObjectSerializationFactory.useJBossSerialization = true;
  -      run('V', "Version Aware AbstractMarshaller - with JBoss Serialization");
  +      run(Type.VAM_JBOSS_SERIALIZATION);
      }
   
  -   public void run(final char type, String name)
  +   public void run(final Type t)
      {
         Thread threads[] = new Thread[NUM_THREADS];
   
  @@ -82,44 +128,45 @@
   
                  try
                  {
  -                  Map node = new HashMap();
  +                  Object remoteMethodCall = createRemoteMethodCall();
                     for (int j = 0; j < NUM_TIMES_PER_THREAD; j++)
                     {
                        long start;
                        long timeTaken;
                        byte[] buffer;
   
  -                     node.put("key" + j, "value" + j);
  -
  -                     switch (type)
  +                     switch (t)
                        {
  -                        case'S':
  +                        case JDK_SERIALIZATION:
                              start = System.currentTimeMillis();
  -                           buffer = writeStandardSerialization(node);
  +                           buffer = writeStandardSerialization(remoteMethodCall);
                              timeTaken = System.currentTimeMillis() - start;
   
  -                           write[j + id] = timeTaken;
  +                           if (j < IGNORE_LOOPS) write[j + id] = timeTaken;
   
                              start = System.currentTimeMillis();
                              readStandardSerialization(buffer);
                              timeTaken = System.currentTimeMillis() - start;
   
  -                           read[j + id] = timeTaken;
  +                           if (j < IGNORE_LOOPS) read[j + id] = timeTaken;
  +                           if (id == 0 && j == 0) size = buffer.length;
                              break;
  -                        case'V':
  +                        case VAM_JBOSS_SERIALIZATION:
  +                        case VAM_JDK_SERIALIZATION:
                              VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.0.0.GA");
   
                              start = System.currentTimeMillis();
  -                           buffer = writeVam(marshaller, node);
  +                           buffer = writeVam(marshaller, remoteMethodCall);
                              timeTaken = System.currentTimeMillis() - start;
   
  -                           write[j + id] = timeTaken;
  +                           if (j < IGNORE_LOOPS) write[j + id] = timeTaken;
   
                              start = System.currentTimeMillis();
                              readVam(marshaller, buffer);
                              timeTaken = System.currentTimeMillis() - start;
   
  -                           read[j + id] = timeTaken;
  +                           if (j < IGNORE_LOOPS) read[j + id] = timeTaken;
  +                           if (id == 0 && j == 0) size = buffer.length;
                              break;
                        }
                     }
  @@ -138,7 +185,25 @@
         // wait for all the threads to join
         waitForThreads(threads);
   
  -      printResults(name, write, read);
  +      Result r = new Result(read, write, size, t.toString());
  +      // add to map
  +      results.put(t, r);
  +      printResults(r);
  +   }
  +
  +   private Object createRemoteMethodCall()
  +   {
  +      Map data = new HashMap();
  +      data.put("key", "value");
  +      MethodCall put1 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.fromString("/root/put1"), data, true);
  +      MethodCall put2 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.fromString("/root/put2"), data, true);
  +      MethodCall put3 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.fromString("/root/put3"), data, true);
  +      List list = new LinkedList();
  +      list.add(put1);
  +      list.add(put2);
  +      list.add(put3);
  +      MethodCall methodToCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, null, list, null, true);
  +      return MethodCallFactory.create(MethodDeclarations.replicateMethod, methodToCall);
      }
   
      private byte[] writeStandardSerialization(Object o) throws Exception
  @@ -205,47 +270,68 @@
         TestingUtil.sleepThread(random.nextInt(1000));
      }
   
  -   private void printResults(String name, long[] writeStats, long[] readStats)
  +   private void printResults(Result r)
      {
  -      Map writeResults = getStats(writeStats);
  -      Map readResults = getStats(readStats);
  +      System.out.println(r);
  +   }
   
  -      System.out.println("------------------------------------");
  -      System.out.println("  (all times in ms)");
  -      System.out.println();
  -      System.out.println("  Test name:         Writes for " + name);
  -      System.out.println("  NumThreads:        " + NUM_THREADS);
  -      System.out.println("  NumLoopsPerThread: " + NUM_TIMES_PER_THREAD);
  -      System.out.println();
  -      System.out.println("  Writes Total time:        " + writeResults.get("total"));
  -      System.out.println("  Writes Avg time:          " + ((Long) writeResults.get("total")).doubleValue() / writeStats.length);
  -      System.out.println("  Writes shortest time:     " + writeResults.get("shortest"));
  -      System.out.println("  Writes longest time:      " + writeResults.get("longest"));
  -      System.out.println();
  -      System.out.println("  Reads Total time:         " + readResults.get("total"));
  -      System.out.println("  Reads Avg time:           " + ((Long) readResults.get("total")).doubleValue() / readStats.length);
  -      System.out.println("  Reads shortest time:      " + readResults.get("shortest"));
  -      System.out.println("  Reads longest time:       " + readResults.get("longest"));
  -      System.out.println("------------------------------------");
  -   }
  -
  -   public Map<String, Long> getStats(long[] stats)
  -   {
  -      long statTotal = 0;
  -      long largest = 0;
  -      long smallest = stats[0];
  -      for (long stat : stats)
  -      {
  -         statTotal = statTotal + stat;
  -         if (stat > largest) largest = stat;
  -         if (stat < smallest) smallest = stat;
  -      }
  -
  -      Map<String, Long> results = new HashMap<String, Long>();
  -      results.put("total", statTotal);
  -      results.put("shortest", smallest);
  -      results.put("longest", largest);
   
  -      return results;
  +   private static class Result
  +   {
  +      long writeTotalTime, readTotalTime;
  +      int size;
  +      long writeLongestTime, readLongestTime;
  +      long writeShortestTime = Long.MAX_VALUE, readShortestTime = Long.MAX_VALUE;
  +      double writeAverageTime, readAverageTime;
  +      String name;
  +
  +
  +      public Result(long[] readStats, long[] writeStats, int size, String name)
  +      {
  +         this.size = size;
  +         this.name = name;
  +
  +         for (long stat : readStats)
  +         {
  +            readLongestTime = Math.max(readLongestTime, stat);
  +            readShortestTime = Math.min(readShortestTime, stat);
  +            readTotalTime += stat;
  +         }
  +
  +         readAverageTime = ((double) readTotalTime) / readStats.length;
  +
  +         for (long stat : writeStats)
  +         {
  +            writeLongestTime = Math.max(writeLongestTime, stat);
  +            writeShortestTime = Math.min(writeShortestTime, stat);
  +            writeTotalTime += stat;
  +         }
  +
  +         writeAverageTime = ((double) writeTotalTime) / readStats.length;
  +      }
  +
  +      public String toString()
  +      {
  +         String s = "------------------------------------\n";
  +         s += "  (all times in ms)\n";
  +         s += "\n";
  +         s += "  Test name:         Writes for " + name + "\n";
  +         s += "  NumThreads:        " + NUM_THREADS + "\n";
  +         s += "  NumLoopsPerThread: " + NUM_TIMES_PER_THREAD + "\n";
  +         s += "\n";
  +         s += "  Writes Total time:        " + writeTotalTime + "\n";
  +         s += "  Writes Avg time:          " + writeAverageTime + "\n";
  +         s += "  Writes shortest time:     " + writeShortestTime + "\n";
  +         s += "  Writes longest time:      " + writeLongestTime + "\n";
  +         s += "\n";
  +         s += "  Reads Total time:         " + readTotalTime + "\n";
  +         s += "  Reads Avg time:           " + readAverageTime + "\n";
  +         s += "  Reads shortest time:      " + readShortestTime + "\n";
  +         s += "  Reads longest time:       " + readLongestTime + "\n";
  +         s += "\n";
  +         s += "  Byte array size:       " + size + "\n";
  +         s += "------------------------------------\n";
  +         return s;
  +      }
      }
   }
  
  
  



More information about the jboss-cvs-commits mailing list