SlideShare a Scribd company logo
Concurrent and Distributed Applications 
with 
Akka, Java and Scala 
! 
Buenos Aires, Argentina, Oct 2012 
! 
@frodriguez
Moore’s law 
Moore's law says that every 18 months, 
the number of transistors that can fit within a 
given area on a chip doubles.
Moore’s law 
Moore's law says that every 18 months, 
the number of transistors that can fit within a 
given area on a chip doubles. 
Page's law says that every 18 months 
software becomes twice as slow
Modern CPUs 
intel ® 
Xeon 
® 
processor
Modern CPUs 
intel ® 
Xeon 
® 
processor 
Small improvements 
in 
execution speed
intel ® 
Xeon 
® 
processor 
Small improvements 
in 
execution speed 
but... 
Modern CPUs
Modern CPUs 
Core Core Core Core 
Cor 
Core 
Core 
Core 
Core 
Core 
Core 
Core 
Core Core 
Core Core 
Small improvements 
in 
execution speed 
but... 
Improved 
parallelism support 
Multicore processors
Alternative Moore’s & Page’s laws 
Every 18 months, 
the number of cores per chip doubles.
Alternative Moore’s & Page’s laws 
Every 18 months, 
the number of cores per chip doubles. 
Every 18 months the number of IDLE 
cores doubles
Modern Applications Demands...
Modern Applications Demands... 
Scalability
Modern Applications Demands... 
Scalability 
Vertical (scaling up) - Concurrency 
Horizontal (scaling out) - Distribution
Modern Applications Demands... 
Scalability 
Vertical (scaling up) - Concurrency 
Horizontal (scaling out) - Distribution 
Size (Resources, Users, ...) 
Geographically 
Admin / Management
Modern Applications Demands...
Modern Applications Demands... 
High Availability 
Fault Tolerance (local & distributed)
Modern Applications Demands... 
High Availability 
Fault Tolerance (local & distributed) 
Performance & Low Latency 
Efficient Use of Resources (CPU & Memory) 
Asynchronous (reduced latency) 
Distributed (cheap machines, better performance / $)
How to Write 
Concurrent Applications 
for 
Multicore Processors ?
Traditional Approach 
Threads (pools processing tasks) 
Shared (and mutable) State 
Synchronization and Locking 
Concurrent Collections
Traditional Threads ?
Traditional Threads ? 
process(...){ 
}
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
}
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
}
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Blocked 
Updating State in the Heap 
Returning Results 
} 
Thread 
Suspended
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
}
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
}
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
} 
Add concurrency...
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
}
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
Requires 
Synchronization 
can be blocked 
Requires 
Synchronization 
can be blocked 
}
Traditional Threads ? 
process(...){ 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
Requires 
Synchronization 
can be blocked 
Requires 
Synchronization 
can be blocked 
} 
Bad for 
CPU caches
Traditional Threads ? 
How many threads ? 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results
Traditional Threads ? 
How many threads ? 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results
Traditional Threads ? 
How many threads ? 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
Improves with threads 
(Assuming blocking, 
non-async I/O is used...)
Traditional Threads ? 
How many threads ? 
Computing 
Reading State from Heap 
I/O (e.g: Disk, Network, DBs) 
Processing Results 
Updating State in the Heap 
Returning Results 
Degrades with more 
threads than cores 
Context Switching, 
Contention, 
L1 & L2 Caches
What About Latency ? 
Client 
Biz 
DB 
Fetching 
and 
Mapping N Items 
Latency (time to first item) 
Thread by task (instead of by layer). Sync Results
What About Latency ? 
Client 
Biz 
DB 
Fetching 
and 
Mapping N Items 
Latency (time to first item) 
Parallelism by Layer - Asynchronous and Partial Results 
From Request/Response to Request Stream/Response Stream
How to Write 
Distributed Applications ?
Traditional Approach 
RPC (WS, RMI, ...) 
Queues (JMS, AMQP, STOMP, etc), 
Raw Sockets
Traditional Approach 
RPC (WS, RMI, ...) 
Queues (JMS, AMQP, STOMP, etc), 
Raw Sockets 
Local != Remote 
Local should be an optimization, 
not a forced early decision...
Akka 
“Akka is a toolkit and runtime for 
building highly concurrent, 
distributed, and fault tolerant event-driven 
applications on the JVM. ” 
Based on the actor model
What is an Actor ? 
Actors are objects which 
encapsulate state and behavior 
Communicate exclusively by 
exchanging messages 
Conceptually have their own 
light-weight thread 
No Need for Synchronization
Actors 
Actor 
State 
Behavior
Actors 
Actor 
State 
Behavior 
Mailbox
Actors 
Actor 
State 
Behavior 
C B A 
Mailbox
Actors 
Actor 
State 
Behavior 
C B A 
Mailbox
Actors 
Actor 
State 
Behavior 
C B A 
Mailbox
Actors 
Actor 
State 
BehaAvior 
C B 
Mailbox
Actors 
Actor 
State 
Behavior 
C B 
Mailbox
Actors 
Actor 
State 
Behavior 
C B 
Mailbox
Actors 
Actor 
State 
Behavior 
C B 
Millions of 
Actors 
Mailbox 
One per Actor
Actors 
Actor 
State 
Behavior 
Number of 
Threads 
Proportional to 
number of 
Cores 
C B 
Millions of 
Actors 
Mailbox 
One per Actor
Actors: Processing Messages 
/myactor 
State 
Behavior 
A
Actors: Processing Messages 
/myactor 
State 
BehaAvior
Actors: Processing Messages 
/myactor 
New State 
State 
Behavior 
Change State
Actors: Processing Messages 
/myactor 
State 
NBeewh Baevhaioviorr 
Change State 
Change Behavior
Actors: Processing Messages 
/myactor 
State 
Behavior 
/someactor 
State 
B Behavior 
Change State 
Change Behavior 
Send a Message
Actors: Processing Messages 
/myactor 
State 
Behavior 
/someactor 
State 
Behavior 
B 
Change State 
Change Behavior 
Send a Message
Actors: Processing Messages 
/myactor 
State 
Behavior 
/someactor 
State 
BehaBvior 
Change State 
Change Behavior 
Send a Message
Actors: Processing Messages 
/myactor 
State 
Behavior 
/someactor 
State 
Behavior 
/myactor/child 
State 
Behavior 
Change State 
Change Behavior 
Send a Message 
Create Actors
Hello World Actor 
Define 
class HelloWorld extends Actor { 
def receive = { 
case msg => 
printf(“Received %sn”, msg) 
} 
} 
Create 
val system = ActorSystem(“MySystem”) 
val hello = system.actorOf(Props[HelloWorld], “hello”) 
Send Message 
hello ! “World”
Counter Actor 
Define 
class Counter extends Actor { 
var total = 0 
! 
def receive = { 
case Count(value) => 
total += value 
case GetStats => 
sender ! Stats(total) 
} 
} 
Protocol 
case class Count(n: Int) 
case class Stats(total: Int) 
case object GetStats
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
BehAavior 
actorB ! A
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior 
A 
actorB ! A
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior A 
actorB ! A
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior A 
actorB ! A sender ! B
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior 
B 
actorB ! A sender ! B
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A sender ! B 
B
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior 
B 
actorB ! A sender ! B
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A sender ! B
Sending a Message 
/actorB 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A 
actorB tell A 
sender ! B 
sender tell B
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB tell (A, actorC)
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
BehAavior 
actorB tell (A, actorC)
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
A 
actorB tell (A, actorC)
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior A 
actorB tell (A, actorC)
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior A 
actorB tell (A, actorC) sender ! B
Sending a Message 
/actorB 
State 
Behavior 
B 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB tell (A, actorC) sender ! B
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB tell (A, actorC) sender ! B 
B
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB tell (A, actorC) sender ! B 
B
Sending a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB tell (A, actorC) sender ! B
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
BehAavior 
actorB ! A
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
A 
actorB ! A
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior A 
actorB ! A
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior A 
actorB ! A actorC forward B
Forward a Message 
/actorB 
State 
Behavior 
B 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A actorC forward B
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A actorC forward B 
B
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A actorC forward B 
B
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A actorC forward B 
sender ! C B
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A actorC forward B 
sender ! C C
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A actorC forward B 
sender ! C 
C
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
C 
actorB ! A actorC forward B 
sender ! C
Forward a Message 
/actorB 
State 
Behavior 
/actorC 
State 
Behavior 
/actorA 
State 
Behavior 
actorB ! A actorC forward B 
sender ! C
Ask & Pipe Patterns 
Ask 
val response = actor ? Message 
! 
response onSuccess { 
case Response(a) => 
printf(“Response %s”, a) 
} 
Pipe 
val response = actor ? Message 
! 
response pipeTo actor2
Mailbox 
UnboundedMailbox (default) 
UnboundedPriorityMailbox 
BoundedMailbox (*) 
BoundedPriorityMailbox (*) 
* May produce deadlocks if used unproperly
Routing 
Round Robin Router 
val actor = system.actorOf( 
Props[MyActor].withRouter(RoundRobinRouter(4)), 
name = “myrouter” 
) 
Using actor with routers (no changes) 
! 
actor ! Message
Routing 
RoundRobinRouter 
RandomRouter 
SmallestMailboxRouter 
BroadcastRouter 
ScatterGatherFirstCompletedRouter
Routing Configuration 
Configuration overrides code 
akka.actor.deployment { 
/myrouter { 
router = round-robin 
nr-of-instances = 8 
} 
} 
Routers from Config 
val actor = system.actorOf( 
Props[MyActor].withRouter(FromConfig()), 
name = “myrouter” 
)
Remoting 
Accessing remote actor 
val actor = system.actorFor( 
“akka://sys@server:2552/user/actor” 
) 
Using remote actor (no changes) 
! 
actor ! Message 
! 
// Replies also work ok 
sender ! Response
Remote Deployment 
Code without changes 
val actor = system.actorOf( 
Props[MyActor], 
name = “myactor” 
) 
Configuration 
! 
akka.actor.deployment { 
/myactor { 
remote = “akka://sys@server:2553” 
} 
}
Remote Deployment (routers) 
akka.actor.deployment { 
/myrouter { 
router = round-robin 
nr-of-instances = 8 
! 
target { 
nodes = [“akka://sys@server1:2552” 
“akka://sys@server2:2552”] 
} 
} 
} 
Routers from Config 
val actor = system.actorOf( 
Props[MyActor].withRouter(FromConfig()), 
name = “myrouter” 
)
Fault Tolerance 
override val supervisorStrategy = OneForOneStrategy(...) 
{ 
case _: ArithmeticException => Resume 
case _: NullPointerException => Restart 
case _: IllegalArgumentException => Stop 
case _: Exception => Escalate 
} 
Supervision Hierarchies across machines
Thanks 
@frodriguez 
frodriguez <at> gmail.com

More Related Content

What's hot

Introduction to MapReduce and Hadoop
Introduction to MapReduce and HadoopIntroduction to MapReduce and Hadoop
Introduction to MapReduce and Hadoop
Mohamed Elsaka
 
Introduction to Hadoop and MapReduce
Introduction to Hadoop and MapReduceIntroduction to Hadoop and MapReduce
Introduction to Hadoop and MapReduce
Dr Ganesh Iyer
 
Apache pig
Apache pigApache pig
Apache pig
Jigar Parekh
 
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab
 
A Deep Dive Into Spark
A Deep Dive Into SparkA Deep Dive Into Spark
A Deep Dive Into Spark
Ashish kumar
 
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labsApache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labsViswanath Gangavaram
 
Shark SQL and Rich Analytics at Scale
Shark SQL and Rich Analytics at ScaleShark SQL and Rich Analytics at Scale
Shark SQL and Rich Analytics at ScaleDataWorks Summit
 
Introduction to Tokyo Products
Introduction to Tokyo ProductsIntroduction to Tokyo Products
Introduction to Tokyo Products
Mikio Hirabayashi
 
Onyx data processing the clojure way
Onyx   data processing  the clojure wayOnyx   data processing  the clojure way
Onyx data processing the clojure way
Bahadir Cambel
 
Hadoop & MapReduce
Hadoop & MapReduceHadoop & MapReduce
Hadoop & MapReduce
Newvewm
 
dmapply: A functional primitive to express distributed machine learning algor...
dmapply: A functional primitive to express distributed machine learning algor...dmapply: A functional primitive to express distributed machine learning algor...
dmapply: A functional primitive to express distributed machine learning algor...
Bikash Chandra Karmokar
 
Introduction to Spark
Introduction to SparkIntroduction to Spark
Introduction to Spark
Li Ming Tsai
 
BDAS Shark study report 03 v1.1
BDAS Shark study report  03 v1.1BDAS Shark study report  03 v1.1
BDAS Shark study report 03 v1.1
Stefanie Zhao
 
mesos-devoxx14
mesos-devoxx14mesos-devoxx14
mesos-devoxx14
Samir Bessalah
 
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
InfluxData
 
apache pig performance optimizations talk at apachecon 2010
apache pig performance optimizations talk at apachecon 2010apache pig performance optimizations talk at apachecon 2010
apache pig performance optimizations talk at apachecon 2010Thejas Nair
 
Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)
Brian O'Neill
 
