only propagate cloud eval when depth increases
this should reduce the number of redis messages greatly. Before that, you could get cevals for pvs greater than yours, even if your depth is already higher.deepcrayonfish^2
parent
ce6129dbd9
commit
ece947fd20
|
@ -22,8 +22,8 @@ final private class EvalCacheUpgrade(setting: SettingStore[Boolean], scheduler:
|
||||||
import EvalCacheUpgrade._
|
import EvalCacheUpgrade._
|
||||||
|
|
||||||
private val members = mutable.AnyRefMap.empty[SriString, WatchingMember]
|
private val members = mutable.AnyRefMap.empty[SriString, WatchingMember]
|
||||||
private val evals = mutable.AnyRefMap.empty[SetupId, Set[SriString]]
|
private val evals = mutable.AnyRefMap.empty[SetupId, EvalState]
|
||||||
private val expirableSris = new ExpireCallbackMemo(20 minutes, sri => unregister(Socket.Sri(sri)))
|
private val expirableSris = new ExpireCallbackMemo(10 minutes, sri => unregister(Socket.Sri(sri)))
|
||||||
|
|
||||||
private val upgradeMon = lila.mon.evalCache.upgrade
|
private val upgradeMon = lila.mon.evalCache.upgrade
|
||||||
|
|
||||||
|
@ -34,15 +34,19 @@ final private class EvalCacheUpgrade(setting: SettingStore[Boolean], scheduler:
|
||||||
}
|
}
|
||||||
val setupId = makeSetupId(variant, fen, multiPv)
|
val setupId = makeSetupId(variant, fen, multiPv)
|
||||||
members += (sri.value -> WatchingMember(push, setupId, path))
|
members += (sri.value -> WatchingMember(push, setupId, path))
|
||||||
evals += (setupId -> (~evals.get(setupId) + sri.value))
|
evals += (setupId -> evals.get(setupId).fold(EvalState(Set(sri.value), 0))(_ addSri sri))
|
||||||
expirableSris put sri.value
|
expirableSris put sri.value
|
||||||
}
|
}
|
||||||
|
|
||||||
def onEval(input: EvalCacheEntry.Input, sri: Socket.Sri): Unit = if (setting.get()) {
|
def onEval(input: EvalCacheEntry.Input, sri: Socket.Sri): Unit = if (setting.get()) {
|
||||||
(1 to input.eval.multiPv) flatMap { multiPv =>
|
(1 to input.eval.multiPv) flatMap { multiPv =>
|
||||||
evals get makeSetupId(input.id.variant, input.fen, multiPv)
|
val setupId = makeSetupId(input.id.variant, input.fen, multiPv)
|
||||||
} foreach { sris =>
|
evals get setupId map (setupId -> _)
|
||||||
val wms = sris.withFilter(sri.value !=) flatMap members.get
|
} filter {
|
||||||
|
_._2.depth < input.eval.depth
|
||||||
|
} foreach { case (setupId, eval) =>
|
||||||
|
evals += (setupId -> eval.copy(depth = input.eval.depth))
|
||||||
|
val wms = eval.sris.withFilter(sri.value !=) flatMap members.get
|
||||||
if (wms.nonEmpty) {
|
if (wms.nonEmpty) {
|
||||||
val json = JsonHandlers.writeEval(input.eval, input.fen)
|
val json = JsonHandlers.writeEval(input.eval, input.fen)
|
||||||
wms foreach { wm =>
|
wms foreach { wm =>
|
||||||
|
@ -61,10 +65,10 @@ final private class EvalCacheUpgrade(setting: SettingStore[Boolean], scheduler:
|
||||||
}
|
}
|
||||||
|
|
||||||
private def unregisterEval(setupId: SetupId, sri: Socket.Sri): Unit =
|
private def unregisterEval(setupId: SetupId, sri: Socket.Sri): Unit =
|
||||||
evals get setupId foreach { sris =>
|
evals get setupId foreach { eval =>
|
||||||
val newSris = sris - sri.value
|
val newSris = eval.sris - sri.value
|
||||||
if (newSris.isEmpty) evals -= setupId
|
if (newSris.isEmpty) evals -= setupId
|
||||||
else evals += (setupId -> newSris)
|
else evals += (setupId -> eval.copy(sris = newSris))
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduler.scheduleWithFixedDelay(1 minute, 1 minute) { () =>
|
scheduler.scheduleWithFixedDelay(1 minute, 1 minute) { () =>
|
||||||
|
@ -80,6 +84,10 @@ private object EvalCacheUpgrade {
|
||||||
private type SetupId = String
|
private type SetupId = String
|
||||||
private type Push = JsObject => Unit
|
private type Push = JsObject => Unit
|
||||||
|
|
||||||
|
private case class EvalState(sris: Set[SriString], depth: Int) {
|
||||||
|
def addSri(sri: Socket.Sri) = copy(sris = sris + sri.value)
|
||||||
|
}
|
||||||
|
|
||||||
private def makeSetupId(variant: Variant, fen: FEN, multiPv: Int): SetupId =
|
private def makeSetupId(variant: Variant, fen: FEN, multiPv: Int): SetupId =
|
||||||
s"${variant.id}${EvalCacheEntry.SmallFen.make(variant, fen).value}^$multiPv"
|
s"${variant.id}${EvalCacheEntry.SmallFen.make(variant, fen).value}^$multiPv"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue