Akka Acto官方文档笔记

Akka Acto官方文档笔记

Akka Actor 2.3.9 官方文档笔记:

  • x

2.2节

An ActorSystem is a heavyweight structure that will allocate 1. . . N Threads,
 so create one per logical application.

ActorSystem 拥有重量级结构,可以分配N个线程,所以在一个逻辑程序中只使用一个ActorSystem。

2.2.1 层级结构
Actor的精髓就是将大任务分成足够小的可执行任务,一层一层分割下去。
建议使用的管理策略是:

  • 如果一个Actor(Manager)管理着别的Actor正在做的工作,即通过传递子任务给别的Actor(子Actor),那么Manager应该监管子Actor。理由是Manage知道有哪些失败情况且知道如何处理。
  • 如果一个Actor带有非常重要的数据,(即这个Actor的状态不应该丢失,如果可以避免的话),这个Actor应该将非常危险的子任务外包给能够监管的子Actor,且能够正确处理子Actor遇到的错误。当有请求要处理时,应该基于请求的本质,给每个请求创立新的子Actor。这样简化了收集回复时的状态管理。这种模式在Erlang语言中叫做“Error Kernel Patten”。

    2.2.4 Blocking Needs Careful Management

    In some cases it is unavoidable to do blocking operations.The non-exhaustive list of adequate solutions to the “blocking problem” includes the following suggestions:

  • If one actor depends on another actor for carrying out its duty, it should watch that other actor’s liveness
    and act upon receiving a termination notice. This is different from supervision, as the watching party has
    no influence on the supervisor strategy, and it should be noted that a functional dependency alone is not a
    criterion for deciding where to place a certain child actor in the hierarchy.

• Do the blocking call within an actor (or a set of actors managed by a router [Java, Scala]), making sure to
configure a thread pool which is either dedicated for this purpose or sufficiently sized.
• Do the blocking call within a Future, ensuring an upper bound on the number of such calls at any point in
time (submitting an unbounded number of tasks of this nature will exhaust your memory or thread limits).
• Do the blocking call within a Future, providing a thread pool with an upper limit on the number of threads which is appropriate for the hardware on which the application runs

`


猜你喜欢

转载自blog.csdn.net/innersense/article/details/48324875