Meethadoop
MeethadoopMeethadoop
Meethadoop
IIIT-H
 
Big Data Analysis With RHadoop
Big Data Analysis With RHadoopBig Data Analysis With RHadoop
Big Data Analysis With RHadoop
David Chiu
 

What's hot (20)

Introduction to MapReduce and Hadoop
Introduction to MapReduce and HadoopIntroduction to MapReduce and Hadoop
Introduction to MapReduce and Hadoop
 
Introduction to Hadoop and MapReduce
Introduction to Hadoop and MapReduceIntroduction to Hadoop and MapReduce
Introduction to Hadoop and MapReduce
 
Apache pig
Apache pigApache pig
Apache pig
 
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
 
A Deep Dive Into Spark
A Deep Dive Into SparkA Deep Dive Into Spark
A Deep Dive Into Spark
 
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labsApache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
 
Shark SQL and Rich Analytics at Scale
Shark SQL and Rich Analytics at ScaleShark SQL and Rich Analytics at Scale
Shark SQL and Rich Analytics at Scale
 
Introduction to Tokyo Products
Introduction to Tokyo ProductsIntroduction to Tokyo Products
Introduction to Tokyo Products
 
Onyx data processing the clojure way
Onyx   data processing  the clojure wayOnyx   data processing  the clojure way
Onyx data processing the clojure way
 
