Skip to content
Snippets Groups Projects
Commit 54cc0302 authored by Christian Wulf's avatar Christian Wulf
Browse files

added more performance tests

parent f8d0b388
Branches
Tags
No related merge requests found
Showing
with 456 additions and 22 deletions
...@@ -22,7 +22,7 @@ import java.util.concurrent.Callable; ...@@ -22,7 +22,7 @@ import java.util.concurrent.Callable;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import teetime.examples.throughput.methodcall.MethodCallThroughputAnalysis; import teetime.examples.throughput.methodcall.MethodCallThroughputAnalysis1;
import teetime.util.StatisticsUtil; import teetime.util.StatisticsUtil;
import teetime.util.StopWatch; import teetime.util.StopWatch;
...@@ -33,7 +33,7 @@ import kieker.common.logging.LogFactory; ...@@ -33,7 +33,7 @@ import kieker.common.logging.LogFactory;
* *
* @since 1.10 * @since 1.10
*/ */
public class MethodCallThoughputTimestampAnalysisTest { public class MethodCallThoughputTimestampAnalysis1Test {
private static final int NUM_OBJECTS_TO_CREATE = 100000; private static final int NUM_OBJECTS_TO_CREATE = 100000;
private static final int NUM_NOOP_FILTERS = 800; private static final int NUM_NOOP_FILTERS = 800;
...@@ -53,7 +53,7 @@ public class MethodCallThoughputTimestampAnalysisTest { ...@@ -53,7 +53,7 @@ public class MethodCallThoughputTimestampAnalysisTest {
final StopWatch stopWatch = new StopWatch(); final StopWatch stopWatch = new StopWatch();
final List<TimestampObject> timestampObjects = new ArrayList<TimestampObject>(NUM_OBJECTS_TO_CREATE); final List<TimestampObject> timestampObjects = new ArrayList<TimestampObject>(NUM_OBJECTS_TO_CREATE);
final MethodCallThroughputAnalysis analysis = new MethodCallThroughputAnalysis(); final MethodCallThroughputAnalysis1 analysis = new MethodCallThroughputAnalysis1();
analysis.setNumNoopFilters(NUM_NOOP_FILTERS); analysis.setNumNoopFilters(NUM_NOOP_FILTERS);
analysis.setTimestampObjects(timestampObjects); analysis.setTimestampObjects(timestampObjects);
analysis.setInput(NUM_OBJECTS_TO_CREATE, new Callable<TimestampObject>() { analysis.setInput(NUM_OBJECTS_TO_CREATE, new Callable<TimestampObject>() {
......
/***************************************************************************
* Copyright 2014 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package teetime.examples.throughput;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import org.junit.Before;
import org.junit.Test;
import teetime.examples.throughput.methodcall.MethodCallThroughputAnalysis3;
import teetime.util.StatisticsUtil;
import teetime.util.StopWatch;
import kieker.common.logging.LogFactory;
/**
* @author Christian Wulf
*
* @since 1.10
*/
public class MethodCallThoughputTimestampAnalysis3Test {
private static final int NUM_OBJECTS_TO_CREATE = 100000;
private static final int NUM_NOOP_FILTERS = 800;
@Before
public void before() {
System.setProperty(LogFactory.CUSTOM_LOGGER_JVM, "NONE");
}
// 500 times faster than our new framework
// TODO check why
@Test
public void testWithManyObjects() {
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 List<TimestampObject> timestampObjects = new ArrayList<TimestampObject>(NUM_OBJECTS_TO_CREATE);
final MethodCallThroughputAnalysis3 analysis = new MethodCallThroughputAnalysis3();
analysis.setNumNoopFilters(NUM_NOOP_FILTERS);
analysis.setTimestampObjects(timestampObjects);
analysis.setInput(NUM_OBJECTS_TO_CREATE, new Callable<TimestampObject>() {
@Override
public TimestampObject call() throws Exception {
return new TimestampObject();
}
});
analysis.init();
stopWatch.start();
try {
analysis.start();
} finally {
stopWatch.end();
}
StatisticsUtil.printStatistics(stopWatch.getDurationInNs(), timestampObjects);
}
}
/***************************************************************************
* Copyright 2014 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package teetime.examples.throughput;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import org.junit.Before;
import org.junit.Test;
import teetime.examples.throughput.methodcall.MethodCallThroughputAnalysis4;
import teetime.util.StatisticsUtil;
import teetime.util.StopWatch;
import kieker.common.logging.LogFactory;
/**
* @author Christian Wulf
*
* @since 1.10
*/
public class MethodCallThoughputTimestampAnalysis4Test {
private static final int NUM_OBJECTS_TO_CREATE = 100000;
private static final int NUM_NOOP_FILTERS = 800;
@Before
public void before() {
System.setProperty(LogFactory.CUSTOM_LOGGER_JVM, "NONE");
}
// 500 times faster than our new framework
// TODO check why
@Test
public void testWithManyObjects() {
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 List<TimestampObject> timestampObjects = new ArrayList<TimestampObject>(NUM_OBJECTS_TO_CREATE);
final MethodCallThroughputAnalysis4 analysis = new MethodCallThroughputAnalysis4();
analysis.setNumNoopFilters(NUM_NOOP_FILTERS);
analysis.setTimestampObjects(timestampObjects);
analysis.setInput(NUM_OBJECTS_TO_CREATE, new Callable<TimestampObject>() {
@Override
public TimestampObject call() throws Exception {
return new TimestampObject();
}
});
analysis.init();
stopWatch.start();
try {
analysis.start();
} finally {
stopWatch.end();
}
StatisticsUtil.printStatistics(stopWatch.getDurationInNs(), timestampObjects);
}
}
...@@ -24,9 +24,10 @@ import teetime.util.list.CommittableQueue; ...@@ -24,9 +24,10 @@ import teetime.util.list.CommittableQueue;
* *
* @since 1.10 * @since 1.10
*/ */
public class CollectorSink<T> extends ConsumerStage<T, Void> { public class CollectorSink<T> extends ConsumerStage<T, Object> {
private static final int THRESHOLD = 10000; private static final int THRESHOLD = 10000;
private static final Object continueSignal = new Object();
private final List<T> elements; private final List<T> elements;
...@@ -37,11 +38,13 @@ public class CollectorSink<T> extends ConsumerStage<T, Void> { ...@@ -37,11 +38,13 @@ public class CollectorSink<T> extends ConsumerStage<T, Void> {
this.elements = list; this.elements = list;
} }
public void execute(final T element) { @Override
this.elements.add(element); public Object execute(final Object element) {
this.elements.add((T) element);
if ((this.elements.size() % THRESHOLD) == 0) { if ((this.elements.size() % THRESHOLD) == 0) {
System.out.println("size: " + this.elements.size()); System.out.println("size: " + this.elements.size());
} }
return continueSignal;
} }
// @Override // @Override
......
...@@ -26,7 +26,7 @@ import teetime.framework.core.Analysis; ...@@ -26,7 +26,7 @@ import teetime.framework.core.Analysis;
* *
* @since 1.10 * @since 1.10
*/ */
public class MethodCallThroughputAnalysis extends Analysis { public class MethodCallThroughputAnalysis1 extends Analysis {
private long numInputObjects; private long numInputObjects;
private Callable<TimestampObject> inputObjectCreator; private Callable<TimestampObject> inputObjectCreator;
...@@ -60,7 +60,7 @@ public class MethodCallThroughputAnalysis extends Analysis { ...@@ -60,7 +60,7 @@ public class MethodCallThroughputAnalysis extends Analysis {
@Override @Override
public void run() { public void run() {
while (true) { while (true) {
TimestampObject object = objectProducer.execute(); TimestampObject object = objectProducer.execute(null);
if (object == null) { if (object == null) {
return; return;
} }
......
...@@ -58,13 +58,15 @@ public class MethodCallThroughputAnalysis2 extends Analysis { ...@@ -58,13 +58,15 @@ public class MethodCallThroughputAnalysis2 extends Analysis {
final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter();
final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects); final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects);
final Pipeline<Void, Void> pipeline = new Pipeline<Void, Void>(); final Pipeline<Void, Object> pipeline = new Pipeline<Void, Object>();
pipeline.setFirstStage(objectProducer); pipeline.setFirstStage(objectProducer);
pipeline.addIntermediateStage(startTimestampFilter); pipeline.addIntermediateStage(startTimestampFilter);
pipeline.addIntermediateStages(noopFilters); pipeline.addIntermediateStages(noopFilters);
pipeline.addIntermediateStage(stopTimestampFilter); pipeline.addIntermediateStage(stopTimestampFilter);
pipeline.setLastStage(collectorSink); pipeline.setLastStage(collectorSink);
pipeline.onStart();
// pipeline.getInputPort().pipe = new Pipe<Void>(); // pipeline.getInputPort().pipe = new Pipe<Void>();
// pipeline.getInputPort().pipe.add(new Object()); // pipeline.getInputPort().pipe.add(new Object());
...@@ -73,10 +75,8 @@ public class MethodCallThroughputAnalysis2 extends Analysis { ...@@ -73,10 +75,8 @@ public class MethodCallThroughputAnalysis2 extends Analysis {
final Runnable runnable = new Runnable() { final Runnable runnable = new Runnable() {
@Override @Override
public void run() { public void run() {
pipeline.onStart();
CommittableQueue<Void> inputQueue = new CommittableResizableArrayQueue<Void>(null, 0); CommittableQueue<Void> inputQueue = new CommittableResizableArrayQueue<Void>(null, 0);
CommittableQueue<Void> outputQueue = new CommittableResizableArrayQueue<Void>(null, 0); CommittableQueue<Object> outputQueue = new CommittableResizableArrayQueue<Object>(null, 0);
while (pipeline.getSchedulingInformation().isActive()) { while (pipeline.getSchedulingInformation().isActive()) {
outputQueue = pipeline.execute2(inputQueue); outputQueue = pipeline.execute2(inputQueue);
......
/***************************************************************************
* Copyright 2014 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package teetime.examples.throughput.methodcall;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import teetime.examples.throughput.TimestampObject;
import teetime.framework.core.Analysis;
/**
* @author Christian Wulf
*
* @since 1.10
*/
public class MethodCallThroughputAnalysis3 extends Analysis {
public abstract class WrappingPipeline {
public abstract boolean execute();
}
private long numInputObjects;
private Callable<TimestampObject> inputObjectCreator;
private int numNoopFilters;
private List<TimestampObject> timestampObjects;
private Runnable runnable;
@Override
public void init() {
super.init();
this.runnable = this.buildPipeline();
}
/**
* @param numNoopFilters
* @since 1.10
*/
private Runnable buildPipeline() {
@SuppressWarnings("unchecked")
final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters];
// create stages
final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(this.numInputObjects, this.inputObjectCreator);
final StartTimestampFilter startTimestampFilter = new StartTimestampFilter();
for (int i = 0; i < noopFilters.length; i++) {
noopFilters[i] = new NoopFilter<TimestampObject>();
}
final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter();
final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects);
final List<Stage> stageList = new ArrayList<Stage>();
stageList.add(objectProducer);
stageList.add(startTimestampFilter);
stageList.addAll(Arrays.asList(noopFilters));
stageList.add(stopTimestampFilter);
stageList.add(collectorSink);
// using an array decreases the performance from 60ms to 200ms (by 3x)
final Stage[] stages = stageList.toArray(new Stage[0]);
final WrappingPipeline pipeline = new WrappingPipeline() {
@Override
public boolean execute() {
// extracting the null-check does NOT improve performance
Stage stage = stages[0];
Object element = stage.execute(null);
if (element == null) {
return false;
}
for (int i = 1; i < stages.length; i++) {
stage = stages[i];
element = stage.execute(element);
}
return true;
}
};
final Runnable runnable = new Runnable() {
@Override
public void run() {
boolean success;
do {
success = pipeline.execute();
} while (success);
}
};
return runnable;
}
@Override
public void start() {
super.start();
this.runnable.run();
}
public void setInput(final int numInputObjects, final Callable<TimestampObject> inputObjectCreator) {
this.numInputObjects = numInputObjects;
this.inputObjectCreator = inputObjectCreator;
}
public int getNumNoopFilters() {
return this.numNoopFilters;
}
public void setNumNoopFilters(final int numNoopFilters) {
this.numNoopFilters = numNoopFilters;
}
public List<TimestampObject> getTimestampObjects() {
return this.timestampObjects;
}
public void setTimestampObjects(final List<TimestampObject> timestampObjects) {
this.timestampObjects = timestampObjects;
}
}
/***************************************************************************
* Copyright 2014 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package teetime.examples.throughput.methodcall;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import teetime.examples.throughput.TimestampObject;
import teetime.framework.core.Analysis;
/**
* @author Christian Wulf
*
* @since 1.10
*/
public class MethodCallThroughputAnalysis4 extends Analysis {
public abstract class WrappingPipeline {
public abstract boolean execute();
}
private long numInputObjects;
private Callable<TimestampObject> inputObjectCreator;
private int numNoopFilters;
private List<TimestampObject> timestampObjects;
private Runnable runnable;
@Override
public void init() {
super.init();
this.runnable = this.buildPipeline();
}
/**
* @param numNoopFilters
* @since 1.10
*/
private Runnable buildPipeline() {
@SuppressWarnings("unchecked")
final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters];
// create stages
final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(this.numInputObjects, this.inputObjectCreator);
final StartTimestampFilter startTimestampFilter = new StartTimestampFilter();
for (int i = 0; i < noopFilters.length; i++) {
noopFilters[i] = new NoopFilter<TimestampObject>();
}
final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter();
final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects);
List<Stage> stages = new ArrayList<Stage>();
stages.add(objectProducer);
stages.add(startTimestampFilter);
stages.addAll(Arrays.asList(noopFilters));
stages.add(stopTimestampFilter);
stages.add(collectorSink);
final WrappingPipeline pipeline = new WrappingPipeline() {
@Override
public boolean execute() {
TimestampObject object = objectProducer.execute(null);
if (object == null) {
return false;
}
object = startTimestampFilter.execute(object);
for (final NoopFilter<TimestampObject> noopFilter : noopFilters) {
object = noopFilter.execute(object);
}
object = stopTimestampFilter.execute(object);
collectorSink.execute(object);
return true;
}
};
final Runnable runnable = new Runnable() {
@Override
public void run() {
boolean success;
do {
success = pipeline.execute();
} while (success);
}
};
return runnable;
}
@Override
public void start() {
super.start();
this.runnable.run();
}
public void setInput(final int numInputObjects, final Callable<TimestampObject> inputObjectCreator) {
this.numInputObjects = numInputObjects;
this.inputObjectCreator = inputObjectCreator;
}
public int getNumNoopFilters() {
return this.numNoopFilters;
}
public void setNumNoopFilters(final int numNoopFilters) {
this.numNoopFilters = numNoopFilters;
}
public List<TimestampObject> getTimestampObjects() {
return this.timestampObjects;
}
public void setTimestampObjects(final List<TimestampObject> timestampObjects) {
this.timestampObjects = timestampObjects;
}
}
...@@ -24,8 +24,9 @@ import teetime.util.list.CommittableQueue; ...@@ -24,8 +24,9 @@ import teetime.util.list.CommittableQueue;
*/ */
public class NoopFilter<T> extends ConsumerStage<T, T> { public class NoopFilter<T> extends ConsumerStage<T, T> {
public T execute(final T obj) { @Override
return obj; public T execute(final Object obj) {
return (T) obj;
} }
// @Override // @Override
......
...@@ -37,7 +37,8 @@ public class ObjectProducer<T> extends ProducerStage<Void, T> { ...@@ -37,7 +37,8 @@ public class ObjectProducer<T> extends ProducerStage<Void, T> {
this.inputObjectCreator = inputObjectCreator; this.inputObjectCreator = inputObjectCreator;
} }
public T execute() { @Override
public T execute(final Object element) {
if (this.numInputObjects == 0) { if (this.numInputObjects == 0) {
return null; return null;
} }
......
...@@ -141,6 +141,11 @@ public class Pipeline<I, O> implements Stage<I, O>, OnDisableListener { ...@@ -141,6 +141,11 @@ public class Pipeline<I, O> implements Stage<I, O>, OnDisableListener {
this.listener = listener; this.listener = listener;
} }
@Override
public O execute(final Object element) {
throw new IllegalStateException();
}
// @Override // @Override
// public OutputPort getOutputPort() { // public OutputPort getOutputPort() {
// return this.lastStage.getOutputPort(); // return this.lastStage.getOutputPort();
......
...@@ -6,6 +6,8 @@ public interface Stage<I, O> { ...@@ -6,6 +6,8 @@ public interface Stage<I, O> {
public static final Object END_SIGNAL = new Object(); public static final Object END_SIGNAL = new Object();
O execute(Object element);
// CommittableQueue<O> execute2(); // CommittableQueue<O> execute2();
// InputPort<I> getInputPort(); // InputPort<I> getInputPort();
......
...@@ -25,9 +25,11 @@ import teetime.util.list.CommittableQueue; ...@@ -25,9 +25,11 @@ import teetime.util.list.CommittableQueue;
*/ */
public class StartTimestampFilter extends ConsumerStage<TimestampObject, TimestampObject> { public class StartTimestampFilter extends ConsumerStage<TimestampObject, TimestampObject> {
public TimestampObject execute(final TimestampObject obj) { @Override
obj.setStartTimestamp(System.nanoTime()); public TimestampObject execute(final Object obj) {
return obj; TimestampObject timestampObject = (TimestampObject) obj;
timestampObject.setStartTimestamp(System.nanoTime());
return timestampObject;
} }
// @Override // @Override
......
...@@ -25,9 +25,11 @@ import teetime.util.list.CommittableQueue; ...@@ -25,9 +25,11 @@ import teetime.util.list.CommittableQueue;
*/ */
public class StopTimestampFilter extends ConsumerStage<TimestampObject, TimestampObject> { public class StopTimestampFilter extends ConsumerStage<TimestampObject, TimestampObject> {
public TimestampObject execute(final TimestampObject obj) { @Override
obj.setStopTimestamp(System.nanoTime()); public TimestampObject execute(final Object obj) {
return obj; TimestampObject timestampObject = (TimestampObject) obj;
timestampObject.setStopTimestamp(System.nanoTime());
return timestampObject;
} }
// @Override // @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment