Akka路由器的重要性
Importance of Akka Routers
我对 Akka
路由器的重要性一直存疑。我在当前正在进行的项目中使用了 Akka 路由器。但是,我对它的重要性有点困惑。在以下两种方法中,哪种方法更有益。
- 有路由器和路由。
- 根据需要创建尽可能多的演员。
我了解到路由器会根据策略在其路由之间分配传入消息。另外,我们可以有基于路由器的监管策略。
我还了解到 actor 也是轻量级的,创建尽可能多的 actor 并不是开销。因此,我们可以为每个传入消息创建 actor,并在处理 si 完成后根据需要将其杀死。
所以我想了解一下以上设计哪个更好?或者换句话说,在这种情况下 (1) 比 (2) 有优势,反之亦然。
好问题。在阅读 Akka 文档之前,我也有过类似的疑惑。原因如下:
效率。来自 docs:
On the surface routers look like normal actors, but they are actually
implemented differently. Routers are designed to be extremely
efficient at receiving messages and passing them quickly on to
routees.
A normal actor can be used for routing messages, but an actor's
single-threaded processing can become a bottleneck. Routers can
achieve much higher throughput with an optimization to the usual
message-processing pipeline that allows concurrent routing. This is
achieved by embedding routers' routing logic directly in their
ActorRef rather than in the router actor. Messages sent to a router's
ActorRef can be immediately routed to the routee, bypassing the
single-threaded router actor entirely.
The cost to this is, of course, that the internals of routing code are
more complicated than if routers were implemented with normal actors.
Fortunately all of this complexity is invisible to consumers of the
routing API. However, it is something to be aware of when implementing
your own routers.
多个路由策略的默认实现。您可以随时编写自己的代码,但这可能会很棘手。你要兼顾监管、恢复、负载均衡、远程部署等
Akka 路由器模式将熟悉 Akka 用户。如果您推出自定义路由,那么每个人都将不得不花时间了解所有极端情况和影响(+ 测试?:))。
TL;DR 如果您不太关心效率并且如果您更容易产生新演员,那就去做吧。否则使用路由器。
我对 Akka
路由器的重要性一直存疑。我在当前正在进行的项目中使用了 Akka 路由器。但是,我对它的重要性有点困惑。在以下两种方法中,哪种方法更有益。
- 有路由器和路由。
- 根据需要创建尽可能多的演员。
我了解到路由器会根据策略在其路由之间分配传入消息。另外,我们可以有基于路由器的监管策略。 我还了解到 actor 也是轻量级的,创建尽可能多的 actor 并不是开销。因此,我们可以为每个传入消息创建 actor,并在处理 si 完成后根据需要将其杀死。
所以我想了解一下以上设计哪个更好?或者换句话说,在这种情况下 (1) 比 (2) 有优势,反之亦然。
好问题。在阅读 Akka 文档之前,我也有过类似的疑惑。原因如下:
效率。来自 docs:
On the surface routers look like normal actors, but they are actually implemented differently. Routers are designed to be extremely efficient at receiving messages and passing them quickly on to routees.
A normal actor can be used for routing messages, but an actor's single-threaded processing can become a bottleneck. Routers can achieve much higher throughput with an optimization to the usual message-processing pipeline that allows concurrent routing. This is achieved by embedding routers' routing logic directly in their ActorRef rather than in the router actor. Messages sent to a router's ActorRef can be immediately routed to the routee, bypassing the single-threaded router actor entirely.
The cost to this is, of course, that the internals of routing code are more complicated than if routers were implemented with normal actors. Fortunately all of this complexity is invisible to consumers of the routing API. However, it is something to be aware of when implementing your own routers.
多个路由策略的默认实现。您可以随时编写自己的代码,但这可能会很棘手。你要兼顾监管、恢复、负载均衡、远程部署等
Akka 路由器模式将熟悉 Akka 用户。如果您推出自定义路由,那么每个人都将不得不花时间了解所有极端情况和影响(+ 测试?:))。
TL;DR 如果您不太关心效率并且如果您更容易产生新演员,那就去做吧。否则使用路由器。