簡體   English   中英

Akka演員阻止消息

[英]Akka actors blocking messages

嗨,由於我無法正確解決問題,這可能不是我所提問題的正確標題,但實際情況是這樣;

演員A創建演員B1,而演員B1創建負責執行任務的“ n”個演員。 因此,A是B1的父級,而B1是b1,b2,b3,...的父級。

在A中,我安排了一個股票行情,以便A每10秒檢查一次是否有新的B'要創建。

Duration duration = Duration.create(10 sec.);
FiniteDuration interval = new FiniteDuration(duration.toMillis(), TimeUnit.MILLISECONDS);
ticker = getContext().system().scheduler().schedule(interval, interval, getSelf(), new Tick() { }, getContext().dispatcher(), getSelf());

在前端,我可以調整“ b”個任務的並行度。 例如,如果我將並行度設置為3,則B(1)創建3個actor,每個actor執行某個任務,如果一個actor,使b(n)結束,則創建b(n + 1),依此類推。

問題是 ;

如果只有一個由演員“ B'”創建的演員b(i = 1)(該B不重要),則記號器會每10秒真正滴答一聲,但是如果我將b的平行度提高到64 b (i = 64),則股票行情不會表現得很好。 它等待相當長的時間,例如1分鍾。 然后滴答作響6次,好像有一個沖洗機械。

當我增加系統參與者的數量時,這不是我遇到的唯一問題。

我有一個api,以便用戶將訂單發送給演員,如下所示

String path = ActorPaths.actorPathForPlan(plan);
ActorSelection actorSelection = runtimeInit.getSystem().actorSelection(path);
// ask
Timeout timeout = new Timeout(Duration.create(4*1000, TimeUnit.MILLISECONDS));
Future<Object> future = Patterns.ask(actorSelection, message, timeout);
// get result
return returnType.cast(Await.result(future, timeout.duration()));

當大約有10個參與者時,期貨總是超時,但是當我調試代碼時,我看到消息已接收,但是經過了很長一段時間。

因此,我想知道是什么阻止了Actor A接收消息。 同樣的問題可能發生在演員B'及其孩子中,但我尚未檢查過,但是如果我發現問題,我相信我可以將解決方案應用於其他對象。

感謝您的任何建議。

層次結構是這樣的

http://i.stack.imgur.com/PRmwE.png

默認情況下,所有Akka參與者都使用同一執行器,該執行器最多只能使用64個線程。 http://doc.akka.io/docs/akka/snapshot/general/configuration.html

# This will be used if you have set "executor = "default-executor"".
      # If an ActorSystem is created with a given ExecutionContext, this
      # ExecutionContext will be used as the default executor for all
      # dispatchers in the ActorSystem configured with
      # executor = "default-executor". Note that "default-executor"
      # is the default value for executor, and therefore used if not
      # specified otherwise. If no ExecutionContext is given,
      # the executor configured in "fallback" will be used.
      default-executor {
        fallback = "fork-join-executor"
      }

      # This will be used if you have set "executor = "fork-join-executor""
      fork-join-executor {
        # Min number of threads to cap factor-based parallelism number to
        parallelism-min = 8

        # The parallelism factor is used to determine thread pool size using the
        # following formula: ceil(available processors * factor). Resulting size
        # is then bounded by the parallelism-min and parallelism-max values.
        parallelism-factor = 3.0

        # Max number of threads to cap factor-based parallelism number to
        parallelism-max = 64
      }

問題可能與阻止b * actor中的調用有關。 Akka從64個池中分配單獨的線程來處理b * actor中的這些阻塞調用,並等待它們中的一個完成消息處理,以便能夠處理A和B的消息。

有關如何解決此問題的想法,請參閱http://doc.akka.io/docs/akka/snapshot/general/actor-systems.html中的 “阻止需要仔細管理”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM