[jbosscache-commits] JBoss Cache SVN: r6304 - in benchmarks/benchmark-fwk/trunk: conf and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Jul 16 11:03:07 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-07-16 11:03:07 -0400 (Wed, 16 Jul 2008)
New Revision: 6304

Modified:
   benchmarks/benchmark-fwk/trunk/conf/cachebench-local.xml
   benchmarks/benchmark-fwk/trunk/runAllLocal.sh
   benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/simpletests/SimpleTest.java
Log:
Simple tests now measure concurrent puts and gets like the session repl test

Modified: benchmarks/benchmark-fwk/trunk/conf/cachebench-local.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/conf/cachebench-local.xml	2008-07-16 13:57:30 UTC (rev 6303)
+++ benchmarks/benchmark-fwk/trunk/conf/cachebench-local.xml	2008-07-16 15:03:07 UTC (rev 6304)
@@ -60,7 +60,9 @@
          * You can write your own custom testClass.
          * weight is currently unused.
       -->
-      <test name="Strings" testClass="org.cachebench.tests.simpletests.StringTest" weight="2.0"/>
+      <test name="Strings" testClass="org.cachebench.tests.simpletests.StringTest" weight="2.0">
+         <param name="writePercentage" value="20"/>
+      </test>
 
       <!--<test name="SessionSimulator" testClass="org.cachebench.tests.SessionSimulatorTest" weight="2.0">-->
       <!--<param name="numberOfRequest" value="100000"/>-->

Modified: benchmarks/benchmark-fwk/trunk/runAllLocal.sh
===================================================================
--- benchmarks/benchmark-fwk/trunk/runAllLocal.sh	2008-07-16 13:57:30 UTC (rev 6303)
+++ benchmarks/benchmark-fwk/trunk/runAllLocal.sh	2008-07-16 15:03:07 UTC (rev 6304)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+rm -rf ./output/*
+
 ./runLocalNode.sh jbosscache-3.0.0 pess-local.xml
 ./runLocalNode.sh jbosscache-3.0.0 mvcc-local.xml
 ./runLocalNode.sh jbosscache-3.0.0 pess-local-NONE.xml

Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/simpletests/SimpleTest.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/simpletests/SimpleTest.java	2008-07-16 13:57:30 UTC (rev 6303)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/simpletests/SimpleTest.java	2008-07-16 15:03:07 UTC (rev 6304)
@@ -6,6 +6,8 @@
 import org.cachebench.CacheWrapper;
 import org.cachebench.SerializableCacheWrapper;
 import org.cachebench.config.Configuration;
+import org.cachebench.config.TestCase;
+import org.cachebench.config.TestConfig;
 import org.cachebench.tests.CacheTest;
 import org.cachebench.tests.results.StatisticTestResult;
 
@@ -13,9 +15,11 @@
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.Date;
+import java.util.Random;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
 
@@ -27,14 +31,31 @@
 {
    protected Log log = LogFactory.getLog(this.getClass());
    protected AtomicLong numberOfBytesPut = new AtomicLong(0);
-   protected long elapsedSecondsForAllPuts = 0;
+   protected int writePercentage = 50;
    protected ExecutorService executor;
    private static final int EXECUTOR_SHUTDOWN_TIMEOUT_POLL_SECS = 60;
    protected Configuration configuration;
    protected final int LOG_FREQUENCY = 5000;
 
+   private int getWritePercentageFromConfig(String testCaseName, String testName)
+   {
+      try
+      {
+         TestCase tc = configuration.getTestCase(testName);
+         TestConfig t = tc.getTest(testCaseName);
+         return t.getIntValue("writePercentage");
+      }
+      catch (Exception e)
+      {
+         log.warn("Unable to get write percentage.  Using default (50)", e);
+         return 50;
+      }
+   }
+
    protected StatisticTestResult performTestWithObjectType(String testCaseName, CacheWrapper cache, Class valueClass, String testName, int sampleSize, int numThreads) throws Exception
    {
+      writePercentage = getWritePercentageFromConfig(testCaseName, testName);
+      log.info("Using write percentage " + writePercentage);
       log.info("Number of threads " + numThreads);
       executor = Executors.newFixedThreadPool(numThreads);
 
@@ -43,14 +64,11 @@
       result.setTestTime(new Date());
       result.setTestType(testName);
 
-      log.info("Performing '" + sampleSize + "' PUTs");
-      DescriptiveStatistics putStats = doPuts(cache, valueClass, sampleSize);
-      executor = Executors.newFixedThreadPool(numThreads);
-      log.info("Performing GETs");
-      DescriptiveStatistics getStats = doGets(cache, sampleSize);
+      log.info("Performing test");
+      DescriptiveStatistics[] stats = doGetsAndPuts(cache, valueClass, sampleSize);
 
-      result.setGetData(getStats);
-      result.setPutData(putStats);
+      result.setGetData(stats[0]);
+      result.setPutData(stats[1]);
       result.setTestPassed(true); // The test is passed. The report would make use of this attribute.
 
       // calculate throughput, in transactions per second.
@@ -58,8 +76,10 @@
 
       // calc tps.
 
+      long elapsedSecondsForAllPuts = TimeUnit.NANOSECONDS.toSeconds((long) stats[1].getSum());
+
       System.out.println("*** sum of time: " + elapsedSecondsForAllPuts);
-      System.out.println("*** num puts occured: " + putStats.getN());
+      System.out.println("*** num puts occured: " + stats[1].getN());
 
       try
       {
@@ -93,49 +113,112 @@
     * @param sampleSize The size of the cache.
     * @return The Descriptive statistics of the cache benchmarking.
     */
