SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

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
 

Kürzlich hochgeladen (20)

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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 

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