[jbosscache-commits] JBoss Cache SVN: r7334 - 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
Tue Dec 16 09:19:02 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-12-16 09:19:02 -0500 (Tue, 16 Dec 2008)
New Revision: 7334

Added:
   core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/
   core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/Generator.java
   core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/TaskRunner.java
Modified:
   core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
Log:


Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2008-12-16 13:46:43 UTC (rev 7333)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2008-12-16 14:19:02 UTC (rev 7334)
@@ -6,6 +6,8 @@
 import org.jboss.cache.config.BuddyReplicationConfig;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.profiling.testinternals.Generator;
+import org.jboss.cache.profiling.testinternals.TaskRunner;
 import org.jboss.cache.transaction.DummyTransactionManagerLookup;
 import org.jboss.cache.util.TestingUtil;
 import org.testng.annotations.Test;
@@ -13,10 +15,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Random;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
@@ -39,26 +37,29 @@
    /*
       Test configuration options
     */
-   protected static final long NUM_OPERATIONS = 5000000; // DURATION is replaced with a fixed number of operations instead.
+   protected static final long NUM_OPERATIONS = 1000000; // DURATION is replaced with a fixed number of operations instead.
    protected static final int NUM_THREADS = 25;
    protected static final int MAX_RANDOM_SLEEP_MILLIS = 1;
    protected static final int MAX_DEPTH = 3;
-   protected static final int MAX_OVERALL_NODES = 200;
+   protected static final int MAX_OVERALL_NODES = 2000;
    protected static final int WARMUP_LOOPS = 20000;
    protected static final boolean USE_SLEEP = false; // throttle generation a bit
 
+
    private List<Fqn> fqns = new ArrayList<Fqn>(MAX_OVERALL_NODES);
-   private Random r = new Random();
 
    Log log = LogFactory.getLog(ProfileTest.class);
 
    @Test(enabled = false)
    public void testLocalModePess() throws Exception
    {
-      cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
-      cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.MVCC);
-      cache.getConfiguration().setConcurrencyLevel(500);
-      cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+      Configuration cfg = cache.getConfiguration();
+      cfg.setCacheMode(Configuration.CacheMode.LOCAL);
+      cfg.setConcurrencyLevel(2000);
+      cfg.setLockAcquisitionTimeout(120000);
+      cfg.setLockParentForChildInsertRemove(true);
+      cfg.setIsolationLevel(IsolationLevel.READ_COMMITTED);
+      cfg.setNodeLockingScheme(Configuration.NodeLockingScheme.MVCC);
       runCompleteTest();
    }
 
