SlideShare a Scribd company logo
1 of 21
Download to read offline
Dominik Gruber, @the_dom
Vienna Scala User Group – Feb. 20, 2014
Akka Concurrency
•

521 pages

•

Written by Derek Wyatt, Foreword by Roland Kuhn

•

Published in May 2013

•

Based on Akka 2.1

•

EUR 17,– (Kindle) / EUR 29,95 (Dead Tree)

Akka Concurrency

Dominik Gruber • @the_dom
Prerequisites
•

Basic Scala Knowledge

•

No Akka Knowledge

•

“Principles of Reactive Programming” Course: Half of
the content will be new

Akka Concurrency

Dominik Gruber • @the_dom
Pros
•

Big focus on testing

•

One big, concise example throughout the book

•

Exhaustive overview

Akka Concurrency

Dominik Gruber • @the_dom
Cons
•

Based on Akka 2.1
•

No Akka Cluster

•

No Akka Persistence

Akka Concurrency

Dominik Gruber • @the_dom
Table of Contents, I
•

Why Akka?, Concurrency and Parallelism, Actors,…

•

Akka Testing

•

Supervision and DeathWatch

•

Being Stateful

•

Routing Messages

•

Dispatchers and Mailboxes

Akka Concurrency

Dominik Gruber • @the_dom
Table of Contents, II
•

Futures, Networking, Remote Actors

•

Sharing Data with Agents

•

Granular Concurrency with Dataflow

•

Patterns / Antipatterns

•

Add-On Modules

•

Using Akka from Java

Akka Concurrency

Dominik Gruber • @the_dom
Some Examples

Akka Concurrency

Dominik Gruber • @the_dom
Being Stateful
def expectHello: Receive = {
case “Hello” =>
sender ! “Goodbye”
context.become(expectGoodbye)
}
def expectGoodbye: Receive = {
case “Goodbye” =>
sender ! “Hello”
context.become(expectHello)
}
def receive = expectHello

Akka Concurrency

Dominik Gruber • @the_dom
FSM
sealed trait State
case object Idle extends State
case object Active extends State

!
sealed trait Data
case object Uninitialized extends Data
case class Todo(target: ActorRef, queue: immutable.Seq[Any])
extends Data

Akka Concurrency

Dominik Gruber • @the_dom
class Buncher extends Actor with FSM[State, Data] {

startWith(Idle, Uninitialized)

when(Idle) {
case Event(SetTarget(ref), Uninitialized) =>
stay using Todo(ref, Vector.empty)
}
when(Active, stateTimeout = 1 second) {
case Event(Flush | StateTimeout, t: Todo) =>
goto(Idle) using t.copy(queue = Vector.empty)
}
// …
}

Akka Concurrency

Dominik Gruber • @the_dom
class Buncher extends Actor with FSM[State, Data] {
//…
onTransition {
case Active -> Idle =>
stateData match {
case Todo(ref, queue) => ref ! Batch(queue)
}
}
whenUnhandled {
// common code for both states
case Event(Queue(obj), t @ Todo(_, v)) =>
goto(Active) using t.copy(queue = v :+ obj)
case Event(e, s) =>
log.warning("received unhandled request {} in state {}/{}", e, stateName, s)
stay
}
}

Akka Concurrency

Dominik Gruber • @the_dom
Routers
•

RoundRobinRouter

•

RandomRouter

•

BroadcastRouter

•

SmallestMailboxRouter

•

ScatterGatherFirstCompletedRouter

Akka Concurrency

Dominik Gruber • @the_dom
Dataflow Concurrency
def calculatePiTo(places: Int): Future[BigDecimal] = ???
def fibonaccis(n: Int): Future[Seq[BigDecimal]] = ???
val perfect = flow {
val pie = calculatePiTo(3000000)
val fibs = fibonaccis(31402)
val lastFibs = fibs().last
pie() * lastFibs * lastFibs
}
Akka Concurrency

Dominik Gruber • @the_dom
Akka Concurrency

Dominik Gruber • @the_dom
Future
val result = for {
i <- Future(5)
j <- Future(11)

Blocking!

} yield j

Akka Concurrency

Dominik Gruber • @the_dom
Future
Translates to:
val result = fiveFuture.flatMap { i =>
Future(11) map { j => j }
}

Akka Concurrency

Dominik Gruber • @the_dom
Future
val fiveFuture = Future(5)
val elevenFuture = Future(11)
val result = for {
i <- fiveFuture

Non-Blocking

j <- elevenFuture
} yield j
Akka Concurrency

Dominik Gruber • @the_dom
Future
Translates to:
val result = fiveFuture.flatMap { i =>
elevenFuture map { j => j }
}

