From 7cde84b5dbc200e63c41bb30f37d49d90c4a38d2 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Thu, 20 Oct 2011 17:45:16 +0200 Subject: [PATCH] Fixed benchmark reporting, which was broken in AkkaApplication refactoring. Repo must be global to keep results --- .../trading/common/PerformanceTest.scala | 54 ++++++++++--------- .../workbench/BenchResultRepository.scala | 16 +++--- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/performance/trading/common/PerformanceTest.scala b/akka-actor-tests/src/test/scala/akka/performance/trading/common/PerformanceTest.scala index fb6610a75e..2ac7d88ca7 100644 --- a/akka-actor-tests/src/test/scala/akka/performance/trading/common/PerformanceTest.scala +++ b/akka-actor-tests/src/test/scala/akka/performance/trading/common/PerformanceTest.scala @@ -56,7 +56,7 @@ trait PerformanceTest extends JUnitSuite { var stat: DescriptiveStatistics = _ - val resultRepository = BenchResultRepository(app) + val resultRepository = BenchResultRepository() lazy val report = new Report(app, resultRepository, compareResultWith) type TS <: TradingSystem @@ -107,34 +107,38 @@ trait PerformanceTest extends JUnitSuite { def compareResultWith: Option[String] = None def logMeasurement(scenario: String, numberOfClients: Int, durationNs: Long) { + try { + val name = simpleName(this) + val durationS = durationNs.toDouble / 1000000000.0 + + val percentiles = TreeMap[Int, Long]( + 5 -> (stat.getPercentile(5.0) / 1000).toLong, + 25 -> (stat.getPercentile(25.0) / 1000).toLong, + 50 -> (stat.getPercentile(50.0) / 1000).toLong, + 75 -> (stat.getPercentile(75.0) / 1000).toLong, + 95 -> (stat.getPercentile(95.0) / 1000).toLong) - val name = simpleName(this) - val durationS = durationNs.toDouble / 1000000000.0 + val n = stat.getN * sampling - val percentiles = TreeMap[Int, Long]( - 5 -> (stat.getPercentile(5.0) / 1000).toLong, - 25 -> (stat.getPercentile(25.0) / 1000).toLong, - 50 -> (stat.getPercentile(50.0) / 1000).toLong, - 75 -> (stat.getPercentile(75.0) / 1000).toLong, - 95 -> (stat.getPercentile(95.0) / 1000).toLong) + val stats = Stats( + name, + load = numberOfClients, + timestamp = TestStart.startTime, + durationNanos = durationNs, + n = n, + min = (stat.getMin / 1000).toLong, + max = (stat.getMax / 1000).toLong, + mean = (stat.getMean / 1000).toLong, + tps = (n.toDouble / durationS), + percentiles) - val n = stat.getN * sampling + resultRepository.add(stats) - val stats = Stats( - name, - load = numberOfClients, - timestamp = TestStart.startTime, - durationNanos = durationNs, - n = n, - min = (stat.getMin / 1000).toLong, - max = (stat.getMax / 1000).toLong, - mean = (stat.getMean / 1000).toLong, - tps = (n.toDouble / durationS), - percentiles) - - resultRepository.add(stats) - - report.html(resultRepository.get(name)) + report.html(resultRepository.get(name)) + } catch { + // don't fail test due to problems saving bench report + case e: Exception ⇒ app.eventHandler.error(this, e.getMessage) + } } def delay(delayMs: Int) { diff --git a/akka-actor-tests/src/test/scala/akka/performance/workbench/BenchResultRepository.scala b/akka-actor-tests/src/test/scala/akka/performance/workbench/BenchResultRepository.scala index bc9d6593f3..887de2e455 100644 --- a/akka-actor-tests/src/test/scala/akka/performance/workbench/BenchResultRepository.scala +++ b/akka-actor-tests/src/test/scala/akka/performance/workbench/BenchResultRepository.scala @@ -12,7 +12,6 @@ import java.io.PrintWriter import java.text.SimpleDateFormat import java.util.Date import scala.collection.mutable.{ Map ⇒ MutableMap } -import akka.AkkaApplication trait BenchResultRepository { def add(stats: Stats) @@ -30,10 +29,11 @@ trait BenchResultRepository { } object BenchResultRepository { - def apply(app: AkkaApplication): BenchResultRepository = new FileBenchResultRepository(app) + private val repository = new FileBenchResultRepository + def apply(): BenchResultRepository = repository } -class FileBenchResultRepository(val app: AkkaApplication) extends BenchResultRepository { +class FileBenchResultRepository extends BenchResultRepository { private val statsByName = MutableMap[String, Seq[Stats]]() private val baselineStats = MutableMap[Key, Stats]() private val historicalStats = MutableMap[Key, Seq[Stats]]() @@ -102,8 +102,8 @@ class FileBenchResultRepository(val app: AkkaApplication) extends BenchResultRep out.writeObject(stats) } catch { case e: Exception ⇒ - app.eventHandler.error(this, "Failed to save [%s] to [%s], due to [%s]". - format(stats, f.getAbsolutePath, e.getMessage)) + val errMsg = "Failed to save [%s] to [%s], due to [%s]".format(stats, f.getAbsolutePath, e.getMessage) + throw new RuntimeException(errMsg) } finally { if (out ne null) try { out.close() } catch { case ignore: Exception ⇒ } } @@ -119,8 +119,6 @@ class FileBenchResultRepository(val app: AkkaApplication) extends BenchResultRep Some(stats) } catch { case e: Throwable ⇒ - app.eventHandler.error(this, "Failed to load from [%s], due to [%s]". - format(f.getAbsolutePath, e.getMessage)) None } finally { if (in ne null) try { in.close() } catch { case ignore: Exception ⇒ } @@ -143,8 +141,8 @@ class FileBenchResultRepository(val app: AkkaApplication) extends BenchResultRep writer.flush() } catch { case e: Exception ⇒ - app.eventHandler.error(this, "Failed to save report to [%s], due to [%s]". - format(f.getAbsolutePath, e.getMessage)) + val errMsg = "Failed to save report to [%s], due to [%s]".format(f.getAbsolutePath, e.getMessage) + throw new RuntimeException(errMsg) } finally { if (writer ne null) try { writer.close() } catch { case ignore: Exception ⇒ } }