[jbosscache-commits] JBoss Cache SVN: r8266 - in core/trunk/src/test/java/org/jboss/cache/profiling: testinternals and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Oct 21 11:33:44 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-10-21 11:33:44 -0400 (Wed, 21 Oct 2009)
New Revision: 8266

Modified:
   core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java
   core/trunk/src/test/java/org/jboss/cache/profiling/ProfileSlaveTest.java
   core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
   core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/TaskRunner.java
Log:
Updated perf test internals

Modified: core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java	2009-10-21 09:54:32 UTC (rev 8265)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java	2009-10-21 15:33:44 UTC (rev 8266)
@@ -33,6 +33,15 @@
       cache = null;
    }
 
+   boolean startedInCmdLine = false;
+   String clusterNameOverride = null;
+   protected void initTest() {
+      System.out.println("Setting up test params!");
+      if (startedInCmdLine) {
+         setUp();
+      }
+   }
+
    public abstract void testReplSync() throws Exception;
 
    public abstract void testReplAsync() throws Exception;

Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileSlaveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileSlaveTest.java	2009-10-21 09:54:32 UTC (rev 8265)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileSlaveTest.java	2009-10-21 15:33:44 UTC (rev 8266)
@@ -8,44 +8,66 @@
 
 /**
  * Slave to go with ProfileTest.  Should be done in a different VM.  Can be profiled as well to profile receiving
- * messages.
- * Importnat - make sure you inly enable these tests locally!
+ * messages. Importnat - make sure you inly enable these tests locally!
  *
  * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
  * @since 2.1.0
  */
 @Test(groups = "profiling", testName = "profiling.ProfileSlaveTest", enabled = false)
