add lila-ws round-trip latency to lag monitor

pull/10007/head
Thibault Duplessis 2021-10-22 09:59:22 +02:00
parent c456eb5eaa
commit 0e8fe36533
3 changed files with 15 additions and 9 deletions

View File

@ -12,13 +12,16 @@ private object MoveLatMonitor {
}
private val latency = new AtomicReference(Latency())
def record(micros: Int): Unit = latency.getAndUpdate(_ record micros).unit
object wsLatency {
var latestMillis = 0
def set(millis: Int) = latestMillis = millis
}
def start(scheduler: Scheduler)(implicit ec: scala.concurrent.ExecutionContext) =
scheduler.scheduleWithFixedDelay(10 second, 2 second) { () =>
lila.common.Bus.publish(
lila.hub.actorApi.round.Mlat(latency.getAndSet(Latency()).average),
"mlat"
)
val full = latency.getAndSet(Latency()).average + wsLatency.latestMillis * 1000
lila.common.Bus.publish(lila.hub.actorApi.round.Mlat(full), "mlat")
}
def record(micros: Int): Unit = latency.getAndUpdate(_ record micros).unit
}

View File

@ -150,7 +150,8 @@ final class RoundSocket(
case RP.In.SetVersions(versions) =>
preloadRoundsWithVersions(versions)
send(Protocol.Out.versioningReady)
case P.In.Ping(id) => send(P.Out.pong(id))
case P.In.Ping(id) => send(P.Out.pong(id))
case Protocol.In.WsLatency(millis) => MoveLatMonitor.wsLatency.set(millis)
case P.In.WsBoot =>
logger.warn("Remote socket boot")
// schedule termination for all game asyncActors
@ -315,6 +316,7 @@ object RoundSocket {
case class Flag(gameId: Game.Id, color: Color, fromPlayerId: Option[PlayerId]) extends P.In
case class Berserk(gameId: Game.Id, userId: User.ID) extends P.In
case class SelfReport(fullId: FullId, ip: IpAddress, userId: Option[User.ID], name: String) extends P.In
case class WsLatency(millis: Int) extends P.In
val reader: P.In.Reader = raw =>
raw.path match {
@ -376,7 +378,8 @@ object RoundSocket {
Flag(Game.Id(gameId), _, P.In.optional(playerId) map PlayerId.apply)
}
}
case _ => RP.In.reader(raw)
case "r/latency" => raw.args.toIntOption map WsLatency
case _ => RP.In.reader(raw)
}
private def centis(s: String): Option[Centis] =

View File

@ -7,7 +7,7 @@
<string name="yesItWillBeFixedSoon">Yes. It will be fixed soon!</string>
<string name="andNowTheLongAnswerLagComposedOfTwoValues">And now, the long answer! Game lag is composed of two unrelated values (lower is better):</string>
<string name="lichessServerLatency">Lichess server latency</string>
<string name="lichessServerLatencyExplanation">The time it takes to process a move on the server. It's the same for everybody, and only depends on the server load. The more players and the higher it gets, but Lichess developers do their best to keep it low. It rarely exceeds 10ms.</string>
<string name="lichessServerLatencyExplanation">The time it takes to process a move on the server. It's the same for everybody, and only depends on the servers load. The more players and the higher it gets, but Lichess developers do their best to keep it low. It rarely exceeds 10ms.</string>
<string name="networkBetweenLichessAndYou">Network between Lichess and you</string>
<string name="networkBetweenLichessAndYouExplanation">The time it takes to send a move from your computer to Lichess server, and get the response back. It's specific to your distance to Lichess (France), and to the quality of your Internet connection. Lichess developers cannot fix your wifi or make light go faster.</string>
<string name="youCanFindTheseValuesAtAnyTimeByClickingOnYourUsername">You can find both these values at any time, by clicking your username in the top bar.</string>