29. A bit more about the hierarchy
ヒエラルキーの最上位はどうなっているか…
「guardianと呼ばれる」3つの特別なアクター
- root guardian
- user guardian
- system guardian
30. A bit more about the hierarchy
・user guardian
system.actorOf()を使って生成されるアクター達のトップ
⇒作ったアクターがハンドリングできなかったエラーは最終的にここに来る
SupervisorStrategyは、akka.actor.guardian-supervisor-startegyで上書きできる
32. A bit more about the hierarchy
・system guardian
user-levelのアクターが必要とするサービスを提供(順番にshut-downさせるとか)
user guardiaをwatchしてる
・root guardian
ヒエラルキーのトップに存在して、guardianからEscalateされたエラーを処理する
33. A bit more about the hierarchy
root guardianもアクターなので、supervisorが必要
⇒ActorSystemの外側に、疑似アクターのsupervisorが居る
どんなエラーが起きても、子アクター(root guardian)をStopさせる。
34. Guidelines for handling failures
・危険な処理を隔離して、エラーが起きても良い設計にしよう!
・error kernel pattern…エラーハンドリングを、発生する場所の近くに分散させる
例:DBとのやりとりは、別のアクターにする
35. Guidlines for handling failures
・更なるアプローチとして
特定の役割を持ったアクターと、supervisorをセットで作る
危険な仕事をするアクター + そのアクターを監視するアクター
ロジックを抽象化できる
System
count = 3Request
{“count”:3}
Child
Actor
Supervise
SupervisorStorategy
38. The basics of routers
・Routerは、アクターへのメッセージの流れを制御する
アクターのグループへ、ルールに従ってメッセージを送信する
・Routerは一応アクターだが、Mailboxやメッセージハンドリングは使わない
Router
Routees
Other Actor
39. The basics of routers
Routerの用途
負荷分散したい
少ないリソースを効率的に使いたい
少しでも速く処理したい(後述)
etc
40. The basics of routers
senderについての細かい話
Router
Routees
Other Actor
sender.tell(SomeMessage())
41. The basics of routers
送信元はRouteeなので、返事がRouteeに来てしまう
Router
Routees
Other Actor
sender.tell(SomeMessage())
sender.tell(ResponseMessage())
42. The basics of routers
送信元を親(Router)にすると…
Router
Routees
Other Actor
sender.tell(SomeMessage(),context.parent)
第二引数で送信元を指定
43. The basics of routers
Routerに送信され、いずれかのRouteeに送信される
Router
Routees
Other Actor
sender.tell(ResponseMessage())
sender.tell(SomeMessage(),context.parent)