私はこの秋に分散システムのクラスを受講していますが、Scalaアクターはこの分野で非常に役立つので、Scalaの学習を始めたばかりです。「ActorsinScala」というテキストの俳優についてこれまで読んだことから、テキストではあまり明確に取り上げられていないように思われる質問があります。
現在、マルチコアプロセッサを搭載した単一のマシンでプログラムをモデル化し、Master-Workersモデルでイベントベースのアクターを使用しています。次の2つの設計上の選択のうち、すべてのプロセッサコアが最適に使用されるようになるのはどれですか?
1)マスターアクターが持つジョブの数に関係なく、アクターの数を少数の固定数に制限して、ワーカーアクターに配布します(ちなみに、これはかなり大きい場合があります)
2)マスターアクターが完了する必要のあるジョブの数と同じ数のアクターを生成します
上記の2つの選択肢に対する私の決定を左右する要因は何ですか?
更新:実行している100人のワーカーアクターのスレッドIDを出力しました。これが出力です-
No. of Processors-2
MainActor is on thread:Thread[ForkJoinPool-1-worker-0,5,main]
AccumulatorActor is on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-1 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-4 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-5 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-6 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-7 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-8 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-9 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-10 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-3 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-12 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-13 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-14 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-15 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-2 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-16 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-11 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-17 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-18 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-19 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-20 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-21 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-22 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-23 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-24 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-25 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-26 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-28 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-29 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-27 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-30 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-31 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-33 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-32 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-34 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-35 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-36 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-38 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-39 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-40 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-41 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-42 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-43 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-44 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-45 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-46 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-47 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-48 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-51 running on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-50 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-54 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-49 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-56 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-57 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-58 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-55 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-59 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-52 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-61 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-60 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-63 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-53 running on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-65 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-66 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-68 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-64 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-62 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-70 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-69 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-67 running on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-72 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-73 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-71 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-75 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-78 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-79 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-80 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-81 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-82 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-83 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-74 running on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-84 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-85 running on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-77 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-76 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-86 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-87 running on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-88 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-89 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-91 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-92 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-94 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-95 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
Worker Actor-96 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-90 running on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-98 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-99 running on thread:Thread[ForkJoinPool-1-worker-1,5,main]
Worker Actor-100 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-93 running on thread:Thread[ForkJoinPool-1-worker-2,5,main]
Worker Actor-37 running on thread:Thread[ForkJoinPool-1-worker-0,5,main]
Worker Actor-97 running on thread:Thread[ForkJoinPool-1-worker-3,5,main]
上記のように、ForkJoinPoolでは4つのワーカースレッドが実行されていますが、マシンには2つのCPUコアがあります。ResizableThreadPoolSchedulerのソースをざっと見てみると、最初はプール内のワーカースレッドの数がCPUコアの数に等しく、いずれかのアクターの場合に動的に増加すると信じているため、これがなぜであるかはわかりません。プール内のワーカースレッドの1つでブロックされています。私が使用するすべてのアクターはイベントベース(react)であり、ブロッキング操作を実行しません。理想的なシナリオは、ForkJoinPoolに2つのスレッドを配置し、各アクターの作業を実行する2つのコアでそれらを並列に実行することです。これについての私の理解は正しいですか、それともここで何かが欠けていますか?