Hadoop & MapReduce
Hadoop & MapReduceHadoop & MapReduce
Hadoop & MapReduce
 
dmapply: A functional primitive to express distributed machine learning algor...
dmapply: A functional primitive to express distributed machine learning algor...dmapply: A functional primitive to express distributed machine learning algor...
dmapply: A functional primitive to express distributed machine learning algor...
 
Introduction to Spark
Introduction to SparkIntroduction to Spark
Introduction to Spark
 
BDAS Shark study report 03 v1.1
BDAS Shark study report  03 v1.1BDAS Shark study report  03 v1.1
BDAS Shark study report 03 v1.1
 
mesos-devoxx14
mesos-devoxx14mesos-devoxx14
mesos-devoxx14
 
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
 
Hadoop 2
Hadoop 2Hadoop 2
Hadoop 2
 
apache pig performance optimizations talk at apachecon 2010
apache pig performance optimizations talk at apachecon 2010apache pig performance optimizations talk at apachecon 2010
apache pig performance optimizations talk at apachecon 2010
 
Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)
 
Meethadoop
MeethadoopMeethadoop
Meethadoop
 
Big Data Analysis With RHadoop
Big Data Analysis With RHadoopBig Data Analysis With RHadoop
Big Data Analysis With RHadoop
 

Viewers also liked