Akka Concurrency

Dominik Gruber • @the_dom

More Related Content

What's hot

What's hot (20)

Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
 
Concurrecny inf sharp
Concurrecny inf sharpConcurrecny inf sharp
Concurrecny inf sharp
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
 
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka Building reactive distributed systems with Akka
Building reactive distributed systems with Akka
 
Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
 
Back to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migrationBack to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migration
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
 
A gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelA gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor model
 
Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014
 
Paws - A Perl AWS SDK
Paws - A Perl AWS SDKPaws - A Perl AWS SDK
Paws - A Perl AWS SDK
 
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka features
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matter
 
Paws - Perl AWS SDK Update - November 2015
Paws - Perl AWS SDK Update - November 2015Paws - Perl AWS SDK Update - November 2015
Paws - Perl AWS SDK Update - November 2015
 
Java 8 concurrency abstractions
Java 8 concurrency abstractionsJava 8 concurrency abstractions
Java 8 concurrency abstractions
 

Similar to 2014-02-20 | Akka Concurrency (Vienna Scala User Group)

NYC Lucene/Solr Meetup: Spark / Solr
NYC Lucene/Solr Meetup: Spark / SolrNYC Lucene/Solr Meetup: Spark / Solr
NYC Lucene/Solr Meetup: Spark / Solr
thelabdude
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
Konrad Malawski
 

Similar to 2014-02-20 | Akka Concurrency (Vienna Scala User Group) (20)

