fishnet + cloud eval WIP, only monitoring ATM, for #3758
parent
08310a8133
commit
1cde128b4a
|
@ -249,7 +249,7 @@ lazy val simul = module("simul", Seq(
|
|||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val fishnet = module("fishnet", Seq(common, game, analyse, db)).settings(
|
||||
lazy val fishnet = module("fishnet", Seq(common, game, analyse, db, evalCache)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver, semver)
|
||||
)
|
||||
|
||||
|
|
|
@ -511,6 +511,7 @@ object mon {
|
|||
}
|
||||
val post = rec("fishnet.analysis.post")
|
||||
val requestCount = inc("fishnet.analysis.request")
|
||||
val evalCacheHits = rec("fishnet.analysis.eval_cache_hits")
|
||||
}
|
||||
}
|
||||
object api {
|
||||
|
|
|
@ -33,6 +33,11 @@ final class EvalCacheApi(
|
|||
|
||||
def shouldPut = truster shouldPut _
|
||||
|
||||
def getSinglePvEval(variant: Variant, fen: FEN): Fu[Option[Eval]] = getEval(
|
||||
id = Id(variant, SmallFen.make(variant, fen)),
|
||||
multiPv = 1
|
||||
)
|
||||
|
||||
private[evalCache] def drop(variant: Variant, fen: FEN): Funit = {
|
||||
val id = Id(chess.variant.Standard, SmallFen.make(variant, fen))
|
||||
coll.remove($id(id)).void >>- cache.put(id, none)
|
||||
|
|
|
@ -2,7 +2,7 @@ package lila.fishnet
|
|||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import chess.format.FEN
|
||||
import chess.format.{ Forsyth, FEN }
|
||||
|
||||
import lila.analyse.AnalysisRepo
|
||||
import lila.game.{ Game, GameRepo, UciMemo }
|
||||
|
@ -11,6 +11,7 @@ final class Analyser(
|
|||
repo: FishnetRepo,
|
||||
uciMemo: UciMemo,
|
||||
sequencer: lila.hub.FutureSequencer,
|
||||
evalCacheApi: lila.evalCache.EvalCacheApi,
|
||||
limiter: Limiter
|
||||
) {
|
||||
|
||||
|
@ -36,7 +37,10 @@ final class Analyser(
|
|||
// first request, store
|
||||
case _ =>
|
||||
lila.mon.fishnet.analysis.requestCount()
|
||||
repo addAnalysis work
|
||||
evalCacheHits(work) flatMap { cacheHits =>
|
||||
lila.mon.fishnet.analysis.evalCacheHits(cacheHits.size)
|
||||
repo addAnalysis work
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,4 +70,22 @@ final class Analyser(
|
|||
createdAt = DateTime.now
|
||||
)
|
||||
}
|
||||
|
||||
private def evalCacheHits(work: Work.Analysis): Fu[Map[Int, lila.evalCache.EvalCacheEntry.Eval]] =
|
||||
chess.Replay.games(
|
||||
work.game.moveList.take(12),
|
||||
work.game.initialFen map (_.value),
|
||||
work.game.variant
|
||||
).fold(
|
||||
_ => fuccess(Map.empty),
|
||||
_.zipWithIndex.map {
|
||||
case (game, index) =>
|
||||
evalCacheApi.getSinglePvEval(
|
||||
work.game.variant,
|
||||
FEN(Forsyth >> game)
|
||||
) map2 { (eval: lila.evalCache.EvalCacheEntry.Eval) =>
|
||||
(index + work.startPly) -> eval
|
||||
}
|
||||
}.sequenceFu.map(_.flatten.toMap)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ final class Env(
|
|||
config: Config,
|
||||
uciMemo: lila.game.UciMemo,
|
||||
requesterApi: lila.analyse.RequesterApi,
|
||||
evalCacheApi: lila.evalCache.EvalCacheApi,
|
||||
hub: lila.hub.Env,
|
||||
db: lila.db.Env,
|
||||
system: ActorSystem,
|
||||
|
@ -81,6 +82,7 @@ final class Env(
|
|||
repo = repo,
|
||||
uciMemo = uciMemo,
|
||||
sequencer = sequencer,
|
||||
evalCacheApi = evalCacheApi,
|
||||
limiter = limiter
|
||||
)
|
||||
|
||||
|
@ -130,6 +132,7 @@ object Env {
|
|||
system = lila.common.PlayApp.system,
|
||||
uciMemo = lila.game.Env.current.uciMemo,
|
||||
requesterApi = lila.analyse.Env.current.requesterApi,
|
||||
evalCacheApi = lila.evalCache.Env.current.api,
|
||||
hub = lila.hub.Env.current,
|
||||
db = lila.db.Env.current,
|
||||
config = lila.common.PlayApp loadConfig "fishnet",
|
||||
|
|
|
@ -4,8 +4,8 @@ import org.joda.time.DateTime
|
|||
import reactivemongo.bson._
|
||||
import scala.util.{ Try, Success, Failure }
|
||||
|
||||
import lila.common.IpAddress
|
||||
import Client.Skill
|
||||
import lila.common.IpAddress
|
||||
import lila.db.dsl._
|
||||
import lila.hub.FutureSequencer
|
||||
|
||||
|
|
Loading…
Reference in New Issue