Scala collection
Scala collectionScala collection
Scala collection
Knoldus Inc.
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camelkrasserm
 
Introduction to Option monad in Scala
Introduction to Option monad in ScalaIntroduction to Option monad in Scala
Introduction to Option monad in Scala
Jan Krag
 
Tech planet 2015 Docker 클라우드 구축 프로젝트 - d4
Tech planet 2015 Docker 클라우드 구축 프로젝트 - d4Tech planet 2015 Docker 클라우드 구축 프로젝트 - d4
Tech planet 2015 Docker 클라우드 구축 프로젝트 - d4
Sangcheol Hwang
 
Exception Handling in Scala
Exception Handling in ScalaException Handling in Scala
Exception Handling in Scala
Nag Arvind Gudiseva
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 

Viewers also liked (6)

Scala collection
Scala collectionScala collection
Scala collection
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
 
Introduction to Option monad in Scala
Introduction to Option monad in ScalaIntroduction to Option monad in Scala
Introduction to Option monad in Scala
 
Tech planet 2015 Docker 클라우드 구축 프로젝트 - d4
Tech planet 2015 Docker 클라우드 구축 프로젝트 - d4Tech planet 2015 Docker 클라우드 구축 프로젝트 - d4
Tech planet 2015 Docker 클라우드 구축 프로젝트 - d4
 
