diff --git a/src/main/java/teetime/util/StatisticsUtil.java b/src/main/java/teetime/util/StatisticsUtil.java index cd0e3d4340c5244b7e1be388127f27a5f09d00b2..5690d1ceabde332d354a1ec0147559fac2741a25 100644 --- a/src/main/java/teetime/util/StatisticsUtil.java +++ b/src/main/java/teetime/util/StatisticsUtil.java @@ -107,4 +107,5 @@ public class StatisticsUtil { } return quintileValues; } + } diff --git a/src/test/java/teetime/examples/throughput/MethodCallThoughputTimestampAnalysis16Test.java b/src/test/java/teetime/examples/throughput/MethodCallThoughputTimestampAnalysis16Test.java index 287345461d2c812e5ccf0c2a4c3186c2a8d9e423..9db9a7b353b529c21fa111329b033f768cd0a06a 100644 --- a/src/test/java/teetime/examples/throughput/MethodCallThoughputTimestampAnalysis16Test.java +++ b/src/test/java/teetime/examples/throughput/MethodCallThoughputTimestampAnalysis16Test.java @@ -44,12 +44,20 @@ public class MethodCallThoughputTimestampAnalysis16Test { } @Test - public void testWithManyObjects() { + public void testWithManyObjectsAnd1Thread() { + long durationWith1Thread = this.performAnalysis(1, -1); + this.performAnalysis(2, durationWith1Thread); + this.performAnalysis(4, durationWith1Thread); + // this.performAnalysis(8, stopWatch.getDurationInNs()); + } + + private long performAnalysis(final int numThreads, final long durationWith1Thread) { System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" + NUM_NOOP_FILTERS + "..."); final StopWatch stopWatch = new StopWatch(); final MethodCallThroughputAnalysis16 analysis = new MethodCallThroughputAnalysis16(); + analysis.setNumWorkerThreads(numThreads); analysis.setNumNoopFilters(NUM_NOOP_FILTERS); analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { @Override @@ -69,11 +77,18 @@ public class MethodCallThoughputTimestampAnalysis16Test { List<TimestampObject> timestampObjects = ListUtil.merge(analysis.getTimestampObjectsList()); StatisticsUtil.printStatistics(stopWatch.getDurationInNs(), timestampObjects); + + if (durationWith1Thread != -1) { + double speedup = (double) durationWith1Thread / stopWatch.getDurationInNs(); + System.out.println("Speedup (from 1 to " + numThreads + " threads): " + String.format("%.2f", speedup)); + } + + return stopWatch.getDurationInNs(); } public static void main(final String[] args) { MethodCallThoughputTimestampAnalysis16Test test = new MethodCallThoughputTimestampAnalysis16Test(); test.before(); - test.testWithManyObjects(); + test.testWithManyObjectsAnd1Thread(); } } diff --git a/src/test/java/teetime/examples/throughput/MethodCallThoughputTimestampAnalysis17Test.java b/src/test/java/teetime/examples/throughput/MethodCallThoughputTimestampAnalysis17Test.java index b5dababf03cb5260b4359662e3aa393d42eb4b8d..1fbf55115091bc723be40968babcb5ffa13aa3df 100644 --- a/src/test/java/teetime/examples/throughput/MethodCallThoughputTimestampAnalysis17Test.java +++ b/src/test/java/teetime/examples/throughput/MethodCallThoughputTimestampAnalysis17Test.java @@ -49,6 +49,8 @@ public class MethodCallThoughputTimestampAnalysis17Test { + NUM_NOOP_FILTERS + "..."); final StopWatch stopWatch = new StopWatch(); + // int count = 10; + // while (count-- > 0) { final MethodCallThroughputAnalysis17 analysis = new MethodCallThroughputAnalysis17(); analysis.setNumNoopFilters(NUM_NOOP_FILTERS); analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { @@ -70,5 +72,6 @@ public class MethodCallThoughputTimestampAnalysis17Test { List<TimestampObject> timestampObjects = ListUtil.merge(analysis.getTimestampObjectsList()); StatisticsUtil.printStatistics(stopWatch.getDurationInNs(), timestampObjects); + // } } } diff --git a/src/test/java/teetime/examples/throughput/methodcall/MethodCallThroughputAnalysis16.java b/src/test/java/teetime/examples/throughput/methodcall/MethodCallThroughputAnalysis16.java index e58e1b93f8bf0cc7778d5715a59adb275156752b..1070521e0a7d7a8bc15ecb23b099e57fc251521b 100644 --- a/src/test/java/teetime/examples/throughput/methodcall/MethodCallThroughputAnalysis16.java +++ b/src/test/java/teetime/examples/throughput/methodcall/MethodCallThroughputAnalysis16.java @@ -50,15 +50,17 @@ public class MethodCallThroughputAnalysis16 extends Analysis { private Thread[] workerThreads; + private int numWorkerThreads; + @Override public void init() { super.init(); Pipeline<Void, TimestampObject> producerPipeline = this.buildProducerPipeline(this.numInputObjects, this.inputObjectCreator); this.producerThread = new Thread(new RunnableStage(producerPipeline)); - int numWorkerThreads = Math.min(NUM_WORKER_THREADS, 1); // only for testing purpose + this.numWorkerThreads = Math.min(NUM_WORKER_THREADS, this.numWorkerThreads); - this.workerThreads = new Thread[numWorkerThreads]; + this.workerThreads = new Thread[this.numWorkerThreads]; for (int i = 0; i < this.workerThreads.length; i++) { List<TimestampObject> resultList = new ArrayList<TimestampObject>(this.numInputObjects); this.timestampObjectsList.add(resultList); @@ -67,14 +69,14 @@ public class MethodCallThroughputAnalysis16 extends Analysis { this.workerThreads[i] = new Thread(workerRunnable); } - this.producerThread.start(); - - try { - this.producerThread.join(); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } + // this.producerThread.start(); + // + // try { + // this.producerThread.join(); + // } catch (InterruptedException e1) { + // // TODO Auto-generated catch block + // e1.printStackTrace(); + // } } private Pipeline<Void, TimestampObject> buildProducerPipeline(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { @@ -131,10 +133,19 @@ public class MethodCallThroughputAnalysis16 extends Analysis { public void start() { super.start(); + this.producerThread.start(); + for (Thread workerThread : this.workerThreads) { workerThread.start(); } + try { + this.producerThread.join(); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { for (Thread workerThread : this.workerThreads) { workerThread.join(); @@ -162,4 +173,12 @@ public class MethodCallThroughputAnalysis16 extends Analysis { return this.timestampObjectsList; } + public int getNumWorkerThreads() { + return this.numWorkerThreads; + } + + public void setNumWorkerThreads(final int numWorkerThreads) { + this.numWorkerThreads = numWorkerThreads; + } + } diff --git a/src/test/java/teetime/examples/throughput/methodcall/MethodCallThroughputAnalysis17.java b/src/test/java/teetime/examples/throughput/methodcall/MethodCallThroughputAnalysis17.java index 81da2950b41abb270ca39cff89b6388f5c470c4c..87f74b22f9919ed7dd28f5438d557f39250259ba 100644 --- a/src/test/java/teetime/examples/throughput/methodcall/MethodCallThroughputAnalysis17.java +++ b/src/test/java/teetime/examples/throughput/methodcall/MethodCallThroughputAnalysis17.java @@ -31,7 +31,6 @@ import teetime.examples.throughput.methodcall.stage.Sink; import teetime.examples.throughput.methodcall.stage.StartTimestampFilter; import teetime.examples.throughput.methodcall.stage.StopTimestampFilter; import teetime.framework.core.Analysis; -import teetime.util.StopWatch; /** * @author Christian Wulf @@ -90,12 +89,6 @@ public class MethodCallThroughputAnalysis17 extends Analysis { // this.producerThread.run(); new RunnableStage(producerPipeline).run(); - // Pipeline<Void, TimestampObject> stage = producerPipeline; - // stage.onStart(); - // do { - // stage.executeWithPorts(); - // } while (stage.isReschedulable()); - // try { // this.producerThread.join(); // } catch (InterruptedException e1) { @@ -103,13 +96,6 @@ public class MethodCallThroughputAnalysis17 extends Analysis { // e1.printStackTrace(); // } - // try { - // Thread.sleep(1000); - // } catch (InterruptedException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - super.init(); } @@ -186,11 +172,8 @@ public class MethodCallThroughputAnalysis17 extends Analysis { return new RunnableStage(pipeline); } - private final StopWatch stopWatch = new StopWatch(); - @Override public void start() { - this.stopWatch.start(); super.start(); for (Thread workerThread : this.workerThreads) { @@ -205,8 +188,6 @@ public class MethodCallThroughputAnalysis17 extends Analysis { // TODO Auto-generated catch block e.printStackTrace(); } - this.stopWatch.end(); - System.out.println("dur: " + this.stopWatch.getDurationInNs() + " ns"); } public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { diff --git a/src/test/java/teetime/examples/throughput/methodcall/stage/Distributor.java b/src/test/java/teetime/examples/throughput/methodcall/stage/Distributor.java index 322159b5fe452478dc7ad6ef359a1e20389f9940..825055dffc6342ea6293be18c870a824d47b1b96 100644 --- a/src/test/java/teetime/examples/throughput/methodcall/stage/Distributor.java +++ b/src/test/java/teetime/examples/throughput/methodcall/stage/Distributor.java @@ -9,6 +9,8 @@ import teetime.util.list.CommittableQueue; public final class Distributor<T> extends AbstractStage<T, T> { + // TODO do not inherit from AbstractStage since it provides the default output port that is unnecessary for the distributor + private final List<OutputPort<T>> outputPortList = new ArrayList<OutputPort<T>>(); private OutputPort<T>[] outputPorts;