Fixed benchmark reporting, which was broken in AkkaApplication refactoring. Repo must be global to keep results
This commit is contained in:
parent
9bf9cea0d9
commit
7cde84b5db
2 changed files with 36 additions and 34 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 ⇒ }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue