10. Распределенные кэши (1 из 3)
deployment {
/sessionManager/router {
router = consistent-hashing-group
nr-of-instances = 16
routees.paths = ["/user/sessionManager"]
cluster {
enabled = on
allow-local-routees = on
}
}
}
11. Распределенные кэши (2 из 3)
import akka.routing.ConsistentHashingRouter.ConsistentHashable
trait RoutedMsgWithId {
val id: Long
}
case class RoutedMsg[T](key: T, msg: Any) extends ConsistentHashable {
val consistentHashKey = key
}
12. Распределенные кэши (3 из 3)
class SessionManager extends Actor with ActorLogging {
val managerRouter = context.actorOf(Props.empty.withRouter(FromConfig), "router")
override def receive = LoggingReceive {
case msg: RoutedMsgWithId =>
managerRouter forward RoutedMsg(msg.id, msg)
case r@RoutedMsg(sid: Long, msg: Any) =>
val actorName = s"session-$sid"
context.child(actorName) getOrElse {
context.actorOf(SessionActor.props(sid), actorName)
} forward msg
}
}
15. Поиск узких мест
● Метрики
● Флаг writeTrace: Boolean
● Пробрасываение контекста Kamon’ом
● Класс-наследник Actor
● Смотрим в логи через Logentries
● Немного хитрой логики, когда писать
● + https://www.yourkit.com/