Skip to content

Commit

Permalink
BestFirstSearch: don't give up too soon
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Meltzer committed Feb 21, 2020
1 parent 1d09969 commit 0876f01
Show file tree
Hide file tree
Showing 11 changed files with 2,283 additions and 904 deletions.
72 changes: 59 additions & 13 deletions repos/lila/modules/api/src/main/RoundApiBalancer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,97 @@ private[api] final class RoundApiBalancer(
implicit val timeout = makeTimeout seconds 20

case class Player(pov: Pov, apiVersion: Int, ctx: Context)
case class Watcher(pov: Pov, apiVersion: Int, tv: Option[lila.round.OnTv],
case class Watcher(
pov: Pov,
apiVersion: Int,
tv: Option[lila.round.OnTv],
analysis: Option[(Pgn, Analysis)] = None,
initialFenO: Option[Option[String]] = None,
withMoveTimes: Boolean = false,
withOpening: Boolean = false,
ctx: Context)
case class UserAnalysis(pov: Pov, pref: Pref, initialFen: Option[String], orientation: chess.Color, owner: Boolean)
case class UserAnalysis(
pov: Pov,
pref: Pref,
initialFen: Option[String],
orientation: chess.Color,
owner: Boolean)

val router = system.actorOf(
akka.routing.RoundRobinPool(nbActors).props(Props(new lila.hub.SequentialProvider {
akka.routing
.RoundRobinPool(nbActors)
.props(Props(new lila.hub.SequentialProvider {
val futureTimeout = 20.seconds
val logger = RoundApiBalancer.this.logger
def process = {
case Player(pov, apiVersion, ctx) => {
api.player(pov, apiVersion)(ctx) addFailureEffect { e =>
logger.error(pov.toString, e)
}
}.chronometer.logIfSlow(500, logger) { _ => s"inner player $pov" }.result
case Watcher(pov, apiVersion, tv, analysis, initialFenO, withMoveTimes, withOpening, ctx) =>
api.watcher(pov, apiVersion, tv, analysis, initialFenO, withMoveTimes, withOpening)(ctx)
}.chronometer
.logIfSlow(500, logger) { _ => s"inner player $pov" }
.result
case Watcher(
pov,
apiVersion,
tv,
analysis,
initialFenO,
withMoveTimes,
withOpening,
ctx) =>
api.watcher(
pov,
apiVersion,
tv,
analysis,
initialFenO,
withMoveTimes,
withOpening)(ctx)
case UserAnalysis(pov, pref, initialFen, orientation, owner) =>
api.userAnalysisJson(pov, pref, initialFen, orientation, owner)
}
})), "api.round.router")
})),
"api.round.router"
)
}

import implementation._

def player(pov: Pov, apiVersion: Int)(implicit ctx: Context): Fu[JsObject] = {
router ? Player(pov, apiVersion, ctx) mapTo manifest[JsObject] addFailureEffect { e =>
logger.error(pov.toString, e)
router ? Player(pov, apiVersion, ctx) mapTo manifest[JsObject] addFailureEffect {
e => logger.error(pov.toString, e)
}
}.chronometer
.mon(_.round.api.player)
.logIfSlow(500, logger) { _ => s"outer player $pov" }
.result

def watcher(pov: Pov, apiVersion: Int, tv: Option[lila.round.OnTv],
def watcher(
pov: Pov,
apiVersion: Int,
tv: Option[lila.round.OnTv],
analysis: Option[(Pgn, Analysis)] = None,
initialFenO: Option[Option[String]] = None,
withMoveTimes: Boolean = false,
withOpening: Boolean = false)(implicit ctx: Context): Fu[JsObject] = {
router ? Watcher(pov, apiVersion, tv, analysis, initialFenO, withMoveTimes, withOpening, ctx) mapTo manifest[JsObject]
router ? Watcher(
pov,
apiVersion,
tv,
analysis,
initialFenO,
withMoveTimes,
withOpening,
ctx) mapTo manifest[JsObject]
}.mon(_.round.api.watcher)

def userAnalysisJson(pov: Pov, pref: Pref, initialFen: Option[String], orientation: chess.Color, owner: Boolean): Fu[JsObject] =
router ? UserAnalysis(pov, pref, initialFen, orientation, owner) mapTo manifest[JsObject]
def userAnalysisJson(
pov: Pov,
pref: Pref,
initialFen: Option[String],
orientation: chess.Color,
owner: Boolean): Fu[JsObject] =
router ? UserAnalysis(pov, pref, initialFen, orientation, owner) mapTo manifest[
JsObject]
}
Loading

0 comments on commit 0876f01

Please sign in to comment.