-   private DescriptiveStatistics doGets(final CacheWrapper cache, int sampleSize) throws Exception
+   private DescriptiveStatistics[] doGetsAndPuts(final CacheWrapper cache, final Class valueClass, int sampleSize) throws Exception
    {
       log.debug("Inside doGets for : " + cache);
       final String key = "baseKey";
-      final DescriptiveStatistics stats = DescriptiveStatistics.newInstance();
+      final DescriptiveStatistics getStats = DescriptiveStatistics.newInstance();
+      final DescriptiveStatistics putStats = DescriptiveStatistics.newInstance();
       final boolean useSerializable = cache instanceof SerializableCacheWrapper;
+      Random rand = new Random();
+      int modDivisor = 100 / writePercentage;
+      numberOfBytesPut.set(0);
 
+      final AtomicInteger getCount = new AtomicInteger(0);
+      final AtomicInteger putCount = new AtomicInteger(0);
+
       for (int i = 0; i < sampleSize; i++)
       {
-         final int cycleNumber = i;
-         Runnable r = new Runnable()
+         Runnable r;
+         if (rand.nextInt(100) % modDivisor == 0)
          {
-            public void run()
+            // do a WRITE!
+            r = new Runnable()
             {
-               try
+               public void run()
                {
-                  if (!useSerializable)
+                  int cycleNumber = putCount.getAndIncrement();
+                  try
                   {
-                     // start your timer...
-                     long startTime = System.nanoTime();
-                     cache.get(key + cycleNumber);
-                     long statValue = (System.nanoTime() - startTime);
-                     stats.addValue(statValue);
-                     log.debug("The Get stat : " + statValue);
+                     // generate some value
+                     Object value;
+                     if (valueClass == null) value = null;
+                     else if (valueClass.getName().equals(String.class.getName())) value = "value" + cycleNumber;
+                     else if (valueClass.getName().equals(Integer.class.getName())) value = cycleNumber;
+                     else value = valueClass.newInstance();
+
+                     // even though some impls may use special marshalling to reduce the amount of data transmitted (such as JBoss Cache's
+                     // CacheMarshaller) we still want to measure the serialized size of objects for this metric.
+
+                     numberOfBytesPut.getAndAdd(calculateSerializedSize(value));
+
+                     if (!useSerializable)
+                     {
+                        // start your timer...
+                        long startTime = System.nanoTime();
+                        cache.put(key + cycleNumber, value);
+                        long statValue = (System.nanoTime() - startTime);
+                        putStats.addValue(statValue);
+                        if (log.isDebugEnabled()) log.debug("Time For This Put: " + statValue);
+                     }
+                     else
+                     {
+                        SerializableCacheWrapper sCache = (SerializableCacheWrapper) cache;
+                        Serializable sValue = (Serializable) value;
+                        long startTime = System.nanoTime();
+                        sCache.putSerializable(key + cycleNumber, sValue);
+                        long statValue = (System.nanoTime() - startTime);
+                        putStats.addValue(statValue);
+                        if (log.isDebugEnabled()) log.debug("Time For This Put: " + statValue);
+                     }
+                     logOperation(cycleNumber, "PUTS");
                   }
-                  else
+                  catch (Exception e)
                   {
-                     SerializableCacheWrapper sCache = (SerializableCacheWrapper) cache;
-                     long startTime = System.nanoTime();
-                     sCache.getSerializable(key + cycleNumber);
-                     long statValue = (System.nanoTime() - startTime);
-                     stats.addValue(statValue);
-                     log.debug("The Get stat : " + statValue);
+                     // how should we handle this?  Log for now...
+                     log.error("Operation failed!", e);
                   }
-                  logOperation(cycleNumber, "GETS");
                }
-               catch (Exception e)
+            };
+         }
+         else
+         {
+            // do a READ!
+            r = new Runnable()
+            {
+               public void run()
                {
-                  // how should we handle this?  Log for now...
-                  log.error("Operation failed!", e);
+                  int cycleNumber = getCount.getAndIncrement();
+                  try
+                  {
+                     if (!useSerializable)
+                     {
+                        // start your timer...
+                        long startTime = System.nanoTime();
+                        cache.get(key + cycleNumber);
+                        long statValue = (System.nanoTime() - startTime);
+                        getStats.addValue(statValue);
+                        if (log.isDebugEnabled()) log.debug("Time For This Get: " + statValue);
+                     }
+                     else
+                     {
+                        SerializableCacheWrapper sCache = (SerializableCacheWrapper) cache;
+                        long startTime = System.nanoTime();
+                        sCache.getSerializable(key + cycleNumber);
+                        long statValue = (System.nanoTime() - startTime);
+                        getStats.addValue(statValue);
+                        if (log.isDebugEnabled()) log.debug("Time For This Get: " + statValue);
+                     }
+                     logOperation(cycleNumber, "GETS");
+                  }
+                  catch (Exception e)
+                  {
+                     // how should we handle this?  Log for now...
+                     log.error("Operation failed!", e);
+                  }
                }
-            }
-         };
+            };
+         }
 
          // submit task to be executed
          executor.execute(r);
