Revert "rate limit player and watcher sockets"
Apparently a terrible performance regression.
Production CPU went berserk.
How to reproduce in test env?
This reverts commit b66bb61380
.
This commit is contained in:
parent
4b4af3f4f6
commit
88ba7dcf92
|
@ -51,11 +51,6 @@ private[controllers] trait LilaController
|
|||
protected def SocketEither[A: FrameFormatter](f: Context => Fu[Either[Result, (Iteratee[A, _], Enumerator[A])]]) =
|
||||
WebSocket.tryAccept[A] { req => reqToCtx(req) flatMap f }
|
||||
|
||||
protected def SocketEitherLimited[A: FrameFormatter](consumer: TokenBucket.Consumer, name: String)(f: Context => Fu[Either[Result, (Iteratee[A, _], Enumerator[A])]]) =
|
||||
LilaSocket.rateLimited[A](consumer, name) { req =>
|
||||
reqToCtx(req) flatMap f
|
||||
}
|
||||
|
||||
protected def SocketOption[A: FrameFormatter](f: Context => Fu[Option[(Iteratee[A, _], Enumerator[A])]]) =
|
||||
WebSocket.tryAccept[A] { req =>
|
||||
reqToCtx(req) flatMap f map {
|
||||
|
|
|
@ -23,40 +23,31 @@ object Round extends LilaController with TheftPrevention {
|
|||
private def bookmarkApi = Env.bookmark.api
|
||||
private def analyser = Env.analyse.analyser
|
||||
|
||||
private val socketConsumer = lila.api.TokenBucket.create(
|
||||
system = lila.common.PlayApp.system,
|
||||
size = 10,
|
||||
rate = 6)
|
||||
|
||||
def websocketWatcher(gameId: String, color: String) = SocketOptionLimited[JsValue](
|
||||
consumer = socketConsumer,
|
||||
name = "watcher") { implicit ctx =>
|
||||
get("sri") ?? { uid =>
|
||||
env.socketHandler.watcher(
|
||||
gameId = gameId,
|
||||
colorName = color,
|
||||
uid = uid,
|
||||
user = ctx.me,
|
||||
ip = ctx.ip,
|
||||
userTv = get("userTv"))
|
||||
}
|
||||
def websocketWatcher(gameId: String, color: String) = SocketOption[JsValue] { implicit ctx =>
|
||||
get("sri") ?? { uid =>
|
||||
env.socketHandler.watcher(
|
||||
gameId = gameId,
|
||||
colorName = color,
|
||||
uid = uid,
|
||||
user = ctx.me,
|
||||
ip = ctx.ip,
|
||||
userTv = get("userTv"))
|
||||
}
|
||||
}
|
||||
|
||||
def websocketPlayer(fullId: String, apiVersion: Int) = SocketEitherLimited[JsValue](
|
||||
consumer = socketConsumer,
|
||||
name = "player") { implicit ctx =>
|
||||
GameRepo pov fullId flatMap {
|
||||
case Some(pov) =>
|
||||
if (isTheft(pov)) fuccess(Left(theftResponse))
|
||||
else get("sri") match {
|
||||
case Some(uid) => requestAiMove(pov) >> env.socketHandler.player(
|
||||
pov, uid, ~get("ran"), ctx.me, ctx.ip
|
||||
) map Right.apply
|
||||
case None => fuccess(Left(NotFound))
|
||||
}
|
||||
case None => fuccess(Left(NotFound))
|
||||
}
|
||||
def websocketPlayer(fullId: String, apiVersion: Int) = SocketEither[JsValue] { implicit ctx =>
|
||||
GameRepo pov fullId flatMap {
|
||||
case Some(pov) =>
|
||||
if (isTheft(pov)) fuccess(Left(theftResponse))
|
||||
else get("sri") match {
|
||||
case Some(uid) => requestAiMove(pov) >> env.socketHandler.player(
|
||||
pov, uid, ~get("ran"), ctx.me, ctx.ip
|
||||
) map Right.apply
|
||||
case None => fuccess(Left(NotFound))
|
||||
}
|
||||
case None => fuccess(Left(NotFound))
|
||||
}
|
||||
}
|
||||
|
||||
private def requestAiMove(pov: Pov) = pov.game.playableByAi ?? Env.fishnet.player(pov.game)
|
||||
|
||||
|
|
Loading…
Reference in a new issue