Akka:我应该在 actor 中使用 parallelStream 还是 executors
Akka: Should I use parallelStream or executors in an actor
我是 Akka actor 模型的新手。据我了解,akka 提供了对并行性和并发性的抽象。话虽如此,我觉得通过 parallelStream 或 actor 本身的执行器框架进行并发是不对的,想知道这是否是一种反模式。另外,这是否意味着 actor 中的所有代码总是顺序的?
如果你指的是Java本身的并行流,那么"likely not"。特别是因为大多数 "get results" 操作都是阻塞的,所以你会被迫在 Actor 中阻塞,这确实是一种反模式(阅读这里:blocking needs careful management)。
但是您可以使用 Akka Streams inside Actors more freely, this is because all of their operations offload the work to a separate dispatcher, so it won't block the Actor. They're also more configurable and offer connectors to various tech, and integrate well Actors themselves.
我是 Akka actor 模型的新手。据我了解,akka 提供了对并行性和并发性的抽象。话虽如此,我觉得通过 parallelStream 或 actor 本身的执行器框架进行并发是不对的,想知道这是否是一种反模式。另外,这是否意味着 actor 中的所有代码总是顺序的?
如果你指的是Java本身的并行流,那么"likely not"。特别是因为大多数 "get results" 操作都是阻塞的,所以你会被迫在 Actor 中阻塞,这确实是一种反模式(阅读这里:blocking needs careful management)。
但是您可以使用 Akka Streams inside Actors more freely, this is because all of their operations offload the work to a separate dispatcher, so it won't block the Actor. They're also more configurable and offer connectors to various tech, and integrate well Actors themselves.