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

added more performance tests

parent 3645dd80
No related branches found
No related tags found
No related merge requests found
Showing
with 456 additions and 22 deletions
......@@ -22,7 +22,7 @@ import java.util.concurrent.Callable;
import org.junit.Before;
import org.junit.Test;
import teetime.examples.throughput.methodcall.MethodCallThroughputAnalysis;
import teetime.examples.throughput.methodcall.MethodCallThroughputAnalysis1;
import teetime.util.StatisticsUtil;
import teetime.util.StopWatch;
......@@ -33,7 +33,7 @@ import kieker.common.logging.LogFactory;
*
* @since 1.10
*/
public class MethodCallThoughputTimestampAnalysisTest {
public class MethodCallThoughputTimestampAnalysis1Test {
private static final int NUM_OBJECTS_TO_CREATE = 100000;
private static final int NUM_NOOP_FILTERS = 800;
......@@ -53,7 +53,7 @@ public class MethodCallThoughputTimestampAnalysisTest {
final StopWatch stopWatch = new StopWatch();
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.setTimestampObjects(timestampObjects);
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;
*
* @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 Object continueSignal = new Object();
private final List<T> elements;
......@@ -37,11 +38,13 @@ public class CollectorSink<T> extends ConsumerStage<T, Void> {
this.elements = list;
}
public void execute(final T element) {
this.elements.add(element);
@Override
public Object execute(final Object element) {
this.elements.add((T) element);
if ((this.elements.size() % THRESHOLD) == 0) {
System.out.println("size: " + this.elements.size());
}
return continueSignal;
}
// @Override
......
......@@ -23,10 +23,10 @@ import teetime.framework.core.Analysis;
/**
* @author Christian Wulf
*
*
* @since 1.10
*/
public class MethodCallThroughputAnalysis extends Analysis {
public class MethodCallThroughputAnalysis1 extends Analysis {
private long numInputObjects;
private Callable<TimestampObject> inputObjectCreator;
......@@ -60,7 +60,7 @@ public class MethodCallThroughputAnalysis extends Analysis {
@Override
public void run() {
while (true) {
TimestampObject object = objectProducer.execute();
TimestampObject object = objectProducer.execute(null);
if (object == null) {
return;
}
......
......@@ -58,13 +58,15 @@ public class MethodCallThroughputAnalysis2 extends Analysis {
final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter();
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.addIntermediateStage(startTimestampFilter);
pipeline.addIntermediateStages(noopFilters);
pipeline.addIntermediateStage(stopTimestampFilter);
pipeline.setLastStage(collectorSink);
pipeline.onStart();
// pipeline.getInputPort().pipe = new Pipe<Void>();
// pipeline.getInputPort().pipe.add(new Object());
......@@ -73,10 +75,8 @@ public class MethodCallThroughputAnalysis2 extends Analysis {
final Runnable runnable = new Runnable() {
@Override
public void run() {
pipeline.onStart();
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()) {
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;
*/
public class NoopFilter<T> extends ConsumerStage<T, T> {
public T execute(final T obj) {
return obj;
@Override
public T execute(final Object obj) {
return (T) obj;
}
// @Override
......
......@@ -37,7 +37,8 @@ public class ObjectProducer<T> extends ProducerStage<Void, T> {
this.inputObjectCreator = inputObjectCreator;
}
public T execute() {
@Override
public T execute(final Object element) {
if (this.numInputObjects == 0) {
return null;
}
......
......@@ -141,6 +141,11 @@ public class Pipeline<I, O> implements Stage<I, O>, OnDisableListener {
this.listener = listener;
}
@Override
public O execute(final Object element) {
throw new IllegalStateException();
}
// @Override
// public OutputPort getOutputPort() {
// return this.lastStage.getOutputPort();
......
......@@ -6,6 +6,8 @@ public interface Stage<I, O> {
public static final Object END_SIGNAL = new Object();
O execute(Object element);
// CommittableQueue<O> execute2();
// InputPort<I> getInputPort();
......
......@@ -25,9 +25,11 @@ import teetime.util.list.CommittableQueue;
*/
public class StartTimestampFilter extends ConsumerStage<TimestampObject, TimestampObject> {
public TimestampObject execute(final TimestampObject obj) {
obj.setStartTimestamp(System.nanoTime());
return obj;
@Override
public TimestampObject execute(final Object obj) {
TimestampObject timestampObject = (TimestampObject) obj;
timestampObject.setStartTimestamp(System.nanoTime());
return timestampObject;
}
// @Override
......
......@@ -25,9 +25,11 @@ import teetime.util.list.CommittableQueue;
*/
public class StopTimestampFilter extends ConsumerStage<TimestampObject, TimestampObject> {
public TimestampObject execute(final TimestampObject obj) {
obj.setStopTimestamp(System.nanoTime());
return obj;
@Override
public TimestampObject execute(final Object obj) {
TimestampObject timestampObject = (TimestampObject) obj;
timestampObject.setStopTimestamp(System.nanoTime());
return timestampObject;
}
// @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment