Skip to content

Commit

Permalink
remove precalculation of stats holder
Browse files Browse the repository at this point in the history
bump up to new minor
  • Loading branch information
aurbroszniowski committed Oct 14, 2019
1 parent f3e358c commit a7050e3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>io.rainfall</groupId>
<artifactId>rainfall-core</artifactId>
<name>Rainfall-core</name>
<version>1.4.17-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
Expand Down
31 changes: 4 additions & 27 deletions src/main/java/io/rainfall/ScenarioRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import io.rainfall.configuration.ConcurrencyConfig;
import io.rainfall.configuration.DistributedConfig;
import io.rainfall.configuration.ReportingConfig;
import io.rainfall.reporting.Reporter;
import io.rainfall.reporting.PeriodicReporter;
import io.rainfall.statistics.InitStatisticsHolder;
import io.rainfall.reporting.Reporter;
import io.rainfall.statistics.RuntimeStatisticsHolder;
import io.rainfall.statistics.StatisticsPeekHolder;
import io.rainfall.statistics.StatisticsThread;
import io.rainfall.utils.RangeMap;
import io.rainfall.utils.distributed.RainfallClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,7 +32,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -113,16 +110,11 @@ public StatisticsPeekHolder<E> start() {
//TODO : add generics ? cast?
ReportingConfig<E> reportingConfig = (ReportingConfig<E>)configurations.get(ReportingConfig.class);

//TODO change this, this is ugly
// we need to call all operations to init the 'names', measured, should the 'name' be the key of the maps or instead
// be inside of the Statistics, and the key would be operation result
// besides, we end up having to initialize two stats holder, one real, and one blank for warmup phase, it's ugly
RuntimeStatisticsHolder<E> blankStatisticsHolder = new RuntimeStatisticsHolder<E>(reportingConfig.getResults(), reportingConfig
.getResultsReported(), reportingConfig.getStatisticsCollectors());
initStatistics(blankStatisticsHolder);

try {
if (warmup != null) {
RuntimeStatisticsHolder<E> blankStatisticsHolder = new RuntimeStatisticsHolder<E>(reportingConfig.getResults(), reportingConfig
.getResultsReported(), reportingConfig.getStatisticsCollectors());
System.out.println("Executing warmup phase, please wait.");
warmup.execute(blankStatisticsHolder, scenario, configurations, assertions);
}
Expand All @@ -132,11 +124,10 @@ public StatisticsPeekHolder<E> start() {

this.statisticsHolder = new RuntimeStatisticsHolder<E>(reportingConfig.getResults(), reportingConfig.getResultsReported(),
reportingConfig.getStatisticsCollectors());
initStatistics(this.statisticsHolder);

final Set<Reporter<E>> logReporters = reportingConfig.getLogReporters();
ScheduledExecutorService topOfSecondExecutor = Executors.newScheduledThreadPool(logReporters.size(), new CustomThreadFactory());
StatisticsThread<E> stats = null;
StatisticsThread<E> stats = null;
StatisticsPeekHolder<E> peek = null;
try {
stats = new StatisticsThread<E>(statisticsHolder, reportingConfig, getDescription(),
Expand Down Expand Up @@ -260,20 +251,6 @@ private List<String> getDescription() {
return description;
}

private void initStatistics(RuntimeStatisticsHolder<E> statisticsHolder) {
try {
for (RangeMap<WeightedOperation> operation : scenario.getOperations().values()) {
Collection<WeightedOperation> allOperations = operation.getAll();
for (WeightedOperation allOperation : allOperations) {
allOperation.getOperation()
.exec(new InitStatisticsHolder<E>(statisticsHolder), this.configurations, this.assertions);
}
}
} catch (TestException e) {
throw new RuntimeException(e);
}
}

public Scenario getScenario() {
return scenario;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ public Histogram fetchHistogram(final Enum<E> result) {
return this.histograms.fetchHistogram(result);
}

public void addStatistics(String name, Statistics<E> statistics) {
this.statistics.put(name, statistics);
this.assertionsErrors.put(name, new LongAdder());
}

@Override
public synchronized void reset() {
for (Statistics<E> statistics : this.statistics.values()) {
Expand All @@ -105,7 +100,15 @@ public synchronized long getCurrentTps(Enum result) {

@Override
public void record(final String name, final long responseTimeInNs, final Enum result) {
this.statistics.get(name).increaseCounterAndSetLatencyInNs(result, responseTimeInNs);
Statistics<E> eStatistics = this.statistics.get(name);
if (eStatistics == null) {
final Statistics<E> statistics = new Statistics<>(name, results);
eStatistics = this.statistics.putIfAbsent(name, statistics);
if (eStatistics == null) {
eStatistics = statistics;
}
}
eStatistics.increaseCounterAndSetLatencyInNs(result, responseTimeInNs);
histograms.recordValue(result, responseTimeInNs);
}

Expand Down
2 changes: 0 additions & 2 deletions src/test/java/io/rainfall/integration/StatsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.rainfall.configuration.ReportingConfig;
import io.rainfall.reporting.Reporter;
import io.rainfall.statistics.RuntimeStatisticsHolder;
import io.rainfall.statistics.Statistics;
import io.rainfall.utils.SystemTest;
import org.HdrHistogram.Histogram;
import org.junit.Ignore;
Expand Down Expand Up @@ -60,7 +59,6 @@ public void testStatsHolderOnly() {
);

String name = "MY_TEST";
statisticsHolder.addStatistics(name, new Statistics<StatsTestResult>(name, statisticsHolder.getResults()));

TimeUnit reportIntervalUnit = reportingConfig.getReportTimeUnit();
long reportIntervalMillis = reportIntervalUnit.toMillis(reportingConfig.getReportInterval());
Expand Down

0 comments on commit a7050e3

Please sign in to comment.