我正在尝试将数据保存到数据库中。我的保存方法是异步的。
class MyActor(persistenceFactory:PersistenceFactory) extends Actor {
def receive: Receive = {
case record: Record =>
// this method is asynchronous, immediate return Future[Int]
persistenceFactory.persist(record)
}
}
瓶颈出现在这里,当应用程序在增加负载下运行时,我们要么会耗尽内存,要么没有可用的线程。
那么,在Akka actor的receive方法内处理异步调用的最佳方式是什么?
persist
是做什么的?它是否接受隐式的ExecutionContext
? - Yuval ItzchakovExecutionContext
?你能展示一下代码吗? - Yuval Itzchakov