Exception Handling in Scala
Exception Handling in ScalaException Handling in Scala
Exception Handling in Scala
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 

Similar to Concurrent and Distributed Applications with Akka, Java and Scala

Scaling Apache Storm - Strata + Hadoop World 2014
Scaling Apache Storm - Strata + Hadoop World 2014Scaling Apache Storm - Strata + Hadoop World 2014
Scaling Apache Storm - Strata + Hadoop World 2014
P. Taylor Goetz
 
Embrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with RippleEmbrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with Ripple
Sean Cribbs
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
Yaroslav Tkachenko
 
Declarative Multilingual Information Extraction with SystemT
Declarative Multilingual Information Extraction with SystemTDeclarative Multilingual Information Extraction with SystemT
Declarative Multilingual Information Extraction with SystemT
Laura Chiticariu
 
Notes on a High-Performance JSON Protocol
Notes on a High-Performance JSON ProtocolNotes on a High-Performance JSON Protocol
Notes on a High-Performance JSON Protocol
Daniel Austin
 
Actors, a Unifying Pattern for Scalable Concurrency | C4 2006
Actors, a Unifying Pattern for Scalable Concurrency | C4 2006 Actors, a Unifying Pattern for Scalable Concurrency | C4 2006
Actors, a Unifying Pattern for Scalable Concurrency | C4 2006
Real Nobile
 
Introducingakkajavazone2012 120914094033-phpapp02
Introducingakkajavazone2012 120914094033-phpapp02Introducingakkajavazone2012 120914094033-phpapp02
Introducingakkajavazone2012 120914094033-phpapp02Typesafe
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
Jonas Bonér
 
Introduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf TrainingIntroduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf Training
Sean Cribbs
 
Clouds: All fluff and no substance?
Clouds: All fluff and no substance?Clouds: All fluff and no substance?
Clouds: All fluff and no substance?
Guy Coates
 
Real-World Pulsar Architectural Patterns
Real-World Pulsar Architectural PatternsReal-World Pulsar Architectural Patterns
Real-World Pulsar Architectural Patterns
Devin Bost
 
Project Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Project Tungsten Phase II: Joining a Billion Rows per Second on a LaptopProject Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Project Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Databricks
 
Towards Scalable Service Composition on Multicores
Towards Scalable Service Composition on MulticoresTowards Scalable Service Composition on Multicores
Towards Scalable Service Composition on Multicores
Cesare Pautasso
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServices
Stéphane Maldini
 
Modern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettextModern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettext
Alexander Mostovenko
 
Presto at Tivo, Boston Hadoop Meetup
Presto at Tivo, Boston Hadoop MeetupPresto at Tivo, Boston Hadoop Meetup
Presto at Tivo, Boston Hadoop Meetup
Justin Borgman
 
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Codemotion
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESI
Kit Chan
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical Section
Tony Albrecht
 

Similar to Concurrent and Distributed Applications with Akka, Java and Scala (20)

Scaling Apache Storm - Strata + Hadoop World 2014
Scaling Apache Storm - Strata + Hadoop World 2014Scaling Apache Storm - Strata + Hadoop World 2014
Scaling Apache Storm - Strata + Hadoop World 2014
 
Embrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with RippleEmbrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with Ripple
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Declarative Multilingual Information Extraction with SystemT
Declarative Multilingual Information Extraction with SystemTDeclarative Multilingual Information Extraction with SystemT
Declarative Multilingual Information Extraction with SystemT
 
Notes on a High-Performance JSON Protocol
Notes on a High-Performance JSON ProtocolNotes on a High-Performance JSON Protocol
Notes on a High-Performance JSON Protocol
 
Actors, a Unifying Pattern for Scalable Concurrency | C4 2006
Actors, a Unifying Pattern for Scalable Concurrency | C4 2006 Actors, a Unifying Pattern for Scalable Concurrency | C4 2006
Actors, a Unifying Pattern for Scalable Concurrency | C4 2006
 
