简体   繁体   English

Akka封锁要求会封锁其他演员吗?

[英]Does an Akka Blocking Request Block Other Actors?

Say we have: 说我们有:

  • Thread 1 containing Actors A, B, and C. 线程1包含Actor A,B和C。
  • Thread 2 containing Actor Y. 线程2包含ActorY。
  • Thread 3 containing Actor Z. 线程3包含ActorZ。
  • Actors A and B are listening for messages from Actor Y. 演员A和演员B正在监听演员Y的消息。

Actor C then makes a blocking request to Actor Z. 然后,演员C向演员Z发出阻止请求。

Before the request returns, Actor Y sends a few messages to Actors A and B. 在请求返回之前,Actor Y向Actor A和B发送一些消息。

Can Actors A and B receive the messages before Actor C completes? 演员A和B可以在演员C完成之前收到消息吗?

Or is it a must that Actor C complete before Actors A and B can receive the messages? 还是演员A和B可以接收到消息之前,演员C 必须完成?

I included Actor Y to allow the possibility of it sending messages while Z is processing the request from C. 我包括Actor Y,以允许它在Z处理来自C的请求时发送消息的可能性。

All threads are on different physical cores - they run in parallel. 所有线程都在不同的物理核心上-它们并行运行。

Actor may process a message from queue on any thread - they are not pinned to concrete threads by default (if you don't use pinned dispatcher). Actor可以在任何线程上处理队列中的消息-默认情况下,它们不会固定在具体线程上(如果您不使用固定分配器)。 Simply saying different messages from same queue may be processed on different threads (choosed by dispatcher). 简单地说,来自同一队列的不同消息可能在不同的线程上处理(由调度程序选择)。

I suppose that by "thread containg actor" you mean containg in one or several moments (messages) of time. 我想用“线程容器参与者”来指的是在一到几个时刻(消息)内的容器。 Because dispatcher is free (by default) to choose any thread for any message of any actor/mailbox. 因为调度程序是自由的(默认情况下),所以可以为任何参与者/邮箱的任何消息选择任何线程。 In practice it may choose the same thread sometimes but not always. 实际上,它有时会选择相同的线程,但并非总是如此。

So, if one thread is blocked, dispatcher (by default) goes to another. 因此,如果一个线程被阻止,调度程序(默认情况下)将转到另一个线程。 A and B may receive messages before C completes if you have enough threads. 如果您有足够的线程,则AB可能会在C完成之前收到消息。

However, blocking itself is a bad practice for Akka ( Blocking Needs Careful Management ). 但是,阻塞本身对Akka来说是个坏习惯( 阻塞需要仔细的管理 )。

Let it be reactive! 让它反应!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM