如何检查我在配置文件中定义的 akka 调度程序是否正常工作
how to check my akka dispatchers defined in config file working or not
嗨,我是 akka 调度员的新手,我从 akka documentation
那里得到了帮助
我想检查我是否正确调整了调度程序
这是我的 applica.conf
include "DirectUserWriteMongoActor"
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
}
这是我的 DirectUserWriteMongoActor.conf
akka {
actor{
############################### Setting for a Dispatcher #####################################
directUserWriteMongoActor-dispatcher {
type = Dispatcher
executor = "fork-join-executor"
fork-join-executor {
parallelism-min = 2
parallelism-factor = 2.0
parallelism-max = 10
}
throughput = 10
} #end default-dispatcher
############################### Setting for a Router #####################################
deployment{
/directUserWritwMongoActorRouter{
router = round-robin
nr-of-instances = 5
}
}#end deployment
} #end Actor
} #end Akka
这是我的代码
object TestActor extends App{
val config = ConfigFactory.load().getConfig("akka.actor")
val system = ActorSystem("TestActorSystem",config)
val DirectUserWriteMongoActor = system.actorOf(Props[DirectUserWriteMongoActor].withDispatcher("directUserWriteMongoActor-dispatcher"), name = "directwritemongoactor")
class DirectUserWriteMongoActor extends Actor {
def receive =
{
case _ =>
}
}
当我 运行 它编译代码时,但我想知道我如何知道 akka 调度程序是否在工作,请帮助
您可以使用 system
对象获取当前调度程序:
scala> val config = ConfigFactory.load().getConfig("akka.actor")
config: com.typesafe.config.Config = Config(SimpleConfigObject(... "default-dispatcher" ... )
scala> val system = ActorSystem("ArteciateActorSystem", config)
system: akka.actor.ActorSystem = akka://ArteciateActorSystem
scala> system.dispatcher.toString
res7: String = Dispatcher[akka.actor.default-dispatcher]
请注意,我已将 Config
中的代码删减到相关部分,您得到的内容要冗长得多。
您始终可以从 Actor 内部打印线程名称,因为线程池(由调度程序使用)将具有适当的名称,您应该能够确定它是否在您期望的调度程序上 运行ning 运行。
class CheckingThread extends Actor {
def receive = {
case _ =>
println(s"Using thread: ${Thread.currentThread().getName}")
// or reply with it: sender() ! Thread.currentThread().getName
}
}
您也可以通过打开 visual vm 或您喜欢/可用的任何 jvm 分析器来调查 运行ning 线程。
嗨,我是 akka 调度员的新手,我从 akka documentation
那里得到了帮助我想检查我是否正确调整了调度程序 这是我的 applica.conf
include "DirectUserWriteMongoActor"
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
}
这是我的 DirectUserWriteMongoActor.conf
akka {
actor{
############################### Setting for a Dispatcher #####################################
directUserWriteMongoActor-dispatcher {
type = Dispatcher
executor = "fork-join-executor"
fork-join-executor {
parallelism-min = 2
parallelism-factor = 2.0
parallelism-max = 10
}
throughput = 10
} #end default-dispatcher
############################### Setting for a Router #####################################
deployment{
/directUserWritwMongoActorRouter{
router = round-robin
nr-of-instances = 5
}
}#end deployment
} #end Actor
} #end Akka
这是我的代码
object TestActor extends App{
val config = ConfigFactory.load().getConfig("akka.actor")
val system = ActorSystem("TestActorSystem",config)
val DirectUserWriteMongoActor = system.actorOf(Props[DirectUserWriteMongoActor].withDispatcher("directUserWriteMongoActor-dispatcher"), name = "directwritemongoactor")
class DirectUserWriteMongoActor extends Actor {
def receive =
{
case _ =>
}
}
当我 运行 它编译代码时,但我想知道我如何知道 akka 调度程序是否在工作,请帮助
您可以使用 system
对象获取当前调度程序:
scala> val config = ConfigFactory.load().getConfig("akka.actor")
config: com.typesafe.config.Config = Config(SimpleConfigObject(... "default-dispatcher" ... )
scala> val system = ActorSystem("ArteciateActorSystem", config)
system: akka.actor.ActorSystem = akka://ArteciateActorSystem
scala> system.dispatcher.toString
res7: String = Dispatcher[akka.actor.default-dispatcher]
请注意,我已将 Config
中的代码删减到相关部分,您得到的内容要冗长得多。
您始终可以从 Actor 内部打印线程名称,因为线程池(由调度程序使用)将具有适当的名称,您应该能够确定它是否在您期望的调度程序上 运行ning 运行。
class CheckingThread extends Actor {
def receive = {
case _ =>
println(s"Using thread: ${Thread.currentThread().getName}")
// or reply with it: sender() ! Thread.currentThread().getName
}
}
您也可以通过打开 visual vm 或您喜欢/可用的任何 jvm 分析器来调查 运行ning 线程。