2014-11-26 | Creating a BitTorrent Client with Scala and Akka, Part 1 (Vienna...
2014-11-26 | Creating a BitTorrent Client with Scala and Akka, Part 1 (Vienna...2014-11-26 | Creating a BitTorrent Client with Scala and Akka, Part 1 (Vienna...
2014-11-26 | Creating a BitTorrent Client with Scala and Akka, Part 1 (Vienna...
 
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den Hoek
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015
 
Exactly-once Data Processing with Kafka Streams - July 27, 2017
Exactly-once Data Processing with Kafka Streams - July 27, 2017Exactly-once Data Processing with Kafka Streams - July 27, 2017
Exactly-once Data Processing with Kafka Streams - July 27, 2017
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and Spring
 
Groovy concurrency
Groovy concurrencyGroovy concurrency
Groovy concurrency
 
Kafka Summit SF 2017 - MultiCluster, MultiTenant and Hierarchical Kafka Messa...
Kafka Summit SF 2017 - MultiCluster, MultiTenant and Hierarchical Kafka Messa...Kafka Summit SF 2017 - MultiCluster, MultiTenant and Hierarchical Kafka Messa...
Kafka Summit SF 2017 - MultiCluster, MultiTenant and Hierarchical Kafka Messa...
 
Multi cluster, multitenant and hierarchical kafka messaging service slideshare
Multi cluster, multitenant and hierarchical kafka messaging service   slideshareMulti cluster, multitenant and hierarchical kafka messaging service   slideshare
Multi cluster, multitenant and hierarchical kafka messaging service slideshare
 
mapreduce ppt.ppt
mapreduce ppt.pptmapreduce ppt.ppt
mapreduce ppt.ppt
 
L3.fa14.ppt
L3.fa14.pptL3.fa14.ppt
L3.fa14.ppt
 
NYC Lucene/Solr Meetup: Spark / Solr
NYC Lucene/Solr Meetup: Spark / SolrNYC Lucene/Solr Meetup: Spark / Solr
NYC Lucene/Solr Meetup: Spark / Solr
 
Exactly-once Stream Processing with Kafka Streams
Exactly-once Stream Processing with Kafka StreamsExactly-once Stream Processing with Kafka Streams
Exactly-once Stream Processing with Kafka Streams
 
Training Slides: Introduction To Tungsten Solutions
Training Slides: Introduction To Tungsten SolutionsTraining Slides: Introduction To Tungsten Solutions
Training Slides: Introduction To Tungsten Solutions
 
Guaranteed Event Delivery with Kafka and NodeJS | Amitesh Madhur, Nutanix
Guaranteed Event Delivery with Kafka and NodeJS | Amitesh Madhur, NutanixGuaranteed Event Delivery with Kafka and NodeJS | Amitesh Madhur, Nutanix
Guaranteed Event Delivery with Kafka and NodeJS | Amitesh Madhur, Nutanix
 
Introduction to Kafka Streams
Introduction to Kafka StreamsIntroduction to Kafka Streams
Introduction to Kafka Streams
 
Kafka Summit NYC 2017 Introduction to Kafka Streams with a Real-life Example
Kafka Summit NYC 2017 Introduction to Kafka Streams with a Real-life ExampleKafka Summit NYC 2017 Introduction to Kafka Streams with a Real-life Example
Kafka Summit NYC 2017 Introduction to Kafka Streams with a Real-life Example
 
Reactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka StreamsReactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka Streams
 
Akka-demy (a.k.a. How to build stateful distributed systems) I/II
 Akka-demy (a.k.a. How to build stateful distributed systems) I/II Akka-demy (a.k.a. How to build stateful distributed systems) I/II
Akka-demy (a.k.a. How to build stateful distributed systems) I/II
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

2014-02-20 | Akka Concurrency (Vienna Scala User Group)

  • 1.
  • 2.
  • 3. Dominik Gruber, @the_dom Vienna Scala User Group – Feb. 20, 2014
  • 4. Akka Concurrency • 521 pages • Written by Derek Wyatt, Foreword by Roland Kuhn • Published in May 2013 • Based on Akka 2.1 • EUR 17,– (Kindle) / EUR 29,95 (Dead Tree) Akka Concurrency Dominik Gruber • @the_dom
  • 5. Prerequisites • Basic Scala Knowledge • No Akka Knowledge • “Principles of Reactive Programming” Course: Half of the content will be new Akka Concurrency Dominik Gruber • @the_dom
  • 6. Pros • Big focus on testing • One big, concise example throughout the book • Exhaustive overview Akka Concurrency Dominik Gruber • @the_dom
  • 7. Cons • Based on Akka 2.1 • No Akka Cluster • No Akka Persistence Akka Concurrency Dominik Gruber • @the_dom
  • 8. Table of Contents, I • Why Akka?, Concurrency and Parallelism, Actors,… • Akka Testing • Supervision and DeathWatch • Being Stateful • Routing Messages • Dispatchers and Mailboxes Akka Concurrency Dominik Gruber • @the_dom
  • 9. Table of Contents, II • Futures, Networking, Remote Actors • Sharing Data with Agents • Granular Concurrency with Dataflow • Patterns / Antipatterns • Add-On Modules • Using Akka from Java Akka Concurrency Dominik Gruber • @the_dom
  • 11. Being Stateful def expectHello: Receive = { case “Hello” => sender ! “Goodbye” context.become(expectGoodbye) } def expectGoodbye: Receive = { case “Goodbye” => sender ! “Hello” context.become(expectHello) } def receive = expectHello Akka Concurrency Dominik Gruber • @the_dom
  • 12. FSM sealed trait State case object Idle extends State case object Active extends State ! sealed trait Data case object Uninitialized extends Data case class Todo(target: ActorRef, queue: immutable.Seq[Any]) extends Data Akka Concurrency Dominik Gruber • @the_dom
  • 13. class Buncher extends Actor with FSM[State, Data] { startWith(Idle, Uninitialized) when(Idle) { case Event(SetTarget(ref), Uninitialized) => stay using Todo(ref, Vector.empty) } when(Active, stateTimeout = 1 second) { case Event(Flush | StateTimeout, t: Todo) => goto(Idle) using t.copy(queue = Vector.empty) } // … } Akka Concurrency Dominik Gruber • @the_dom
  • 14. class Buncher extends Actor with FSM[State, Data] { //… onTransition { case Active -> Idle => stateData match { case Todo(ref, queue) => ref ! Batch(queue) } } whenUnhandled { // common code for both states case Event(Queue(obj), t @ Todo(_, v)) => goto(Active) using t.copy(queue = v :+ obj) case Event(e, s) => log.warning("received unhandled request {} in state {}/{}", e, stateName, s) stay } } Akka Concurrency Dominik Gruber • @the_dom
  • 16. Dataflow Concurrency def calculatePiTo(places: Int): Future[BigDecimal] = ??? def fibonaccis(n: Int): Future[Seq[BigDecimal]] = ??? val perfect = flow { val pie = calculatePiTo(3000000) val fibs = fibonaccis(31402) val lastFibs = fibs().last pie() * lastFibs * lastFibs } Akka Concurrency Dominik Gruber • @the_dom
  • 18. Future val result = for { i <- Future(5) j <- Future(11) Blocking! } yield j Akka Concurrency Dominik Gruber • @the_dom
  • 19. Future Translates to: val result = fiveFuture.flatMap { i => Future(11) map { j => j } } Akka Concurrency Dominik Gruber • @the_dom
  • 20. Future val fiveFuture = Future(5) val elevenFuture = Future(11) val result = for { i <- fiveFuture Non-Blocking j <- elevenFuture } yield j Akka Concurrency Dominik Gruber • @the_dom
  • 21. Future Translates to: val result = fiveFuture.flatMap { i => elevenFuture map { j => j } } Akka Concurrency Dominik Gruber • @the_dom