Scaling software with akka
-
Upload
scalaconfjp -
Category
Documents
-
view
2.499 -
download
1
description
Transcript of Scaling software with akka
![Page 1: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/1.jpg)
Jonas BonérCTO Typesafe
Twitter : @jboner
Scaling software with
Akka: ソフトウェアをスケールさせる
![Page 2: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/2.jpg)
Scaling software withScaling software with
![Page 3: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/3.jpg)
Scaling software withScaling software with
Copyright Ingeborg van Leeuwen
![Page 4: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/4.jpg)
Selection of Akka Production Users
![Page 5: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/5.jpg)
![Page 6: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/6.jpg)
![Page 7: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/7.jpg)
Manage System Overload
システムの過負荷を管理する
![Page 8: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/8.jpg)
Automatic Replication & Distribution
for Fault-tolerance & Scalability
耐障害性とスケーラビリティを自動的に実現
![Page 9: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/9.jpg)
Program at a Higher Level
高レベルプログラミング
![Page 10: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/10.jpg)
Program at a Higher Level
高レベルプログラミング
![Page 11: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/11.jpg)
Program at a Higher Level• Never think in terms of shared state, state
visibility, threads, locks, concurrent collections, thread notifications etc.
高レベルプログラミング
![Page 12: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/12.jpg)
Program at a Higher Level• Never think in terms of shared state, state
visibility, threads, locks, concurrent collections, thread notifications etc.
• Low level concurrency plumbing BECOMES SIMPLE WORKFLOW - you only think about how messages flow in the system
高レベルプログラミング
![Page 13: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/13.jpg)
Program at a Higher Level• Never think in terms of shared state, state
visibility, threads, locks, concurrent collections, thread notifications etc.
• Low level concurrency plumbing BECOMES SIMPLE WORKFLOW - you only think about how messages flow in the system
• You get high CPU utilization, low latency, high throughput and scalability - FOR FREE as part of the model
高レベルプログラミング
![Page 14: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/14.jpg)
Program at a Higher Level• Never think in terms of shared state, state
visibility, threads, locks, concurrent collections, thread notifications etc.
• Low level concurrency plumbing BECOMES SIMPLE WORKFLOW - you only think about how messages flow in the system
• You get high CPU utilization, low latency, high throughput and scalability - FOR FREE as part of the model
• Proven and superior model for detecting and recovering from errors
高レベルプログラミング
![Page 15: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/15.jpg)
Distributable by Design
生まれながらに分散化されている
![Page 16: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/16.jpg)
Distributable by Design
生まれながらに分散化されている
![Page 17: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/17.jpg)
Distributable by Design• Actors are location transparent & distributable by design
生まれながらに分散化されている
![Page 18: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/18.jpg)
Distributable by Design• Actors are location transparent & distributable by design
• Scale UP and OUT for free as part of the model
生まれながらに分散化されている
![Page 19: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/19.jpg)
Distributable by Design• Actors are location transparent & distributable by design
• Scale UP and OUT for free as part of the model
• You get the PERFECT FABRIC for the CLOUD
生まれながらに分散化されている
![Page 20: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/20.jpg)
Distributable by Design• Actors are location transparent & distributable by design
• Scale UP and OUT for free as part of the model
• You get the PERFECT FABRIC for the CLOUD
- elastic & dynamic
生まれながらに分散化されている
![Page 21: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/21.jpg)
Distributable by Design• Actors are location transparent & distributable by design
• Scale UP and OUT for free as part of the model
• You get the PERFECT FABRIC for the CLOUD
- elastic & dynamic
- fault-tolerant & self-healing
生まれながらに分散化されている
![Page 22: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/22.jpg)
Distributable by Design• Actors are location transparent & distributable by design
• Scale UP and OUT for free as part of the model
• You get the PERFECT FABRIC for the CLOUD
- elastic & dynamic
- fault-tolerant & self-healing
- adaptive load-balancing, cluster rebalancing & actor migration
生まれながらに分散化されている
![Page 23: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/23.jpg)
Distributable by Design• Actors are location transparent & distributable by design
• Scale UP and OUT for free as part of the model
• You get the PERFECT FABRIC for the CLOUD
- elastic & dynamic
- fault-tolerant & self-healing
- adaptive load-balancing, cluster rebalancing & actor migration
- build extremely loosely coupled and dynamic systems that can change and adapt at runtime
生まれながらに分散化されている
![Page 24: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/24.jpg)
How can we achieve this?
これをどうやって実現するか?
![Page 25: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/25.jpg)
How can we achieve this?
アクターを使おう
![Page 26: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/26.jpg)
How can we achieve this?
Let’s use Actors
アクターを使おう
![Page 27: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/27.jpg)
What is an Actor?
コードを分割して、並行性、スケーラビリティ、耐障害性の高いアプリケーションを支援する
![Page 28: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/28.jpg)
What is an Actor?• Akka's unit of code organization is called an Actor
コードを分割して、並行性、スケーラビリティ、耐障害性の高いアプリケーションを支援する
![Page 29: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/29.jpg)
What is an Actor?• Akka's unit of code organization is called an Actor
• Actors helps you create concurrent, scalable and fault-tolerant applications
コードを分割して、並行性、スケーラビリティ、耐障害性の高いアプリケーションを支援する
![Page 30: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/30.jpg)
What is an Actor?• Akka's unit of code organization is called an Actor
• Actors helps you create concurrent, scalable and fault-tolerant applications
• Like Java EE servlets and session beans, Actors is a model for organizing your code that keeps many “policy decisions” separate from the business logic
コードを分割して、並行性、スケーラビリティ、耐障害性の高いアプリケーションを支援する
![Page 31: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/31.jpg)
What is an Actor?• Akka's unit of code organization is called an Actor
• Actors helps you create concurrent, scalable and fault-tolerant applications
• Like Java EE servlets and session beans, Actors is a model for organizing your code that keeps many “policy decisions” separate from the business logic
• Actors may be new to many in the Java community, but they are a tried-and-true concept (Hewitt 1973) used for many years in telecom systems with 9 nines uptime
コードを分割して、並行性、スケーラビリティ、耐障害性の高いアプリケーションを支援する
![Page 32: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/32.jpg)
What can I use Actors for?
スレッド、コンポーネント、コールバックなどの代替
![Page 33: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/33.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to:
スレッド、コンポーネント、コールバックなどの代替
![Page 34: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/34.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to: - a thread
スレッド、コンポーネント、コールバックなどの代替
![Page 35: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/35.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to: - a thread
- an object instance or component
スレッド、コンポーネント、コールバックなどの代替
![Page 36: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/36.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to: - a thread
- an object instance or component
- a callback or listener
スレッド、コンポーネント、コールバックなどの代替
![Page 37: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/37.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to: - a thread
- an object instance or component
- a callback or listener
- a singleton or service
スレッド、コンポーネント、コールバックなどの代替
![Page 38: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/38.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to: - a thread
- an object instance or component
- a callback or listener
- a singleton or service
- a router, load-balancer or pool
スレッド、コンポーネント、コールバックなどの代替
![Page 39: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/39.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to: - a thread
- an object instance or component
- a callback or listener
- a singleton or service
- a router, load-balancer or pool
- a Java EE Session Bean or Message-Driven Bean
スレッド、コンポーネント、コールバックなどの代替
![Page 40: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/40.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to: - a thread
- an object instance or component
- a callback or listener
- a singleton or service
- a router, load-balancer or pool
- a Java EE Session Bean or Message-Driven Bean
- an out-of-process service
スレッド、コンポーネント、コールバックなどの代替
![Page 41: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/41.jpg)
What can I use Actors for?In different scenarios, an Actor may be an alternative to: - a thread
- an object instance or component
- a callback or listener
- a singleton or service
- a router, load-balancer or pool
- a Java EE Session Bean or Message-Driven Bean
- an out-of-process service
- a Finite State Machine (FSM)
スレッド、コンポーネント、コールバックなどの代替
![Page 42: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/42.jpg)
So, what is theActor Model?
アクターモデルとは何か?
![Page 43: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/43.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 44: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/44.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
- The fundamental unit of computation that embodies:
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 45: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/45.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
- The fundamental unit of computation that embodies:
- Processing
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 46: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/46.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
- The fundamental unit of computation that embodies:
- Processing
- Storage
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 47: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/47.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
- The fundamental unit of computation that embodies:
- Processing
- Storage
- Communication
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 48: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/48.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
- The fundamental unit of computation that embodies:
- Processing
- Storage
- Communication
- 3 axioms - When an Actor receives a message it can:
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 49: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/49.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
- The fundamental unit of computation that embodies:
- Processing
- Storage
- Communication
- 3 axioms - When an Actor receives a message it can:
- Create new Actors
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 50: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/50.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
- The fundamental unit of computation that embodies:
- Processing
- Storage
- Communication
- 3 axioms - When an Actor receives a message it can:
- Create new Actors
- Send messages to Actors it knows
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 51: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/51.jpg)
Carl Hewitt’s definition
http://bit.ly/hewitt-on-actors
- The fundamental unit of computation that embodies:
- Processing
- Storage
- Communication
- 3 axioms - When an Actor receives a message it can:
- Create new Actors
- Send messages to Actors it knows
- Designate how it should handle the next message it receives
処理、記憶、通信を行う基礎単位。受信時の 3公理:新規作成、他のアクターとの通信、次のメッセージ処理の指定
![Page 52: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/52.jpg)
4 core Actor operations
0. DEFINE1. CREATE2. SEND3. BECOME4. SUPERVISE
アクターの4つの主な仕事
![Page 53: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/53.jpg)
0. DEFINE
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
処理可能なメッセージ、振る舞いの定義
![Page 54: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/54.jpg)
0. DEFINEDefine the message(s) the Actor
should be able to respond to
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
処理可能なメッセージ、振る舞いの定義
![Page 55: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/55.jpg)
0. DEFINEDefine the message(s) the Actor
should be able to respond to
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
Define the Actor class
処理可能なメッセージ、振る舞いの定義
![Page 56: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/56.jpg)
0. DEFINEDefine the message(s) the Actor
should be able to respond to
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
Define the Actor class
Define the Actor’s behavior
処理可能なメッセージ、振る舞いの定義
![Page 57: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/57.jpg)
1. CREATE• CREATE - creates a new instance of an Actor
• Extremely lightweight (2.7 Million per Gb RAM)
• Very strong encapsulation - encapsulates:
- state
- behavior
- message queue
• State & behavior is indistinguishable from each other
• Only way to observe state is by sending an actor a message and see how it reacts
新規アクターの作成。強力なカプセル化。メッセージを送ってその反応を見て状態を観測する。
![Page 58: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/58.jpg)
CREATE Actorcase class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
ActorRef が返ってくる
![Page 59: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/59.jpg)
CREATE Actorcase class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
Create an Actor system
ActorRef が返ってくる
![Page 60: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/60.jpg)
CREATE Actorcase class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
Create an Actor system Actor configuration
ActorRef が返ってくる
![Page 61: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/61.jpg)
CREATE Actorcase class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
Give it a name
Create an Actor system Actor configuration
ActorRef が返ってくる
![Page 62: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/62.jpg)
CREATE Actor
Create the Actor
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
Give it a name
Create an Actor system Actor configuration
ActorRef が返ってくる
![Page 63: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/63.jpg)
CREATE Actor
Create the Actor
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
Give it a nameYou get an ActorRef back
Create an Actor system Actor configuration
ActorRef が返ってくる
![Page 64: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/64.jpg)
Guardian System Actor
Actors can form hierarchies
階層構造を作ることができる
![Page 65: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/65.jpg)
Guardian System Actor
system.actorOf(Props[Foo], “Foo”)
Actors can form hierarchies
階層構造を作ることができる
![Page 66: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/66.jpg)
Foo
Guardian System Actor
system.actorOf(Props[Foo], “Foo”)
Actors can form hierarchies
階層構造を作ることができる
![Page 67: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/67.jpg)
Foo
Guardian System Actor
context.actorOf(Props[A], “A”)
Actors can form hierarchies
階層構造を作ることができる
![Page 68: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/68.jpg)
A
Foo
Guardian System Actor
context.actorOf(Props[A], “A”)
Actors can form hierarchies
階層構造を作ることができる
![Page 69: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/69.jpg)
A
B
BarFoo
C
BE
A
D
C
Guardian System Actor
Actors can form hierarchies
階層構造を作ることができる
![Page 70: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/70.jpg)
A
B
BarFoo
C
BE
A
D
C
Guardian System Actor
Name resolution - like a file-system
ファイルシステムのような名前解決
![Page 71: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/71.jpg)
A
B
BarFoo
C
BE
A
D
C
/Foo
Guardian System Actor
Name resolution - like a file-system
ファイルシステムのような名前解決
![Page 72: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/72.jpg)
A
B
BarFoo
C
BE
A
D
C
/Foo
/Foo/A
Guardian System Actor
Name resolution - like a file-system
ファイルシステムのような名前解決
![Page 73: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/73.jpg)
A
B
BarFoo
C
BE
A
D
C
/Foo
/Foo/A
/Foo/A/B
Guardian System Actor
Name resolution - like a file-system
ファイルシステムのような名前解決
![Page 74: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/74.jpg)
A
B
BarFoo
C
BE
A
D
C
/Foo
/Foo/A
/Foo/A/B
/Foo/A/D
Guardian System Actor
Name resolution - like a file-system
ファイルシステムのような名前解決
![Page 75: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/75.jpg)
2. SEND
非同期でノンブロッキングなメッセージの送信
![Page 76: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/76.jpg)
2. SEND• SEND - sends a message to an Actor
非同期でノンブロッキングなメッセージの送信
![Page 77: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/77.jpg)
2. SEND• SEND - sends a message to an Actor
• Asynchronous and Non-blocking - Fire-forget
非同期でノンブロッキングなメッセージの送信
![Page 78: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/78.jpg)
2. SEND• SEND - sends a message to an Actor
• Asynchronous and Non-blocking - Fire-forget
• EVERYTHING is asynchronous and lockless
非同期でノンブロッキングなメッセージの送信
![Page 79: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/79.jpg)
2. SEND• SEND - sends a message to an Actor
• Asynchronous and Non-blocking - Fire-forget
• EVERYTHING is asynchronous and lockless
• Everything happens Reactively
非同期でノンブロッキングなメッセージの送信
![Page 80: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/80.jpg)
2. SEND• SEND - sends a message to an Actor
• Asynchronous and Non-blocking - Fire-forget
• EVERYTHING is asynchronous and lockless
• Everything happens Reactively
- An Actor is passive until a message is sent to it, which triggers something within the Actor
非同期でノンブロッキングなメッセージの送信
![Page 81: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/81.jpg)
2. SEND• SEND - sends a message to an Actor
• Asynchronous and Non-blocking - Fire-forget
• EVERYTHING is asynchronous and lockless
• Everything happens Reactively
- An Actor is passive until a message is sent to it, which triggers something within the Actor
- Messages is the Kinetic Energy in an Actor system
非同期でノンブロッキングなメッセージの送信
![Page 82: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/82.jpg)
2. SEND• SEND - sends a message to an Actor
• Asynchronous and Non-blocking - Fire-forget
• EVERYTHING is asynchronous and lockless
• Everything happens Reactively
- An Actor is passive until a message is sent to it, which triggers something within the Actor
- Messages is the Kinetic Energy in an Actor system
- Actors can have lots of buffered Potential Energy but can't do anything with it until it is triggered by a message
非同期でノンブロッキングなメッセージの送信
![Page 83: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/83.jpg)
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")greeter ! Greeting("Charlie Parker")
SEND message
![Page 84: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/84.jpg)
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")greeter ! Greeting("Charlie Parker")
SEND message
Send the message
![Page 85: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/85.jpg)
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging { def receive = { case Greeting(who) => log.info("Hello " + who) }}
val system = ActorSystem("MySystem")val greeter = system.actorOf(Props[GreetingActor], name = "greeter")greeter ! Greeting("Charlie Parker")
Full example
![Page 86: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/86.jpg)
Load Balancing
![Page 87: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/87.jpg)
Routers
![Page 88: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/88.jpg)
Routers
val router = system.actorOf( Props[SomeActor].withRouter( RoundRobinRouter(nrOfInstances = 5)))
ルータを使う
![Page 89: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/89.jpg)
Router + Resizer
val resizer = DefaultResizer(lowerBound = 2, upperBound = 15)
val router = system.actorOf( Props[ExampleActor1].withRouter( RoundRobinRouter(resizer = Some(resizer))))
リサイザを加える
![Page 90: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/90.jpg)
…or from config akka.actor.deployment { /path/to/actor { router = round-robin nr-of-instances = 5 } }
config ファイルからも設定できる
![Page 91: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/91.jpg)
…or from config akka.actor.deployment { /path/to/actor { router = round-robin resizer { lower-bound = 12 upper-bound = 15 } } }
もしくは設定から
![Page 92: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/92.jpg)
3. BECOME
動的にアクターの振る舞いを再定義振る舞いはスタックして push/pop することができる
![Page 93: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/93.jpg)
3. BECOME
• BECOME - dynamically redefines Actor’s behavior
動的にアクターの振る舞いを再定義振る舞いはスタックして push/pop することができる
![Page 94: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/94.jpg)
3. BECOME
• BECOME - dynamically redefines Actor’s behavior
• Triggered reactively by receive of message
動的にアクターの振る舞いを再定義振る舞いはスタックして push/pop することができる
![Page 95: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/95.jpg)
3. BECOME
• BECOME - dynamically redefines Actor’s behavior
• Triggered reactively by receive of message
• In a type system analogy it is as if the object changed type - changed interface, protocol & implementation
動的にアクターの振る舞いを再定義振る舞いはスタックして push/pop することができる
![Page 96: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/96.jpg)
3. BECOME
• BECOME - dynamically redefines Actor’s behavior
• Triggered reactively by receive of message
• In a type system analogy it is as if the object changed type - changed interface, protocol & implementation
• Will now react differently to the messages it receives
動的にアクターの振る舞いを再定義振る舞いはスタックして push/pop することができる
![Page 97: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/97.jpg)
3. BECOME
• BECOME - dynamically redefines Actor’s behavior
• Triggered reactively by receive of message
• In a type system analogy it is as if the object changed type - changed interface, protocol & implementation
• Will now react differently to the messages it receives
• Behaviors are stacked & can be pushed and popped
動的にアクターの振る舞いを再定義振る舞いはスタックして push/pop することができる
![Page 98: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/98.jpg)
Why would I want to do that?
例) 輻輳時にアクターをルータへ変身、FSM の実装など
![Page 99: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/99.jpg)
Why would I want to do that?• Let a highly contended Actor adaptively transform itself into
an Actor Pool or a Router
例) 輻輳時にアクターをルータへ変身、FSM の実装など
![Page 100: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/100.jpg)
Why would I want to do that?• Let a highly contended Actor adaptively transform itself into
an Actor Pool or a Router
• Implement an FSM (Finite State Machine)
例) 輻輳時にアクターをルータへ変身、FSM の実装など
![Page 101: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/101.jpg)
Why would I want to do that?• Let a highly contended Actor adaptively transform itself into
an Actor Pool or a Router
• Implement an FSM (Finite State Machine)
• Implement graceful degradation
例) 輻輳時にアクターをルータへ変身、FSM の実装など
![Page 102: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/102.jpg)
Why would I want to do that?• Let a highly contended Actor adaptively transform itself into
an Actor Pool or a Router
• Implement an FSM (Finite State Machine)
• Implement graceful degradation
• Spawn up (empty) generic Worker processes that can become whatever the Master currently needs
例) 輻輳時にアクターをルータへ変身、FSM の実装など
![Page 103: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/103.jpg)
Why would I want to do that?• Let a highly contended Actor adaptively transform itself into
an Actor Pool or a Router
• Implement an FSM (Finite State Machine)
• Implement graceful degradation
• Spawn up (empty) generic Worker processes that can become whatever the Master currently needs
• Other: Use your imagination!
例) 輻輳時にアクターをルータへ変身、FSM の実装など
![Page 104: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/104.jpg)
Why would I want to do that?• Let a highly contended Actor adaptively transform itself into
an Actor Pool or a Router
• Implement an FSM (Finite State Machine)
• Implement graceful degradation
• Spawn up (empty) generic Worker processes that can become whatever the Master currently needs
• Other: Use your imagination!
• Very useful once you get the used to it
例) 輻輳時にアクターをルータへ変身、FSM の実装など
![Page 105: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/105.jpg)
become
context become { // new body case NewMessage => ... }
![Page 106: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/106.jpg)
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 107: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/107.jpg)
• You are given a SINGLE thread of control
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 108: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/108.jpg)
• You are given a SINGLE thread of control• If this thread blows up you are screwed
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 109: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/109.jpg)
• You are given a SINGLE thread of control• If this thread blows up you are screwed • So you need to do all explicit error handling WITHIN this
single thread
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 110: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/110.jpg)
• You are given a SINGLE thread of control• If this thread blows up you are screwed • So you need to do all explicit error handling WITHIN this
single thread• To make things worse - errors do not propagate between
threads so there is NO WAY OF EVEN FINDING OUT that something have failed
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 111: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/111.jpg)
• You are given a SINGLE thread of control• If this thread blows up you are screwed • So you need to do all explicit error handling WITHIN this
single thread• To make things worse - errors do not propagate between
threads so there is NO WAY OF EVEN FINDING OUT that something have failed
• This leads to DEFENSIVE programming with:
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 112: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/112.jpg)
• You are given a SINGLE thread of control• If this thread blows up you are screwed • So you need to do all explicit error handling WITHIN this
single thread• To make things worse - errors do not propagate between
threads so there is NO WAY OF EVEN FINDING OUT that something have failed
• This leads to DEFENSIVE programming with:• Error handling TANGLED with business logic
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 113: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/113.jpg)
• You are given a SINGLE thread of control• If this thread blows up you are screwed • So you need to do all explicit error handling WITHIN this
single thread• To make things worse - errors do not propagate between
threads so there is NO WAY OF EVEN FINDING OUT that something have failed
• This leads to DEFENSIVE programming with:• Error handling TANGLED with business logic • SCATTERED all over the code base
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 114: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/114.jpg)
• You are given a SINGLE thread of control• If this thread blows up you are screwed • So you need to do all explicit error handling WITHIN this
single thread• To make things worse - errors do not propagate between
threads so there is NO WAY OF EVEN FINDING OUT that something have failed
• This leads to DEFENSIVE programming with:• Error handling TANGLED with business logic • SCATTERED all over the code base
We can do better than this!!!
Failure Recovery in Java/C/C# etc.
従来のリカバリはスレッドを用いたもの
![Page 115: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/115.jpg)
Just
LET IT CRASH
クラッシュさせろ
![Page 116: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/116.jpg)
クラッシュさせろ
![Page 117: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/117.jpg)
4. SUPERVISE
アクターの故障時は上司の Supervisor が通知され、対応する。通常処理とエラー処理が分離できる。
![Page 118: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/118.jpg)
4. SUPERVISE• SUPERVISE - manage another Actor’s failures
アクターの故障時は上司の Supervisor が通知され、対応する。通常処理とエラー処理が分離できる。
![Page 119: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/119.jpg)
4. SUPERVISE• SUPERVISE - manage another Actor’s failures
• Error handling in actors is handle by letting Actors monitor (supervise) each other for failure
アクターの故障時は上司の Supervisor が通知され、対応する。通常処理とエラー処理が分離できる。
![Page 120: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/120.jpg)
4. SUPERVISE• SUPERVISE - manage another Actor’s failures
• Error handling in actors is handle by letting Actors monitor (supervise) each other for failure
• This means that if an Actor crashes, a notification will be sent to his supervisor, who can react upon the failure
アクターの故障時は上司の Supervisor が通知され、対応する。通常処理とエラー処理が分離できる。
![Page 121: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/121.jpg)
4. SUPERVISE• SUPERVISE - manage another Actor’s failures
• Error handling in actors is handle by letting Actors monitor (supervise) each other for failure
• This means that if an Actor crashes, a notification will be sent to his supervisor, who can react upon the failure
• This provides clean separation of processing and error handling
アクターの故障時は上司の Supervisor が通知され、対応する。通常処理とエラー処理が分離できる。
![Page 122: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/122.jpg)
Fault-tolerant onion-layered Error Kernel
玉ねぎのように階層化された耐障害性
![Page 123: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/123.jpg)
ErrorKernel
![Page 124: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/124.jpg)
ErrorKernel
![Page 125: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/125.jpg)
ErrorKernel
![Page 126: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/126.jpg)
ErrorKernel
![Page 127: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/127.jpg)
ErrorKernel
![Page 128: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/128.jpg)
ErrorKernel
![Page 129: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/129.jpg)
ErrorKernel
Node 1 Node 2
![Page 130: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/130.jpg)
SUPERVISE ActorEvery single actor has a
default supervisor strategy.Which is usually sufficient.But it can be overridden.
デフォルトの Supervisor 戦略をオーバーライドできる
![Page 131: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/131.jpg)
class Supervisor extends Actor { override val supervisorStrategy = (maxNrOfRetries = 10, withinTimeRange = 1 minute) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: Exception => Escalate }
val worker = context.actorOf(Props[Worker])
def receive = { case n: Int => worker forward n }}
SUPERVISE ActorEvery single actor has a
default supervisor strategy.Which is usually sufficient.But it can be overridden.
デフォルトの Supervisor 戦略をオーバーライドできる
![Page 132: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/132.jpg)
class Supervisor extends Actor { override val supervisorStrategy = (maxNrOfRetries = 10, withinTimeRange = 1 minute) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: Exception => Escalate }
val worker = context.actorOf(Props[Worker])
def receive = { case n: Int => worker forward n }}
SUPERVISE Actor
デフォルトの Supervisor 戦略をオーバーライドできる
![Page 133: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/133.jpg)
class Worker extends Actor { ... override def preRestart( reason: Throwable, message: Option[Any]) { ... // clean up before restart } override def postRestart(reason: Throwable) { ... // init after restart }}
Manage failure
故障の管理
![Page 134: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/134.jpg)
Remoting
![Page 135: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/135.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configuration
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 136: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/136.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configuration
Configure a Remote Provider
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 137: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/137.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configuration
Configure a Remote Provider
For the Greeter actor
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 138: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/138.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configuration
Configure a Remote Provider
Define Remote Path
For the Greeter actor
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 139: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/139.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configuration
Configure a Remote Provider
Define Remote Path Protocol
For the Greeter actor
akka://
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 140: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/140.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configuration
Configure a Remote Provider
Define Remote Path Protocol Actor System
For the Greeter actor
akka://MySystem
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 141: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/141.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configuration
Configure a Remote Provider
Define Remote Path Protocol Actor System Hostname
For the Greeter actor
akka://MySystem@machine1
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 142: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/142.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configuration
Configure a Remote Provider
Define Remote Path Protocol Actor System Hostname Port
For the Greeter actor
akka://MySystem@machine1:2552
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 143: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/143.jpg)
akka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = } } }}
Just feed the ActorSystem with this configurationZero code changes
Configure a Remote Provider
Define Remote Path Protocol Actor System Hostname Port
For the Greeter actor
akka://MySystem@machine1:2552
Remote deployment
リモート配備: ActorSystem にこの設定を渡すだけ
![Page 144: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/144.jpg)
Remote Lookup
val greeter = system.actorFor( "akka://MySystem@machine1:2552/user/greeter")
リモートアクターを探す
![Page 145: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/145.jpg)
Can you see the problem?
問題に気付いたかな?
![Page 146: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/146.jpg)
Fixed Addressesakka { actor { provider = akka.remote.RemoteActorRefProvider deployment { /greeter { remote = akka://MySystem@machine1:2552
} } }}
val greeter = system.actorFor( "akka://MySystem@machine1:2552/user/greeter")
アドレスが決め打ちされている
![Page 147: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/147.jpg)
Akka Cluster
![Page 148: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/148.jpg)
Features
• Gossip-based Cluster Membership• Leader determination• Accrual Failure Detector• Cluster DeathWatch• Cluster-Aware Routers
Gossip-based なクラスタ・メンバーシップ
![Page 149: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/149.jpg)
Enable clusteringakka { actor { provider = "akka.cluster.ClusterActorRefProvider" ... } cluster { seed-nodes = [ "akka://[email protected]:2551", "akka://[email protected]:2552" ] auto-down = on }}
クラスタを使う
![Page 150: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/150.jpg)
Configure a clustered router
akka.actor.deployment { /statsService/workerRouter { router = consistent-‐hashing nr-‐of-‐instances = 100
cluster { enabled = on max-nr-of-instances-per-node = 3 allow-‐local-‐routees = on } }}
クラスタ化されたルータの設定
![Page 151: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/151.jpg)
...we have much much more
![Page 152: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/152.jpg)
Dataflow
...we have much much moreFSM
Transactors
Pub/Sub
ZeroMQ
Microkernel
IO
TestKit
Agents
SLF4J
Durable Mailboxes
EventBus CamelPooling
TypedActor
Extensions
Typed Channels
![Page 153: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/153.jpg)
get it and learn morehttp://akka.io
http://typesafe.comhttp://letitcrash.com
![Page 154: Scaling software with akka](https://reader038.fdocuments.net/reader038/viewer/2022102613/554a0e24b4c9058c5d8b47d9/html5/thumbnails/154.jpg)
E0F