jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1213223 - in /jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk: concurrent/ConcurrentBlobTest.java concurrent/ConcurrentCacheTest.java concurrent/ConcurrentTest.java util/Concurrent.java
Date Mon, 12 Dec 2011 13:11:06 GMT
Author: thomasm
Date: Mon Dec 12 13:11:06 2011
New Revision: 1213223

URL: http://svn.apache.org/viewvc?rev=1213223&view=rev
Log:
Support profiling and benchmarks.

Modified:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java?rev=1213223&r1=1213222&r2=1213223&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java
Mon Dec 12 13:11:06 2011
@@ -45,7 +45,7 @@ public class ConcurrentBlobTest {
     @Test
     public void test() throws Exception {
         final AtomicInteger id = new AtomicInteger();
-        Concurrent.run(new Task() {
+        Concurrent.run("blob", new Task() {
             public void call() throws Exception {
                 int i = id.getAndIncrement();
                 ByteArrayOutputStream out = new ByteArrayOutputStream();

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java?rev=1213223&r1=1213222&r2=1213223&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java
Mon Dec 12 13:11:06 2011
@@ -34,7 +34,7 @@ public class ConcurrentCacheTest impleme
 
     @Test
     public void test() throws Exception {
-        Concurrent.run(new Task() {
+        Concurrent.run("cache", new Task() {
             public void call() throws Exception {
                 int k = value++ % 10;
                 Data v = cache.get(k);

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java?rev=1213223&r1=1213222&r2=1213223&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java
Mon Dec 12 13:11:06 2011
@@ -34,11 +34,8 @@ public class ConcurrentTest extends Mult
 
     @Test
     public void test() throws Exception {
-        if (url.startsWith("mem:")) {
-            return;
-        }
         final AtomicInteger id = new AtomicInteger();
-        Concurrent.run(new Task() {
+        Concurrent.run(url, new Task() {
             public void call() throws Exception {
                 long start = System.currentTimeMillis();
                 String rev = mk.getHeadRevision();

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java?rev=1213223&r1=1213222&r2=1213223&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java
Mon Dec 12 13:11:06 2011
@@ -18,33 +18,47 @@ package org.apache.jackrabbit.mk.util;
 
 import java.util.ArrayList;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
+import org.h2.util.Profiler;
 
 /**
  * A concurrency test tool.
  */
 public class Concurrent {
 
+    private static final boolean BENCHMARK = false;
+    private static final boolean PROFILE = false;
+
     /**
      * Run a task concurrently in 2 threads for 1 second.
      *
+     * @param message the message
      * @param task the task
      * @throws Exception the first exception that is thrown (if any)
      */
-    public static void run(Task task) throws Exception {
-        run(task, 2, 1000);
+    public static void run(String message, Task task) throws Exception {
+        run(message, task, 2, 1000);
     }
 
-    public static void run(final Task task, int threadCount, int millis) throws Exception
{
+    public static void run(String message, final Task task, int threadCount, int millis)
throws Exception {
         final AtomicBoolean stopped = new AtomicBoolean();
         final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
         ArrayList<Thread> threads = new ArrayList<Thread>();
+        final AtomicInteger counter = new AtomicInteger();
+        StopWatch timer = new StopWatch();
+        Profiler p = new Profiler();
+        if (PROFILE) {
+            p.interval = 1;
+            p.startCollecting();
+        }
         for (int i = 0; i < threadCount; i++) {
             Thread t = new Thread("Task " + i) {
                 public void run() {
                     while (!stopped.get()) {
                         try {
                             task.call();
+                            counter.incrementAndGet();
                         } catch (Error e) {
                             exception.set(e);
                             stopped.set(true);
@@ -55,8 +69,17 @@ public class Concurrent {
                     }
                 }
             };
-            t.start();
-            threads.add(t);
+            if (threadCount == 1) {
+                long stop = millis + System.currentTimeMillis();
+                while (System.currentTimeMillis() < stop) {
+                    task.call();
+                    counter.incrementAndGet();
+                }
+                millis = 0;
+            } else {
+                t.start();
+                threads.add(t);
+            }
         }
         Throwable e = null;
         while (e == null && millis > 0) {
@@ -74,6 +97,13 @@ public class Concurrent {
             }
             throw (Error) e;
         }
+        if (BENCHMARK) {
+            String t = timer.operationsPerSecond(counter.get());
+            System.out.println(message + ": " + t);
+        }
+        if (PROFILE) {
+            System.out.println(p.getTop(5));
+        }
     }
 
     public interface Task {



Mime
View raw message