Introducingakkajavazone2012 120914094033-phpapp02
Introducingakkajavazone2012 120914094033-phpapp02Introducingakkajavazone2012 120914094033-phpapp02
Introducingakkajavazone2012 120914094033-phpapp02
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
 
Introduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf TrainingIntroduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf Training
 
Clouds: All fluff and no substance?
Clouds: All fluff and no substance?Clouds: All fluff and no substance?
Clouds: All fluff and no substance?
 
Real-World Pulsar Architectural Patterns
Real-World Pulsar Architectural PatternsReal-World Pulsar Architectural Patterns
Real-World Pulsar Architectural Patterns
 
Project Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Project Tungsten Phase II: Joining a Billion Rows per Second on a LaptopProject Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Project Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
 
Towards Scalable Service Composition on Multicores
Towards Scalable Service Composition on MulticoresTowards Scalable Service Composition on Multicores
Towards Scalable Service Composition on Multicores
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServices
 
Modern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettextModern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettext
 
Presto at Tivo, Boston Hadoop Meetup
Presto at Tivo, Boston Hadoop MeetupPresto at Tivo, Boston Hadoop Meetup
Presto at Tivo, Boston Hadoop Meetup
 
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESI
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical Section
 

Recently uploaded

Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
Kamal Acharya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Chat application through client server management system project.pdf
Chat application through client server management system project.pdfChat application through client server management system project.pdf
Chat application through client server management system project.pdf
Kamal Acharya
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
calpeda Water Efficient and Effective Pump.pptx
calpeda Water Efficient and Effective Pump.pptxcalpeda Water Efficient and Effective Pump.pptx
calpeda Water Efficient and Effective Pump.pptx
calpedapumpindia
 

Recently uploaded (20)

Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Chat application through client server management system project.pdf
Chat application through client server management system project.pdfChat application through client server management system project.pdf
Chat application through client server management system project.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
calpeda Water Efficient and Effective Pump.pptx
calpeda Water Efficient and Effective Pump.pptxcalpeda Water Efficient and Effective Pump.pptx
calpeda Water Efficient and Effective Pump.pptx
 

