diff --git a/src/main/java/teetime/framework/concurrent/WorkerThread.java b/src/main/java/teetime/framework/concurrent/WorkerThread.java index aebf09dc3113a3867de890d18864598eff64db63..fe1623646ffb3e60ddc5930ca25eda20610569f2 100644 --- a/src/main/java/teetime/framework/concurrent/WorkerThread.java +++ b/src/main/java/teetime/framework/concurrent/WorkerThread.java @@ -70,26 +70,33 @@ public class WorkerThread extends Thread { iterations++; this.iterationStopWatch.start(); +// beforeStageExecutionStopWatch.start(); + final IStage stage = this.stageScheduler.get(); +// beforeStageExecutionStopWatch.end(); + this.startStageExecution(stage); stageExecutionStopWatch.start(); // expensive: takes 1/3 of overall time final boolean executedSuccessfully = stage.execute(); stageExecutionStopWatch.end(); this.finishStageExecution(stage, executedSuccessfully); - afterStageExecutionStopWatch.start(); +// afterStageExecutionStopWatch.start(); if (this.shouldTerminate) { this.executeTerminationPolicy(stage, executedSuccessfully); } this.stageScheduler.determineNextStage(stage, executedSuccessfully); - afterStageExecutionStopWatch.end(); +// afterStageExecutionStopWatch.end(); this.iterationStopWatch.end(); -// final long schedulingOverhead = this.iterationStopWatch.getDurationInNs() - stageExecutionStopWatch.getDurationInNs(); - final long schedulingOverhead = afterStageExecutionStopWatch.getDurationInNs(); + final long schedulingOverhead = this.iterationStopWatch.getDurationInNs() - stageExecutionStopWatch.getDurationInNs(); //3198 ms +// final long schedulingOverhead = this.iterationStopWatch.getDurationInNs(); //3656 ms +// final long schedulingOverhead = beforeStageExecutionStopWatch.getDurationInNs(); //417 ms +// final long schedulingOverhead = stageExecutionStopWatch.getDurationInNs(); //503 ms +// final long schedulingOverhead = afterStageExecutionStopWatch.getDurationInNs(); //1214 ms schedulingOverheadInNs += schedulingOverhead; if ((iterations % 10000) == 0) { this.schedulingOverheadsInNs.add(schedulingOverheadInNs); diff --git a/src/test/java/kieker/analysis/examples/throughput/ThroughputAnalysisTest.java b/src/test/java/kieker/analysis/examples/throughput/ThroughputAnalysisTest.java new file mode 100644 index 0000000000000000000000000000000000000000..fa53ff4af90a650742f439b7bd3197e3ec521710 --- /dev/null +++ b/src/test/java/kieker/analysis/examples/throughput/ThroughputAnalysisTest.java @@ -0,0 +1,81 @@ +/*************************************************************************** + * 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 kieker.analysis.examples.throughput; + +import java.util.concurrent.Callable; + +import kieker.analysis.examples.ThroughputAnalysis; +import kieker.analysis.exception.AnalysisConfigurationException; +import kieker.common.logging.LogFactory; + +import org.junit.Before; +import org.junit.Test; + +import teetime.util.StopWatch; + +/** + * @author Nils Christian Ehmke + * + * @since 1.10 + */ +public class ThroughputAnalysisTest { + + private static final int numRuns = 1000; + + @Before + public void before() { + System.setProperty(LogFactory.CUSTOM_LOGGER_JVM, "NONE"); + } + + @Test + public void testWithMultipleRuns() throws IllegalStateException, AnalysisConfigurationException { + final StopWatch stopWatch = new StopWatch(); + final long[] durations = new long[numRuns]; + + for (int i = 0; i < numRuns; i++) { + final ThroughputAnalysis<Object> analysis = new ThroughputAnalysis<Object>(); + analysis.setNumNoopFilters(100); + analysis.setInput(100, new Callable<Object>() { + @Override + public Object call() throws Exception { + return new Object(); + } + }); + analysis.init(); + + stopWatch.start(); + try { + analysis.start(); + } finally { + stopWatch.end(); + } + durations[i] = stopWatch.getDurationInNs(); + } + + // for (final long dur : durations) { + // System.out.println("Duration: " + (dur / 1000) + " �s"); + // } + + long sum = 0; + for (int i = durations.length / 2; i < durations.length; i++) { + sum += durations[i]; + } + + final long avgDur = sum / (numRuns / 2); + System.out.println("avg duration: " + (avgDur / 1000) + " �s"); + } + +} diff --git a/src/test/java/kieker/analysis/examples/throughput/ThroughputTimestampAnalysisTest.java b/src/test/java/kieker/analysis/examples/throughput/ThroughputTimestampAnalysisTest.java new file mode 100644 index 0000000000000000000000000000000000000000..fe5a6c4c469a5d1e0680a53f725f9d154338a143 --- /dev/null +++ b/src/test/java/kieker/analysis/examples/throughput/ThroughputTimestampAnalysisTest.java @@ -0,0 +1,74 @@ +/*************************************************************************** + * 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 kieker.analysis.examples.throughput; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +import kieker.analysis.examples.ThroughputTimestampAnalysis; +import kieker.analysis.exception.AnalysisConfigurationException; +import kieker.common.logging.LogFactory; + +import org.junit.Before; +import org.junit.Test; + +import teetime.examples.throughput.TimestampObject; +import teetime.util.StatisticsUtil; +import teetime.util.StopWatch; + + +/** + * @author Nils Christian Ehmke + * + * @since 1.10 + */ +public class ThroughputTimestampAnalysisTest { + + private static final int NUM_OBJECTS_TO_CREATE = 100000; + + @Before + public void before() { + System.setProperty(LogFactory.CUSTOM_LOGGER_JVM, "NONE"); + } + + @Test + public void testWithManyObjects() throws IllegalStateException, AnalysisConfigurationException { + final StopWatch stopWatch = new StopWatch(); + final List<TimestampObject> timestampObjects = new ArrayList<TimestampObject>(NUM_OBJECTS_TO_CREATE); + + final ThroughputTimestampAnalysis analysis = new ThroughputTimestampAnalysis(); + analysis.setNumNoopFilters(800); + 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); + } + +} diff --git a/src/test/java/teetime/examples/throughput/ThroughputTimestampAnalysisTest.java b/src/test/java/teetime/examples/throughput/ThroughputTimestampAnalysisTest.java index c11ce9390642f6a57d19d686734b652c866b2d62..bce03257e251593e379594ddfb0a4bd490cf2a36 100644 --- a/src/test/java/teetime/examples/throughput/ThroughputTimestampAnalysisTest.java +++ b/src/test/java/teetime/examples/throughput/ThroughputTimestampAnalysisTest.java @@ -48,7 +48,7 @@ public class ThroughputTimestampAnalysisTest { final ThroughputTimestampAnalysis analysis = new ThroughputTimestampAnalysis(); analysis.setShouldUseQueue(true); - analysis.setNumNoopFilters(10); // 4+n + analysis.setNumNoopFilters(800); // 4+n analysis.setTimestampObjects(timestampObjects); analysis.setInput(NUM_OBJECTS_TO_CREATE, new Callable<TimestampObject>() { @Override