improve game perf testing

lazy-decoded
Thibault Duplessis 2018-02-06 11:48:50 -05:00
parent e19eb6bcd9
commit 6f4886c604
2 changed files with 16 additions and 7 deletions

View File

@ -102,7 +102,7 @@ final class Env(
def cli = new lila.common.Cli {
def process = {
case "stream" :: "test" :: Nil => StreamTest.start
case "game" :: "test" :: times :: Nil => parseIntOption(times) ?? StreamTest.start
}
}
}

View File

@ -4,6 +4,7 @@ import BSONHandlers._
import lila.db.dsl._
import play.api.libs.iteratee._
import reactivemongo.play.iteratees.cursorProducer
import reactivemongo.bson._
// old (lazyload) = 25 micros / game
// old + toChess = 55 micros / game
@ -12,19 +13,27 @@ import reactivemongo.play.iteratees.cursorProducer
object StreamTest {
val max = 100000
val concurrency = 4
def start = {
def readGame(bson: BSONDocument): Game =
gameBSONHandler read bson
def start(times: Int): Fu[String] = {
GameRepo.coll
.find($empty)
.cursor[Game]()
.cursor[BSONDocument]()
.enumerator(max) |>>>
Iteratee.fold[Game, Int](0) {
case (nb, g) =>
Iteratee.fold[BSONDocument, Int](0) {
case (nb, doc) =>
List.fill(concurrency)(doc).par.map(readGame)
if (nb % 10000 == 0) println(nb)
nb + 1
}
}.chronometer.lap.map { lap =>
println(s"""${lap.result} games in ${lap.millis}ms, ${lap.micros / lap.result} micros per game""")
println(s"""${lap.result * concurrency} games in ${lap.millis}ms, ${lap.micros / lap.result / concurrency} micros per game""")
lap.result
} map (_.toString)
} >> {
if (times > 0) start(times - 1)
else fuccess("done")
}
}