-public class ProfileSlaveTest extends AbstractProfileTest
-{
-   private void waitForTest() throws Exception
-   {
+public class ProfileSlaveTest extends AbstractProfileTest {
+
+   public static void main(String[] args) throws Exception {
+      ProfileSlaveTest pst = new ProfileSlaveTest();
+      pst.startedInCmdLine = true;
+
+      String mode = args[0];
+      try {
+         if (args.length > 1) pst.clusterNameOverride = args[1];
+         if (mode.equals("replsync")) {
+            pst.testReplSync();
+         } else if (mode.equals("replasync")) {
+            pst.testReplAsync();
+         }
+      } finally {
+         pst.tearDown();
+      }
+
+   }
+
+   private void waitForTest() throws Exception {
       System.out.println("Slave listening for remote connections.  Hit Enter when done.");
       System.in.read();
+      if (clusterNameOverride != null) cache.getConfiguration().setClusterName(clusterNameOverride);
    }
 
    @Test(enabled = false)
-   public void testReplSync() throws Exception
-   {
+   public void testReplSync() throws Exception {
+      initTest();
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.MVCC);
-      cache.getConfiguration().setExposeManagementStatistics(true);
+      cache.getConfiguration().setConcurrencyLevel(5000);
       cache.start();
+      System.out.println("My Address is " + cache.getLocalAddress());
+      doTest();
       waitForTest();
    }
 
+   private void doTest() {
+      // this is here to act as a JProfiler trigger
+   }
+
    @Test(enabled = false)
-   public void testReplAsync() throws Exception
-   {
+   public void testReplAsync() throws Exception {
+      initTest();
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.MVCC);
       cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
       cache.getConfiguration().setConcurrencyLevel(5000);
-      cache.getConfiguration().setClusterConfig(getJGroupsConfig());
+//      cache.getConfiguration().setClusterConfig(getJGroupsConfig());
       cache.start();
       waitForTest();
    }
 
    @Test(enabled = false)
-   public void testReplSyncOptimistic() throws Exception
-   {
+   public void testReplSyncOptimistic() throws Exception {
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
       cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
       cache.start();
@@ -53,8 +75,7 @@
    }
 
    @Test(enabled = false)
-   public void testReplAsyncOptimistic() throws Exception
-   {
+   public void testReplAsyncOptimistic() throws Exception {
       cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
       cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
@@ -63,8 +84,7 @@
    }
 
    @Test(enabled = false)
-   public void testReplSyncBR() throws Exception
-   {
+   public void testReplSyncBR() throws Exception {
       BuddyReplicationConfig brc = new BuddyReplicationConfig();
       brc.setEnabled(true);
       cache.getConfiguration().setBuddyReplicationConfig(brc);
@@ -72,8 +92,7 @@
    }
 
    @Test(enabled = false)
-   public void testReplAsyncBR() throws Exception
-   {
+   public void testReplAsyncBR() throws Exception {
       BuddyReplicationConfig brc = new BuddyReplicationConfig();
       brc.setEnabled(true);
       cache.getConfiguration().setBuddyReplicationConfig(brc);
@@ -85,8 +104,7 @@
    }
 
    @Test(enabled = false)
-   public void testReplSyncOptBR() throws Exception
-   {
+   public void testReplSyncOptBR() throws Exception {
       BuddyReplicationConfig brc = new BuddyReplicationConfig();
       brc.setEnabled(true);
       cache.getConfiguration().setBuddyReplicationConfig(brc);
@@ -94,8 +112,7 @@
    }
 
    @Test(enabled = false)
-   public void testReplAsyncOptBR() throws Exception
-   {
+   public void testReplAsyncOptBR() throws Exception {
       BuddyReplicationConfig brc = new BuddyReplicationConfig();
       brc.setEnabled(true);
       cache.getConfiguration().setBuddyReplicationConfig(brc);
@@ -103,26 +120,22 @@
    }
 
    @Test(enabled = false)
-   public void testStateTransfer() throws Exception
-   {
+   public void testStateTransfer() throws Exception {
       throw new Exception("Implement me");
    }
 
    @Test(enabled = false)
-   public void testStartup() throws Exception
-   {
+   public void testStartup() throws Exception {
       throw new Exception("Implement me");
    }
 
    @Test(enabled = false)
-   public void testCacheLoading() throws Exception
-   {
+   public void testCacheLoading() throws Exception {
       throw new Exception("Implement me");
    }
 
    @Test(enabled = false)
-   public void testPassivation() throws Exception
-   {
+   public void testPassivation() throws Exception {
       throw new Exception("Implement me");
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2009-10-21 09:54:32 UTC (rev 8265)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2009-10-21 15:33:44 UTC (rev 8266)
@@ -22,18 +22,17 @@
  * <p/>
  * Typical usage pattern:
  * <p/>
- * 1.  Start a single test method in ProfileSlaveTest.  This will block until you kill it.
- * 2.  Start the corresponding test in this class, with the same name, in a different JVM, and attached to a profiler.
- * 3.  Profile away!
+ * 1.  Start a single test method in ProfileSlaveTest.  This will block until you kill it. 2.  Start the corresponding
+ * test in this class, with the same name, in a different JVM, and attached to a profiler. 3.  Profile away!
  * <p/>
- *
+ * <p/>
  * Importnat - make sure you inly enable these tests locally!
+ *
  * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
  * @since 2.1.0
  */
 @Test(groups = "profiling", testName = "profiling.ProfileTest", enabled = false)
-public class ProfileTest extends AbstractProfileTest
-{
+public class ProfileTest extends AbstractProfileTest {
    /*
       Test configuration options
     */
@@ -45,14 +44,32 @@
    protected static final int WARMUP_LOOPS = 20000;
    protected static final boolean USE_SLEEP = false; // throttle generation a bit
 
+   protected static final boolean SKIP_WARMUP = true;
 
+
    private List<Fqn> fqns = new ArrayList<Fqn>(MAX_OVERALL_NODES);
 
    Log log = LogFactory.getLog(ProfileTest.class);
 
+   public static void main(String[] args) throws Exception {
+      ProfileTest pst = new ProfileTest();
+      pst.startedInCmdLine = true;
+
+      String mode = args[0];
+      try {
+         if (args.length > 1) pst.clusterNameOverride = args[1];
+         if (mode.equals("replsync")) {
+            pst.testReplSync();
+         } else if (mode.equals("replasync")) {
+            pst.testReplAsync();
+         }
+      } finally {
+         pst.tearDown();
+      }
+   }
+
    @Test(enabled = false)
-   public void testLocalModePess() throws Exception
-   {
+   public void testLocalModePess() throws Exception {
       Configuration cfg = cache.getConfiguration();
       cfg.setCacheMode(Configuration.CacheMode.LOCAL);
       cfg.setConcurrencyLevel(2000);
@@ -64,42 +81,42 @@
    }
 
    @Test(enabled = false)
-   public void testLocalModeOpt() throws Exception
-   {
+   public void testLocalModeOpt() throws Exception {
       cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
       runCompleteTest();
    }
 
    @Test(enabled = false)
-   public void testReplSync() throws Exception
-   {
+   public void testReplSync() throws Exception {
+      initTest();
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.MVCC);
+      cache.getConfiguration().setSerializationExecutorPoolSize(0);
+      cache.getConfiguration().setConcurrencyLevel(5000);
+
       runCompleteTest();
    }
 
    @Test(enabled = false)
-   public void testReplAsync() throws Exception
-   {
+   public void testReplAsync() throws Exception {
+      initTest();
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.MVCC);
       cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
       cache.getConfiguration().setSerializationExecutorPoolSize(0);
       cache.getConfiguration().setConcurrencyLevel(5000);
-      cache.getConfiguration().setClusterConfig(getJGroupsConfig());
+
       runCompleteTest();
    }
 
    @Test(enabled = false)
-   public void testReplSyncOptimistic() throws Exception
-   {
+   public void testReplSyncOptimistic() throws Exception {
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
       cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
       runCompleteTest();
    }
 
    @Test(enabled = false)
-   public void testReplAsyncOptimistic() throws Exception
-   {
+   public void testReplAsyncOptimistic() throws Exception {
       cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
       cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
       cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
@@ -107,8 +124,7 @@
    }
 
    @Test(enabled = false)
-   public void testReplSyncBR() throws Exception
-   {
+   public void testReplSyncBR() throws Exception {
       BuddyReplicationConfig brc = new BuddyReplicationConfig();
       brc.setEnabled(true);
       cache.getConfiguration().setBuddyReplicationConfig(brc);
@@ -116,8 +132,7 @@
    }
 
    @Test(enabled = false)
-   public void testReplAsyncBR() throws Exception
-   {
+   public void testReplAsyncBR() throws Exception {
       BuddyReplicationConfig brc = new BuddyReplicationConfig();
       brc.setEnabled(true);
       cache.getConfiguration().setBuddyReplicationConfig(brc);
@@ -129,8 +144,7 @@
    }
 
    @Test(enabled = false)
-   public void testReplSyncOptBR() throws Exception
-   {
+   public void testReplSyncOptBR() throws Exception {
       BuddyReplicationConfig brc = new BuddyReplicationConfig();
       brc.setEnabled(true);
       cache.getConfiguration().setBuddyReplicationConfig(brc);
@@ -138,21 +152,19 @@
    }
 
    @Test(enabled = false)
-   public void testReplAsyncOptBR() throws Exception
-   {
+   public void testReplAsyncOptBR() throws Exception {
       BuddyReplicationConfig brc = new BuddyReplicationConfig();
       brc.setEnabled(true);
       cache.getConfiguration().setBuddyReplicationConfig(brc);
       testReplAsyncOptimistic();
    }
 
-   private void runCompleteTest() throws Exception
-   {
+   private void runCompleteTest() throws Exception {
       init();
       startup();
       warmup();
       doTest();
-
+      testFinishedMarker();
       // wait for user exit
       System.in.read();
    }
@@ -161,18 +173,15 @@
     * Thr following test phases can be profiled individually using triggers in JProfiler.
     */
 
-   protected void init()
-   {
+   protected void init() {
       long startTime = System.currentTimeMillis();
       log.warn("Starting init() phase");
       fqns.clear();
-      for (int i = 0; i < MAX_OVERALL_NODES; i++)
-      {
+      for (int i = 0; i < MAX_OVERALL_NODES; i++) {
          Fqn fqn = Generator.createRandomFqn(MAX_DEPTH);
          while (fqns.contains(fqn)) fqn = Generator.createRandomFqn(MAX_DEPTH);
-         if (i % 10 == 0)
-         {
-            log.warn("Generated " + i + " fqns");
+         if (i % 10 == 0) {
+            log.trace("Generated " + i + " fqns");
          }
          fqns.add(fqn);
       }
@@ -181,8 +190,7 @@
       log.warn("Finished init() phase.  " + printDuration(duration));
    }
 
-   protected void startup()
-   {
+   protected void startup() {
       long startTime = System.currentTimeMillis();
       log.warn("Starting cache");
       cache.start();
@@ -190,18 +198,20 @@
       log.warn("Started cache.  " + printDuration(duration));
    }
 
-   private void warmup() throws InterruptedException
-   {
+   private void warmup() throws InterruptedException {
+      if (SKIP_WARMUP) {
+         log.info("Skipping warmup; taking a nap.");
+         Thread.sleep(5000);
+         log.info("Waking up");
+         return;
+      }
       long startTime = System.currentTimeMillis();
       TaskRunner exec = new TaskRunner(NUM_THREADS);
       log.warn("Starting warmup");
       // creates all the Fqns since this can be expensive and we don't really want to measure this (for now)
-      for (final Fqn f : fqns)
-      {
-         exec.execute(new Runnable()
-         {
-            public void run()
-            {
+      for (final Fqn f : fqns) {
+         exec.execute(new Runnable() {
+            public void run() {
                // this will create the necessary nodes.
                cache.put(f, Collections.emptyMap());
             }
@@ -209,12 +219,9 @@
       }
 
       // loop through WARMUP_LOOPS gets and puts for JVM optimisation
-      for (int i = 0; i < WARMUP_LOOPS; i++)
-      {
-         exec.execute(new Runnable()
-         {
-            public void run()
-            {
+      for (int i = 0; i < WARMUP_LOOPS; i++) {
+         exec.execute(new Runnable() {
+            public void run() {
                Fqn f = Generator.getRandomElement(fqns);
                cache.get(f, "");
                cache.put(f, "k", "v");
@@ -233,8 +240,11 @@
       startup();
    }
 
-   private void doTest() throws Exception
-   {
+   private void testFinishedMarker() {
+      System.out.println("Test finished");
+   }
+
+   private void doTest() throws Exception {
       TaskRunner exec = new TaskRunner(NUM_THREADS);
       log.warn("Starting test");
       int i;
@@ -245,11 +255,9 @@
       AtomicLong durationRemoves = new AtomicLong();
 
       long stElapsed = System.nanoTime();
-      for (i = 0; i < NUM_OPERATIONS; i++)
-      {
+      for (i = 0; i < NUM_OPERATIONS; i++) {
          MyRunnable r = null;
-         switch (i % 3)
-         {
+         switch (i % 3) {
             case 0:
                r = new Putter(i, durationPuts);
                break;
@@ -280,121 +288,105 @@
       log.warn("Average REMOVE time: " + printAvg(durationRemoves.get()));
    }
 
-   private String printAvg(long totalNanos)
-   {
+   private String printAvg(long totalNanos) {
       double nOps = (double) (NUM_OPERATIONS / 3);
       double avg = ((double) totalNanos) / nOps;
       double avgMicros = avg / 1000;
-      return avgMicros + " µs";
+      return avgMicros + " �s";
    }
 
-   private double toMillis(long nanos)
-   {
+   private double toMillis(long nanos) {
       return ((double) nanos / (double) 1000000);
    }
 
-   enum Mode
-   {
+   enum Mode {
       PUT, GET, REMOVE
    }
 
-   private abstract class MyRunnable implements Runnable
-   {
+   private abstract class MyRunnable implements Runnable {
       int id;
       Mode mode;
       AtomicLong duration;
 
-      public void run()
-      {
-         String k = Generator.getRandomString();
-         Fqn f = Generator.getRandomElement(fqns);
-         long d = 0, st = 0;
-         switch (mode)
-         {
-            case PUT:
-               st = System.nanoTime();
-               cache.put(f, k, Generator.getRandomString());
-               d = System.nanoTime() - st;
-               break;
-            case GET:
-               st = System.nanoTime();
-               cache.get(f, k);
-               d = System.nanoTime() - st;
-               break;
-            case REMOVE:
-               st = System.nanoTime();
-               cache.remove(f, k);
-               d = System.nanoTime() - st;
-               break;
+      public void run() {
+         try {
+            String k = Generator.getRandomString();
+            Fqn f = Generator.getRandomElement(fqns);
+            long d = 0, st = 0;
+            switch (mode) {
+               case PUT:
+                  st = System.nanoTime();
+                  cache.put(f, k, Generator.getRandomString());
+                  d = System.nanoTime() - st;
+                  break;
+               case GET:
+                  st = System.nanoTime();
+                  cache.get(f, k);
+                  d = System.nanoTime() - st;
+                  break;
+               case REMOVE:
+                  st = System.nanoTime();
+                  cache.remove(f, k);
+                  d = System.nanoTime() - st;
+                  break;
+            }
+            duration.getAndAdd(d);
+         } catch (Exception e) {
+            log.warn("Caught ", e);
          }
-         duration.getAndAdd(d);
       }
    }
 
-   private class Putter extends MyRunnable
-   {
-      private Putter(int id, AtomicLong duration)
-      {
+   private class Putter extends MyRunnable {
+      private Putter(int id, AtomicLong duration) {
          this.id = id;
          this.duration = duration;
          mode = Mode.PUT;
       }
    }
 
-   private class Getter extends MyRunnable
-   {
-      private Getter(int id, AtomicLong duration)
-      {
+   private class Getter extends MyRunnable {
+      private Getter(int id, AtomicLong duration) {
          this.id = id;
          this.duration = duration;
          mode = Mode.GET;
       }
    }
 
-   private class Remover extends MyRunnable
-   {
-      private Remover(int id, AtomicLong duration)
-      {
+   private class Remover extends MyRunnable {
+      private Remover(int id, AtomicLong duration) {
          this.id = id;
          this.duration = duration;
          mode = Mode.REMOVE;
       }
    }
 
-   protected String printDuration(long duration)
-   {
-      if (duration > 2000)
-      {
+   protected String printDuration(long duration) {
+      if (duration > 2000) {
          double dSecs = ((double) duration / (double) 1000);
          return "Duration: " + dSecs + " seconds";
-      }
-      else
-      {
+      } else {
          return "Duration: " + duration + " millis";
       }
    }
 
    @Test(enabled = false)
-   public void testStateTransfer() throws Exception
-   {
+   public void testStateTransfer() throws Exception {
       throw new Exception("Implement me");
    }
 
    @Test(enabled = false)
-   public void testStartup() throws Exception
-   {
+   public void testStartup() throws Exception {
       throw new Exception("Implement me");
    }
 
    @Test(enabled = false)
-   public void testCacheLoading() throws Exception
-   {
+   public void testCacheLoading() throws Exception {
       throw new Exception("Implement me");
    }
 
    @Test(enabled = false)
-   public void testPassivation() throws Exception
-   {
+   public void testPassivation() throws Exception {
       throw new Exception("Implement me");
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/TaskRunner.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/TaskRunner.java	2009-10-21 09:54:32 UTC (rev 8265)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/TaskRunner.java	2009-10-21 15:33:44 UTC (rev 8266)
@@ -2,7 +2,9 @@
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Essentially a delegate to an ExecutorService, but a special one that is only used by perf tests so it can be ignored
@@ -14,7 +16,13 @@
 
    public TaskRunner(int numThreads)
    {
-      this.exec = Executors.newFixedThreadPool(numThreads);
+      final ThreadGroup tg = new ThreadGroup(Thread.currentThread().getThreadGroup(), "LoadGenerators");
+      final AtomicInteger ai = new AtomicInteger(1);
+      this.exec = Executors.newFixedThreadPool(numThreads, new ThreadFactory() {         
+         public Thread newThread(Runnable r) {
+            return new Thread(tg, r, "LoadGenerator-" + ai.getAndIncrement());
+         }
+      });
    }
 
    public void execute(Runnable r)



More information about the jbosscache-commits mailing list