You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2014/04/10 07:27:23 UTC
svn commit: r1586218 - in /jackrabbit/oak/trunk/oak-run: README.md
src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
Author: chetanm
Date: Thu Apr 10 05:27:23 2014
New Revision: 1586218
URL: http://svn.apache.org/r1586218
Log:
OAK-1716 - Enable passing of a execution context to runTest in multi threaded runs
Exposed a protected method `prepareThreadExecutionContext`
which subclasses can override to return a context instance which would
be used by that thread of execution
Modified:
jackrabbit/oak/trunk/oak-run/README.md
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
Modified: jackrabbit/oak/trunk/oak-run/README.md
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/README.md?rev=1586218&r1=1586217&r2=1586218&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/README.md (original)
+++ jackrabbit/oak/trunk/oak-run/README.md Thu Apr 10 05:27:23 2014
@@ -150,7 +150,13 @@ controls the bundle cache size in Jackra
cache size in MongoMK and the default H2 MK, and the segment cache
size in SegmentMK.
-The `--concurrency` levels can be specified as comma separated list of values, eg: `--concurrency 1,4,8`, which will execute the same test with the number of respective threads. Note that the `beforeSuite()` and `afterSuite()` are executed before and after the concurrency loop. eg. in the example above, the execution order is: `beforeSuite()`, 1x `runTest()`, 4x `runTest()`, 8x `runTest()`, `afterSuite()`. Tests that create their own background threads, should be executed with `--concurrency 1` which is the default.
+The `--concurrency` levels can be specified as comma separated list of values,
+eg: `--concurrency 1,4,8`, which will execute the same test with the number of
+respective threads. Note that the `beforeSuite()` and `afterSuite()` are executed
+before and after the concurrency loop. eg. in the example above, the execution order
+is: `beforeSuite()`, 1x `runTest()`, 4x `runTest()`, 8x `runTest()`, `afterSuite()`.
+Tests that create their own background threads, should be executed with
+`--concurrency 1` which is the default.
You can use extra JVM options like `-Xmx` settings to better control the
benchmark environment. It's also possible to attach the JVM to a
Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java?rev=1586218&r1=1586217&r2=1586218&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java Thu Apr 10 05:27:23 2014
@@ -39,7 +39,7 @@ import org.apache.jackrabbit.oak.fixture
/**
* Abstract base class for individual performance benchmarks.
*/
-abstract class AbstractTest extends Benchmark implements CSVResultGenerator {
+abstract class AbstractTest<T> extends Benchmark implements CSVResultGenerator {
/**
* A random string to guarantee concurrently running tests don't overwrite
@@ -208,14 +208,17 @@ abstract class AbstractTest extends Benc
@Override
public void run() {
+ T context = null;
try {
+ context = prepareThreadExecutionContext();
while (running) {
- statistics.addValue(execute());
+ statistics.addValue(execute(context));
}
} catch (Exception e) {
e.printStackTrace();
+ } finally {
+ disposeThreadExecutionContext(context);
}
-
}
}
@@ -278,6 +281,23 @@ abstract class AbstractTest extends Benc
afterTest();
}
}
+
+ private long execute(T executionContext) throws Exception {
+ if(executionContext == null){
+ return execute();
+ }
+
+ beforeTest(executionContext);
+ try {
+ long start = System.currentTimeMillis();
+ // System.out.println("execute " + this);
+ runTest(executionContext);
+ return System.currentTimeMillis() - start;
+ } finally {
+ afterTest(executionContext);
+ }
+ }
+
/**
* Cleans up after this performance benchmark.
*
@@ -334,6 +354,36 @@ abstract class AbstractTest extends Benc
protected void afterSuite() throws Exception {
}
+ /**
+ * Invoked before the thread starts. If the test later requires
+ * some thread local context e.g. JCR session per thread then sub
+ * classes can return a context instance. That instance would be
+ * passed as part of runTest call
+ *
+ * @return context instance to be used for runTest call for the
+ * current thread
+ */
+ protected T prepareThreadExecutionContext() {
+ return null;
+ }
+
+ protected void disposeThreadExecutionContext(T context) {
+
+ }
+
+ protected void afterTest(T executionContext) {
+
+ }
+
+ protected void runTest(T executionContext) throws Exception {
+ throw new IllegalStateException("If thread execution context is used then subclass must " +
+ "override this method");
+ }
+
+ protected void beforeTest(T executionContext) {
+
+ }
+
protected void failOnRepositoryVersions(String... versions)
throws RepositoryException {
String repositoryVersion =