Concurrent and Distributed Applications with Akka, Java and Scala

  • 1. Concurrent and Distributed Applications with Akka, Java and Scala ! Buenos Aires, Argentina, Oct 2012 ! @frodriguez
  • 2. Moore’s law Moore's law says that every 18 months, the number of transistors that can fit within a given area on a chip doubles.
  • 3. Moore’s law Moore's law says that every 18 months, the number of transistors that can fit within a given area on a chip doubles. Page's law says that every 18 months software becomes twice as slow
  • 4. Modern CPUs intel ® Xeon ® processor
  • 5. Modern CPUs intel ® Xeon ® processor Small improvements in execution speed
  • 6. intel ® Xeon ® processor Small improvements in execution speed but... Modern CPUs
  • 7. Modern CPUs Core Core Core Core Cor Core Core Core Core Core Core Core Core Core Core Core Small improvements in execution speed but... Improved parallelism support Multicore processors
  • 8. Alternative Moore’s & Page’s laws Every 18 months, the number of cores per chip doubles.
  • 9. Alternative Moore’s & Page’s laws Every 18 months, the number of cores per chip doubles. Every 18 months the number of IDLE cores doubles
  • 12. Modern Applications Demands... Scalability Vertical (scaling up) - Concurrency Horizontal (scaling out) - Distribution
  • 13. Modern Applications Demands... Scalability Vertical (scaling up) - Concurrency Horizontal (scaling out) - Distribution Size (Resources, Users, ...) Geographically Admin / Management
  • 15. Modern Applications Demands... High Availability Fault Tolerance (local & distributed)
  • 16. Modern Applications Demands... High Availability Fault Tolerance (local & distributed) Performance & Low Latency Efficient Use of Resources (CPU & Memory) Asynchronous (reduced latency) Distributed (cheap machines, better performance / $)
  • 17. How to Write Concurrent Applications for Multicore Processors ?
  • 18. Traditional Approach Threads (pools processing tasks) Shared (and mutable) State Synchronization and Locking Concurrent Collections
  • 20. Traditional Threads ? process(...){ }
  • 21. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results }
  • 22. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results }
  • 23. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Blocked Updating State in the Heap Returning Results } Thread Suspended
  • 24. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results }
  • 25. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results }
  • 26. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results } Add concurrency...
  • 27. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results }
  • 28. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results Requires Synchronization can be blocked Requires Synchronization can be blocked }
  • 29. Traditional Threads ? process(...){ Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results Requires Synchronization can be blocked Requires Synchronization can be blocked } Bad for CPU caches
  • 30. Traditional Threads ? How many threads ? Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results
  • 31. Traditional Threads ? How many threads ? Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results
  • 32. Traditional Threads ? How many threads ? Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results Improves with threads (Assuming blocking, non-async I/O is used...)
  • 33. Traditional Threads ? How many threads ? Computing Reading State from Heap I/O (e.g: Disk, Network, DBs) Processing Results Updating State in the Heap Returning Results Degrades with more threads than cores Context Switching, Contention, L1 & L2 Caches
  • 34. What About Latency ? Client Biz DB Fetching and Mapping N Items Latency (time to first item) Thread by task (instead of by layer). Sync Results
  • 35. What About Latency ? Client Biz DB Fetching and Mapping N Items Latency (time to first item) Parallelism by Layer - Asynchronous and Partial Results From Request/Response to Request Stream/Response Stream
  • 36. How to Write Distributed Applications ?
  • 37. Traditional Approach RPC (WS, RMI, ...) Queues (JMS, AMQP, STOMP, etc), Raw Sockets
  • 38. Traditional Approach RPC (WS, RMI, ...) Queues (JMS, AMQP, STOMP, etc), Raw Sockets Local != Remote Local should be an optimization, not a forced early decision...
  • 39. Akka “Akka is a toolkit and runtime for building highly concurrent, distributed, and fault tolerant event-driven applications on the JVM. ” Based on the actor model
  • 40. What is an Actor ? Actors are objects which encapsulate state and behavior Communicate exclusively by exchanging messages Conceptually have their own light-weight thread No Need for Synchronization
  • 41. Actors Actor State Behavior
  • 42. Actors Actor State Behavior Mailbox
  • 43. Actors Actor State Behavior C B A Mailbox
  • 44. Actors Actor State Behavior C B A Mailbox
  • 45. Actors Actor State Behavior C B A Mailbox
  • 46. Actors Actor State BehaAvior C B Mailbox
  • 47. Actors Actor State Behavior C B Mailbox
  • 48. Actors Actor State Behavior C B Mailbox
  • 49. Actors Actor State Behavior C B Millions of Actors Mailbox One per Actor
  • 50. Actors Actor State Behavior Number of Threads Proportional to number of Cores C B Millions of Actors Mailbox One per Actor
  • 51. Actors: Processing Messages /myactor State Behavior A
  • 52. Actors: Processing Messages /myactor State BehaAvior
  • 53. Actors: Processing Messages /myactor New State State Behavior Change State
  • 54. Actors: Processing Messages /myactor State NBeewh Baevhaioviorr Change State Change Behavior
  • 55. Actors: Processing Messages /myactor State Behavior /someactor State B Behavior Change State Change Behavior Send a Message
  • 56. Actors: Processing Messages /myactor State Behavior /someactor State Behavior B Change State Change Behavior Send a Message
  • 57. Actors: Processing Messages /myactor State Behavior /someactor State BehaBvior Change State Change Behavior Send a Message
  • 58. Actors: Processing Messages /myactor State Behavior /someactor State Behavior /myactor/child State Behavior Change State Change Behavior Send a Message Create Actors
  • 59. Hello World Actor Define class HelloWorld extends Actor { def receive = { case msg => printf(“Received %sn”, msg) } } Create val system = ActorSystem(“MySystem”) val hello = system.actorOf(Props[HelloWorld], “hello”) Send Message hello ! “World”
  • 60. Counter Actor Define class Counter extends Actor { var total = 0 ! def receive = { case Count(value) => total += value case GetStats => sender ! Stats(total) } } Protocol case class Count(n: Int) case class Stats(total: Int) case object GetStats
  • 61. Sending a Message /actorB State Behavior /actorA State Behavior
  • 62. Sending a Message /actorB State Behavior /actorA State Behavior actorB ! A
  • 63. Sending a Message /actorB State Behavior /actorA State BehAavior actorB ! A
  • 64. Sending a Message /actorB State Behavior /actorA State Behavior A actorB ! A
  • 65. Sending a Message /actorB State Behavior /actorA State Behavior A actorB ! A
  • 66. Sending a Message /actorB State Behavior /actorA State Behavior A actorB ! A sender ! B
  • 67. Sending a Message /actorB State Behavior /actorA State Behavior B actorB ! A sender ! B
  • 68. Sending a Message /actorB State Behavior /actorA State Behavior actorB ! A sender ! B B
  • 69. Sending a Message /actorB State Behavior /actorA State Behavior B actorB ! A sender ! B
  • 70. Sending a Message /actorB State Behavior /actorA State Behavior actorB ! A sender ! B
  • 71. Sending a Message /actorB State Behavior /actorA State Behavior actorB ! A actorB tell A sender ! B sender tell B
  • 72. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior
  • 73. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB tell (A, actorC)
  • 74. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State BehAavior actorB tell (A, actorC)
  • 75. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior A actorB tell (A, actorC)
  • 76. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior A actorB tell (A, actorC)
  • 77. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior A actorB tell (A, actorC) sender ! B
  • 78. Sending a Message /actorB State Behavior B /actorC State Behavior /actorA State Behavior actorB tell (A, actorC) sender ! B
  • 79. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB tell (A, actorC) sender ! B B
  • 80. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB tell (A, actorC) sender ! B B
  • 81. Sending a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB tell (A, actorC) sender ! B
  • 82. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior
  • 83. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB ! A
  • 84. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State BehAavior actorB ! A
  • 85. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior A actorB ! A
  • 86. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior A actorB ! A
  • 87. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior A actorB ! A actorC forward B
  • 88. Forward a Message /actorB State Behavior B /actorC State Behavior /actorA State Behavior actorB ! A actorC forward B
  • 89. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB ! A actorC forward B B
  • 90. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB ! A actorC forward B B
  • 91. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB ! A actorC forward B sender ! C B
  • 92. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB ! A actorC forward B sender ! C C
  • 93. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB ! A actorC forward B sender ! C C
  • 94. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior C actorB ! A actorC forward B sender ! C
  • 95. Forward a Message /actorB State Behavior /actorC State Behavior /actorA State Behavior actorB ! A actorC forward B sender ! C
  • 96. Ask & Pipe Patterns Ask val response = actor ? Message ! response onSuccess { case Response(a) => printf(“Response %s”, a) } Pipe val response = actor ? Message ! response pipeTo actor2
  • 97. Mailbox UnboundedMailbox (default) UnboundedPriorityMailbox BoundedMailbox (*) BoundedPriorityMailbox (*) * May produce deadlocks if used unproperly
  • 98. Routing Round Robin Router val actor = system.actorOf( Props[MyActor].withRouter(RoundRobinRouter(4)), name = “myrouter” ) Using actor with routers (no changes) ! actor ! Message
  • 99. Routing RoundRobinRouter RandomRouter SmallestMailboxRouter BroadcastRouter ScatterGatherFirstCompletedRouter
  • 100. Routing Configuration Configuration overrides code akka.actor.deployment { /myrouter { router = round-robin nr-of-instances = 8 } } Routers from Config val actor = system.actorOf( Props[MyActor].withRouter(FromConfig()), name = “myrouter” )
  • 101. Remoting Accessing remote actor val actor = system.actorFor( “akka://sys@server:2552/user/actor” ) Using remote actor (no changes) ! actor ! Message ! // Replies also work ok sender ! Response
  • 102. Remote Deployment Code without changes val actor = system.actorOf( Props[MyActor], name = “myactor” ) Configuration ! akka.actor.deployment { /myactor { remote = “akka://sys@server:2553” } }
  • 103. Remote Deployment (routers) akka.actor.deployment { /myrouter { router = round-robin nr-of-instances = 8 ! target { nodes = [“akka://sys@server1:2552” “akka://sys@server2:2552”] } } } Routers from Config val actor = system.actorOf( Props[MyActor].withRouter(FromConfig()), name = “myrouter” )
  • 104. Fault Tolerance override val supervisorStrategy = OneForOneStrategy(...) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: IllegalArgumentException => Stop case _: Exception => Escalate } Supervision Hierarchies across machines
  • 105. Thanks @frodriguez frodriguez <at> gmail.com