From a7050e37a7057c9042de0c6df79906f250bfac35 Mon Sep 17 00:00:00 2001 From: Aurelien Date: Mon, 14 Oct 2019 23:17:01 +0200 Subject: [PATCH] remove precalculation of stats holder bump up to new minor --- pom.xml | 2 +- src/main/java/io/rainfall/ScenarioRun.java | 31 +++---------------- .../statistics/RuntimeStatisticsHolder.java | 15 +++++---- .../io/rainfall/integration/StatsTest.java | 2 -- 4 files changed, 14 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 891ba95..613b434 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ io.rainfall rainfall-core Rainfall-core - 1.4.17-SNAPSHOT + 1.5.0-SNAPSHOT jar diff --git a/src/main/java/io/rainfall/ScenarioRun.java b/src/main/java/io/rainfall/ScenarioRun.java index 652606e..8afe340 100644 --- a/src/main/java/io/rainfall/ScenarioRun.java +++ b/src/main/java/io/rainfall/ScenarioRun.java @@ -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; @@ -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; @@ -113,16 +110,11 @@ public StatisticsPeekHolder start() { //TODO : add generics ? cast? ReportingConfig reportingConfig = (ReportingConfig)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 blankStatisticsHolder = new RuntimeStatisticsHolder(reportingConfig.getResults(), reportingConfig - .getResultsReported(), reportingConfig.getStatisticsCollectors()); - initStatistics(blankStatisticsHolder); try { if (warmup != null) { + RuntimeStatisticsHolder blankStatisticsHolder = new RuntimeStatisticsHolder(reportingConfig.getResults(), reportingConfig + .getResultsReported(), reportingConfig.getStatisticsCollectors()); System.out.println("Executing warmup phase, please wait."); warmup.execute(blankStatisticsHolder, scenario, configurations, assertions); } @@ -132,11 +124,10 @@ public StatisticsPeekHolder start() { this.statisticsHolder = new RuntimeStatisticsHolder(reportingConfig.getResults(), reportingConfig.getResultsReported(), reportingConfig.getStatisticsCollectors()); - initStatistics(this.statisticsHolder); final Set> logReporters = reportingConfig.getLogReporters(); ScheduledExecutorService topOfSecondExecutor = Executors.newScheduledThreadPool(logReporters.size(), new CustomThreadFactory()); - StatisticsThread stats = null; + StatisticsThread stats = null; StatisticsPeekHolder peek = null; try { stats = new StatisticsThread(statisticsHolder, reportingConfig, getDescription(), @@ -260,20 +251,6 @@ private List getDescription() { return description; } - private void initStatistics(RuntimeStatisticsHolder statisticsHolder) { - try { - for (RangeMap operation : scenario.getOperations().values()) { - Collection allOperations = operation.getAll(); - for (WeightedOperation allOperation : allOperations) { - allOperation.getOperation() - .exec(new InitStatisticsHolder(statisticsHolder), this.configurations, this.assertions); - } - } - } catch (TestException e) { - throw new RuntimeException(e); - } - } - public Scenario getScenario() { return scenario; } diff --git a/src/main/java/io/rainfall/statistics/RuntimeStatisticsHolder.java b/src/main/java/io/rainfall/statistics/RuntimeStatisticsHolder.java index b6daaa8..c320d74 100644 --- a/src/main/java/io/rainfall/statistics/RuntimeStatisticsHolder.java +++ b/src/main/java/io/rainfall/statistics/RuntimeStatisticsHolder.java @@ -81,11 +81,6 @@ public Histogram fetchHistogram(final Enum result) { return this.histograms.fetchHistogram(result); } - public void addStatistics(String name, Statistics statistics) { - this.statistics.put(name, statistics); - this.assertionsErrors.put(name, new LongAdder()); - } - @Override public synchronized void reset() { for (Statistics statistics : this.statistics.values()) { @@ -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 eStatistics = this.statistics.get(name); + if (eStatistics == null) { + final Statistics statistics = new Statistics<>(name, results); + eStatistics = this.statistics.putIfAbsent(name, statistics); + if (eStatistics == null) { + eStatistics = statistics; + } + } + eStatistics.increaseCounterAndSetLatencyInNs(result, responseTimeInNs); histograms.recordValue(result, responseTimeInNs); } diff --git a/src/test/java/io/rainfall/integration/StatsTest.java b/src/test/java/io/rainfall/integration/StatsTest.java index 0ada3b4..8a81e26 100644 --- a/src/test/java/io/rainfall/integration/StatsTest.java +++ b/src/test/java/io/rainfall/integration/StatsTest.java @@ -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; @@ -60,7 +59,6 @@ public void testStatsHolderOnly() { ); String name = "MY_TEST"; - statisticsHolder.addStatistics(name, new Statistics(name, statisticsHolder.getResults())); TimeUnit reportIntervalUnit = reportingConfig.getReportTimeUnit(); long reportIntervalMillis = reportIntervalUnit.toMillis(reportingConfig.getReportInterval());