@@ -145,8 +228,8 @@
       blockTillTasksComplete();
 
       // return the raw data
-      log.debug("Leaving doGets for : " + cache);
-      return stats;
+      log.debug("Leaving doTasks for : " + cache);
+      return new DescriptiveStatistics[]{getStats, putStats};
    }
 
    private void logOperation(int i, String s)
@@ -157,83 +240,6 @@
       }
    }
 
-   /**
-    * @param cache      The Cachewrapper on which the bechmark is conducted.
-    * @param valueClass The value class instance which is going to be inserted into the Cache.
-    * @param sampleSize The size of the cache.
-    * @return The Descriptive statistics of the cache benchmarking.
-    */
-   private DescriptiveStatistics doPuts(final CacheWrapper cache, final Class valueClass, int sampleSize) throws Exception
-   {
-      log.debug("Inside doPuts for " + cache);
-      final String key = "baseKey";
-      final DescriptiveStatistics stats = DescriptiveStatistics.newInstance();
-      final boolean useSerializable = cache instanceof SerializableCacheWrapper;
-      numberOfBytesPut.set(0);
-      elapsedSecondsForAllPuts = 0;
-      long startElapsedTime = System.nanoTime();
-
-      for (int i = 0; i < sampleSize; i++)
-      {
-         final int cycleNumber = i;
-         Runnable r = new Runnable()
-         {
-            public void run()
-            {
-               try
-               {
-                  // generate some value
-                  Object value;
-                  if (valueClass == null) value = null;
-                  else if (valueClass.getName().equals("java.lang.String")) value = "value" + cycleNumber;
-                  else if (valueClass.getName().equals("java.lang.Integer")) value = cycleNumber;
-                  else value = valueClass.newInstance();
-
-                  // even though some impls may use special marshalling to reduce the amount of data transmitted (such as JBoss Cache's
-                  // CacheMarshaller) we still want to measure the serialized size of objects for this metric.
-
-                  numberOfBytesPut.getAndAdd(calculateSerializedSize(value));
-
-                  if (!useSerializable)
-                  {
-                     // start your timer...
-                     long startTime = System.nanoTime();
-                     cache.put(key + cycleNumber, value);
-                     long statValue = (System.nanoTime() - startTime);
-                     stats.addValue(statValue);
-                  }
-                  else
-                  {
-                     SerializableCacheWrapper sCache = (SerializableCacheWrapper) cache;
-                     Serializable sValue = (Serializable) value;
-                     long startTime = System.nanoTime();
-                     sCache.putSerializable(key + cycleNumber, sValue);
-                     long statValue = (System.nanoTime() - startTime);
-                     stats.addValue(statValue);
-                  }
-                  logOperation(cycleNumber, "PUTS");
-               }
-               catch (Exception e)
-               {
-                  // how should we handle this?  Log for now...
-                  log.error("Operation failed!", e);
-               }
-            }
-         };
-         // submit task to be executed
-         executor.execute(r);
-      }
-
-      // only leave once the task queue is empty!!
-      blockTillTasksComplete();
-
-      elapsedSecondsForAllPuts = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startElapsedTime);
-
-      // return the raw data
-      log.debug("Leaving doPuts for " + cache);
-      return stats;
-   }
-
    private void blockTillTasksComplete()
    {
       // now that just told us that all the tasks have been submitted.  Lets check that the executor has finished everything.




More information about the jbosscache-commits mailing list