@@ -167,8 +168,8 @@
       fqns.clear();
       for (int i = 0; i < MAX_OVERALL_NODES; i++)
       {
-         Fqn fqn = createRandomFqn(r);
-         while (fqns.contains(fqn)) fqn = createRandomFqn(r);
+         Fqn fqn = Generator.createRandomFqn(MAX_DEPTH);
+         while (fqns.contains(fqn)) fqn = Generator.createRandomFqn(MAX_DEPTH);
          if (i % 10 == 0)
          {
             log.warn("Generated " + i + " fqns");
@@ -180,19 +181,6 @@
       log.warn("Finished init() phase.  " + printDuration(duration));
    }
 
-   private Fqn createRandomFqn(Random r)
-   {
-      String s = "/";
-      int depth = r.nextInt(MAX_DEPTH);
-      for (int i = 0; i < depth; i++)
-      {
-         s += r.nextInt(Integer.MAX_VALUE) + "/";
-      }
-
-      return Fqn.fromString(s);
-   }
-
-
    protected void startup()
    {
       long startTime = System.currentTimeMillis();
@@ -205,7 +193,7 @@
    private void warmup() throws InterruptedException
    {
       long startTime = System.currentTimeMillis();
-      ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
+      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)
@@ -227,7 +215,7 @@
          {
             public void run()
             {
-               Fqn f = fqns.get(r.nextInt(MAX_OVERALL_NODES));
+               Fqn f = Generator.getRandomElement(fqns);
                cache.get(f, "");
                cache.put(f, "k", "v");
                cache.remove(f, "k");
@@ -235,8 +223,7 @@
          });
       }
 
-      exec.shutdown();
-      exec.awaitTermination(360, TimeUnit.SECONDS);
+      exec.stop();
 
       long duration = System.currentTimeMillis() - startTime;
       log.warn("Finished warmup.  " + printDuration(duration));
@@ -248,7 +235,7 @@
 
    private void doTest() throws Exception
    {
-      ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
+      TaskRunner exec = new TaskRunner(NUM_THREADS);
       log.warn("Starting test");
       int i;
       long print = NUM_OPERATIONS / 10;
@@ -281,12 +268,9 @@
       }
       log.warn("Finished generating runnables; awaiting executor completion");
       // wait for executors to complete!
-      exec.shutdown();
-      while (!exec.awaitTermination(((long) i), TimeUnit.SECONDS))
-      {
-         Thread.sleep(1);
-      }
-      ;  // wait up to 1 sec for each call?
+      exec.stop();
+
+      // wait up to 1 sec for each call?
       long elapsedTimeNanos = System.nanoTime() - stElapsed;
 
       log.warn("Finished test.  " + printDuration((long) toMillis(elapsedTimeNanos)));
@@ -322,14 +306,14 @@
 
       public void run()
       {
-         String k = getRandomString();
-         Fqn f = fqns.get(r.nextInt(MAX_OVERALL_NODES));
+         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, getRandomString());
+               cache.put(f, k, Generator.getRandomString());
                d = System.nanoTime() - st;
                break;
             case GET:
@@ -377,18 +361,6 @@
       }
    }
 
-   private String getRandomString()
-   {
-      StringBuilder sb = new StringBuilder();
-      int len = r.nextInt(10);
-
-      for (int i = 0; i < len; i++)
-      {
-         sb.append((char) (63 + r.nextInt(26)));
-      }
-      return sb.toString();
-   }
-
    protected String printDuration(long duration)
    {
       if (duration > 2000)

Added: core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/Generator.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/Generator.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/Generator.java	2008-12-16 14:19:02 UTC (rev 7334)
@@ -0,0 +1,36 @@
+package org.jboss.cache.profiling.testinternals;
+
+import org.jboss.cache.Fqn;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+public class Generator
+{
+   private static final Random r = new Random();
+
+   public static String getRandomString()
+   {
+      StringBuilder sb = new StringBuilder();
+      int len = r.nextInt(10);
+
+      for (int i = 0; i < len; i++)
+      {
+         sb.append((char) (63 + r.nextInt(26)));
+      }
+      return sb.toString();
+   }
+
+   public static <T> T getRandomElement(List<T> list)
+   {
+      return list.get(r.nextInt(list.size()));
+   }
+
+   public static Fqn createRandomFqn(int depth)
+   {
+      List<String> fqnElements = new ArrayList<String>(depth);
+      for (int i = 0; i < depth; i++) fqnElements.add(Integer.toHexString(r.nextInt(Integer.MAX_VALUE)));
+      return Fqn.fromList(fqnElements, true);
+   }
+}

Added: core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/TaskRunner.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/TaskRunner.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/testinternals/TaskRunner.java	2008-12-16 14:19:02 UTC (rev 7334)
@@ -0,0 +1,30 @@
+package org.jboss.cache.profiling.testinternals;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Essentially a delegate to an ExecutorService, but a special one that is only used by perf tests so it can be ignored
+ * when profiling.
+ */
+public class TaskRunner
+{
+   ExecutorService exec;
+
+   public TaskRunner(int numThreads)
+   {
+      this.exec = Executors.newFixedThreadPool(numThreads);
+   }
+
+   public void execute(Runnable r)
+   {
+      exec.execute(r);
+   }
+
+   public void stop() throws InterruptedException
+   {
+      exec.shutdown();
+      while (!exec.awaitTermination(30, TimeUnit.SECONDS)) Thread.sleep(30);
+   }
+}




More information about the jbosscache-commits mailing list