SlideShare une entreprise Scribd logo
1  sur  67
Télécharger pour lire hors ligne
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY THIS TALK?
Tools, of course, can be the subtlest of traps
— Neil Gaiman
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
MANUEL.BERNHARDT.IO
> Helping teams to get started with
reactive systems...
> ...and to keep them running
> Lightbend training partner (Akka,
Advanced Akka, Scala)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
MANUEL.BERNHARDT.IO
> Helping teams to get started with
reactive systems...
> ...and to keep them running
> Lightbend training partner (Akka,
Advanced Akka, Scala)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
If you want to make enemies, try
to change something.
— Woodrow Wilson
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #1
GLOBAL MUTABLE STATE
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
> it's okay for an actor to have mutable state
> as long as it retains total control over it and is the
only one to see it
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN IT HAPPEN?
> reference to mutable state in messages
> closing over mutable state in asynchronous calls
> passing shared mutable state to an actor's
constructor
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS THIS BAD?
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD
> use immutable messages for state updates (e.g.
broadcasting for configuration changes)
> use queries for state inquiries (e.g. using the ask
pattern)
> for asynchronous calls, always use the pipe pattern
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
The two enemies of human
happiness are pain and boredom.
— Arthur Schopenhauer
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #2
FLAT ACTOR HIERARCHIES
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN IT HAPPEN?
"Ceci n'est pas une hierarchie" - Magritte, 1928
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
IF YOUR ACTOR SYSTEM HAS NO HIERARCHY
YOU ARE MISSING THE POINT.
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS THIS BAD?
> actor systems are designed to handle failures through
hierarchy
> ergo: no hierarchy, no failure handling
> why then bother to use actors in the first place?
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
How exception catch blocks are used in Java projects 1
1
Analysis of Exception Handling Patterns in Java Projects: An Empirical Study (S. Nakshatri, M. Hegde, S. Thandra)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
Build hierarchies.
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
The mother of excess is not joy
but joylessness.
— Friedrich Nietzsche
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #3
TOO MANY ACTOR SYSTEMS
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN IT HAPPEN?
> eagerly wanting to isolate things
> and not understanding how Akka
works
> (but the intent is good)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS THIS BAD?
> each actor system has at least one dispatcher backed
by a thread pool
> multiple actor systems = multiple thread pools,
contending for the same resources
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INTEAD?
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
Bulkheading with custom dispatchers
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
contexts {
graph-db {
thread-pool-executor {
fixed-pool-size = 2
}
}
}
val graph: ActorRef = context.actorOf(
props = Props[Graph].withDispatcher("contexts.graph-db"),
name = "graph"
)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
"Words, words, words."
— William Shakespeare, Hamlet
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #4
LOGGING (THE WRONG WAY)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
> string concatentation
log().debug("Received message: " + msg.toString());
> non-asynchronous logging
> not turning debug logging off in
production settings
> let's get real: logging to files (it is
2017)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS THIS BAD?
> actor sytems are meant to process millions of
messages per second
> getting logging wrong has a huge performance impact
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
> use Akka's built-in logging facility
> carefully configure the logback appenders, use
asynchronous variants
> use string interpolation: log().debug("Received
message {}", msg);
> use a logging aggregation mechanism (logstash &
friends)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
All that we see or seem is but a
dream within a dream.
— Edgar Allan Poe
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #5BEING OUT OF TOUCH WITH THE HARDWARE
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
XKCDE 2
2
http://xkcd.com/1764/
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS THIS A BAD THING?
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS THIS A BAD THING?
fork-join-executor {
# Min number of threads to cap factor-based parallelism number to
parallelism-min = 2
# Parallelism (threads) ... ceil(available processors * factor)
parallelism-factor = 2.0
# Max number of threads to cap factor-based parallelism number to
parallelism-max = 10
}
ceil(available processors * factor)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS THIS BAD?
> suboptimal or simply wrong configuration for the
amount of CPU cores
> costs of context switching
> contending for network
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
> know your hardware and configure accordingly
> beware of virtualization (is the hypervisor lying to
you?)
> run load tests on the same hardware as your target
production system
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
"...some men aren't looking for
anything logical, like money. They
can't be bought, bullied, reasoned,
or negotiated with. Some men just
want to watch the world burn."
— Alfred Pennyworth, Batman, The Dark Knight
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #6
BLOCKINGScala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
> calling a synchronous API
> or calling an API that calls an API that calls an API...
that calls a synchronous API
> explicitly waiting for the completion of a Future
> using Thread.sleep (don't!)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
> if you really must (legacy API), use a dedicated
dispatcher optimized for the blocking case (and limited
in resources)
> always use Future in combination with the pipe pattern
> use the akka scheduler if you are waiting for something
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ASK AND PIPE
def receive = {
case ComputePi(precision) =>
val originalSender = sender()
implicit val timeout = Timeout(5.seconds)
val computation: Future[Pi] = piActor ? Compute(precision, originalSender)
val result = computation.recover { case t: AskTimeoutException =>
ComputationTimeout(originalSender, precision)
}
result pipeTo self
case Pi(value, originalSender) =>
originalSender ! PiResult(value)
case ComputationTimeout(originalSender, precision) =>
originalSender ! ComputationFailed(s"Sorry, $precision was too high.")
}
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
A man who dares to waste one
hour of time has not discovered
the value of life.
— Charles Darwin
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #7
RE-INVENTING AKKA TOOLS
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
> not reading the documentation
> not keeping up with updates
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
> re-inventing at-least-once delivery (Akka Persistance
+ AtLeastOnceDelivery)
> re-inventing back-off supervision
(BackoffSupervisor)
> re-inventing message prioritization
(*ControlAwareMailbox, *PriorityMailbox,
*StablePriorityMailbox)
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS THIS BAD?
> see the introductory quote for this anti-pattern
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
> read the documentation
> call me
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
This is the way the world ends
Not with a bang but a covfefe.
— T.S. Eliot
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #8
USING JAVA SERIALIZATION
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
> leaving the default on
> Java serialization over the wire
> Java serialization in Akka Persistance
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHY IS IT BAD?
> performance penalty!
> poor candidate for protocol evolution - message
evolutions result in older components not able to
process them any longer
> persistance - messages and snapshots can't be
processed any longer after changes
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
> use a proper binary format
> protobuf, avro, thrift
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
THANK YOU
> Questions, comments, feedback?
> Contact me at manuel@bernhardt.io / @elmanu
> Check out more anti-patterns at https://
manuel.bernhardt.io
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu

Contenu connexe

Similaire à Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of

Writing a REST Interconnection Library in Swift
Writing a REST Interconnection Library in SwiftWriting a REST Interconnection Library in Swift
Writing a REST Interconnection Library in SwiftPablo Villar
 
Briefing on the Modern ML Stack with R
 Briefing on the Modern ML Stack with R Briefing on the Modern ML Stack with R
Briefing on the Modern ML Stack with RDatabricks
 
Session 5.2 multi-core meta-blocking for big linked data
Session 5.2   multi-core meta-blocking for big linked dataSession 5.2   multi-core meta-blocking for big linked data
Session 5.2 multi-core meta-blocking for big linked datasemanticsconference
 
Alpine academy apache spark series #1 introduction to cluster computing wit...
Alpine academy apache spark series #1   introduction to cluster computing wit...Alpine academy apache spark series #1   introduction to cluster computing wit...
Alpine academy apache spark series #1 introduction to cluster computing wit...Holden Karau
 
Regex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadRegex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadAll Things Open
 
Spark ML for custom models - FOSDEM HPC 2017
Spark ML for custom models - FOSDEM HPC 2017Spark ML for custom models - FOSDEM HPC 2017
Spark ML for custom models - FOSDEM HPC 2017Holden Karau
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to AnsibleDan Vaida
 
Webcast: Balancing standardization against the need for creativity
Webcast: Balancing standardization against the need for creativityWebcast: Balancing standardization against the need for creativity
Webcast: Balancing standardization against the need for creativityScriptorium Publishing
 
Scaling PyData Up and Out
Scaling PyData Up and OutScaling PyData Up and Out
Scaling PyData Up and OutTravis Oliphant
 
NoSQL and SQL Anti Patterns
NoSQL and SQL Anti PatternsNoSQL and SQL Anti Patterns
NoSQL and SQL Anti PatternsGleicon Moraes
 
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Roger Huang
 
Microservices, containers, and machine learning
Microservices, containers, and machine learningMicroservices, containers, and machine learning
Microservices, containers, and machine learningPaco Nathan
 
GraphX: Graph analytics for insights about developer communities
GraphX: Graph analytics for insights about developer communitiesGraphX: Graph analytics for insights about developer communities
GraphX: Graph analytics for insights about developer communitiesPaco Nathan
 
Learning Content Patterns from Linked Data
Learning Content Patterns from Linked DataLearning Content Patterns from Linked Data
Learning Content Patterns from Linked DataEmir Muñoz
 
apidays LIVE Paris - JSON Schema - draft 2020 and other things you should kno...
apidays LIVE Paris - JSON Schema - draft 2020 and other things you should kno...apidays LIVE Paris - JSON Schema - draft 2020 and other things you should kno...
apidays LIVE Paris - JSON Schema - draft 2020 and other things you should kno...apidays
 
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams langer4711
 

Similaire à Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of (20)

Writing a REST Interconnection Library in Swift
Writing a REST Interconnection Library in SwiftWriting a REST Interconnection Library in Swift
Writing a REST Interconnection Library in Swift
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Briefing on the Modern ML Stack with R
 Briefing on the Modern ML Stack with R Briefing on the Modern ML Stack with R
Briefing on the Modern ML Stack with R
 
Session 5.2 multi-core meta-blocking for big linked data
Session 5.2   multi-core meta-blocking for big linked dataSession 5.2   multi-core meta-blocking for big linked data
Session 5.2 multi-core meta-blocking for big linked data
 
Alpine academy apache spark series #1 introduction to cluster computing wit...
Alpine academy apache spark series #1   introduction to cluster computing wit...Alpine academy apache spark series #1   introduction to cluster computing wit...
Alpine academy apache spark series #1 introduction to cluster computing wit...
 
Regex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadRegex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language Instead
 
Easy R
Easy REasy R
Easy R
 
Scala+data
Scala+dataScala+data
Scala+data
 
Spark ML for custom models - FOSDEM HPC 2017
Spark ML for custom models - FOSDEM HPC 2017Spark ML for custom models - FOSDEM HPC 2017
Spark ML for custom models - FOSDEM HPC 2017
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to Ansible
 
Webcast: Balancing standardization against the need for creativity
Webcast: Balancing standardization against the need for creativityWebcast: Balancing standardization against the need for creativity
Webcast: Balancing standardization against the need for creativity
 
Scaling PyData Up and Out
Scaling PyData Up and OutScaling PyData Up and Out
Scaling PyData Up and Out
 
NoSQL and SQL Anti Patterns
NoSQL and SQL Anti PatternsNoSQL and SQL Anti Patterns
NoSQL and SQL Anti Patterns
 
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
 
Scala 20140715
Scala 20140715Scala 20140715
Scala 20140715
 
Microservices, containers, and machine learning
Microservices, containers, and machine learningMicroservices, containers, and machine learning
Microservices, containers, and machine learning
 
GraphX: Graph analytics for insights about developer communities
GraphX: Graph analytics for insights about developer communitiesGraphX: Graph analytics for insights about developer communities
GraphX: Graph analytics for insights about developer communities
 
Learning Content Patterns from Linked Data
Learning Content Patterns from Linked DataLearning Content Patterns from Linked Data
Learning Content Patterns from Linked Data
 
apidays LIVE Paris - JSON Schema - draft 2020 and other things you should kno...
apidays LIVE Paris - JSON Schema - draft 2020 and other things you should kno...apidays LIVE Paris - JSON Schema - draft 2020 and other things you should kno...
apidays LIVE Paris - JSON Schema - draft 2020 and other things you should kno...
 
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
Stream Puzzlers – Traps and Pitfalls in Using Java 8 Streams
 

Plus de Manuel Bernhardt

Is there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems HamburgIs there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems HamburgManuel Bernhardt
 
Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018Manuel Bernhardt
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?Manuel Bernhardt
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?Manuel Bernhardt
 
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 2015Manuel Bernhardt
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysManuel Bernhardt
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMManuel Bernhardt
 
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 migrationManuel Bernhardt
 
Project Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 monthsProject Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 monthsManuel Bernhardt
 
Tips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 projectTips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 projectManuel Bernhardt
 

Plus de Manuel Bernhardt (14)

Is there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems HamburgIs there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems Hamburg
 
Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?
 
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
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
 
Writing a technical book
Writing a technical bookWriting a technical book
Writing a technical book
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
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
 
Project Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 monthsProject Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 months
 
Scala - Java2Days Sofia
Scala - Java2Days SofiaScala - Java2Days Sofia
Scala - Java2Days Sofia
 
Tips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 projectTips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 project
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala pitfalls
Scala pitfallsScala pitfalls
Scala pitfalls
 

Dernier

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 

Dernier (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 

Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of

  • 1. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 2. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 3. WHY THIS TALK? Tools, of course, can be the subtlest of traps — Neil Gaiman Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 4. MANUEL.BERNHARDT.IO > Helping teams to get started with reactive systems... > ...and to keep them running > Lightbend training partner (Akka, Advanced Akka, Scala) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 5. MANUEL.BERNHARDT.IO > Helping teams to get started with reactive systems... > ...and to keep them running > Lightbend training partner (Akka, Advanced Akka, Scala) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 6. If you want to make enemies, try to change something. — Woodrow Wilson Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 7. ANTI-PATTERN #1 GLOBAL MUTABLE STATE Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 8. > it's okay for an actor to have mutable state > as long as it retains total control over it and is the only one to see it Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 9. HOW CAN IT HAPPEN? > reference to mutable state in messages > closing over mutable state in asynchronous calls > passing shared mutable state to an actor's constructor Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 10. WHY IS THIS BAD? Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 11. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 12. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 13. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 14. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 15. WHAT TO DO INSTEAD > use immutable messages for state updates (e.g. broadcasting for configuration changes) > use queries for state inquiries (e.g. using the ask pattern) > for asynchronous calls, always use the pipe pattern Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 16. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 17. The two enemies of human happiness are pain and boredom. — Arthur Schopenhauer Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 18. ANTI-PATTERN #2 FLAT ACTOR HIERARCHIES Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 19. HOW CAN IT HAPPEN? "Ceci n'est pas une hierarchie" - Magritte, 1928 Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 20. IF YOUR ACTOR SYSTEM HAS NO HIERARCHY YOU ARE MISSING THE POINT. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 21. WHY IS THIS BAD? > actor systems are designed to handle failures through hierarchy > ergo: no hierarchy, no failure handling > why then bother to use actors in the first place? Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 22. How exception catch blocks are used in Java projects 1 1 Analysis of Exception Handling Patterns in Java Projects: An Empirical Study (S. Nakshatri, M. Hegde, S. Thandra) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 23. WHAT TO DO INSTEAD? Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 24. WHAT TO DO INSTEAD? Build hierarchies. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 25. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 26. The mother of excess is not joy but joylessness. — Friedrich Nietzsche Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 27. ANTI-PATTERN #3 TOO MANY ACTOR SYSTEMS Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 28. HOW CAN IT HAPPEN? > eagerly wanting to isolate things > and not understanding how Akka works > (but the intent is good) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 29. WHY IS THIS BAD? > each actor system has at least one dispatcher backed by a thread pool > multiple actor systems = multiple thread pools, contending for the same resources Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 30. WHAT TO DO INTEAD? Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 31. WHAT TO DO INSTEAD? Bulkheading with custom dispatchers Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 32. contexts { graph-db { thread-pool-executor { fixed-pool-size = 2 } } } val graph: ActorRef = context.actorOf( props = Props[Graph].withDispatcher("contexts.graph-db"), name = "graph" ) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 33. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 34. "Words, words, words." — William Shakespeare, Hamlet Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 35. ANTI-PATTERN #4 LOGGING (THE WRONG WAY) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 36. HOW CAN THIS HAPPEN? > string concatentation log().debug("Received message: " + msg.toString()); > non-asynchronous logging > not turning debug logging off in production settings > let's get real: logging to files (it is 2017) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 37. WHY IS THIS BAD? > actor sytems are meant to process millions of messages per second > getting logging wrong has a huge performance impact Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 38. WHAT TO DO INSTEAD? > use Akka's built-in logging facility > carefully configure the logback appenders, use asynchronous variants > use string interpolation: log().debug("Received message {}", msg); > use a logging aggregation mechanism (logstash & friends) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 39. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 40. All that we see or seem is but a dream within a dream. — Edgar Allan Poe Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 41. ANTI-PATTERN #5BEING OUT OF TOUCH WITH THE HARDWARE Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 42. HOW CAN THIS HAPPEN? XKCDE 2 2 http://xkcd.com/1764/ Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 43. WHY IS THIS A BAD THING? Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 44. WHY IS THIS A BAD THING? fork-join-executor { # Min number of threads to cap factor-based parallelism number to parallelism-min = 2 # Parallelism (threads) ... ceil(available processors * factor) parallelism-factor = 2.0 # Max number of threads to cap factor-based parallelism number to parallelism-max = 10 } ceil(available processors * factor) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 45. WHY IS THIS BAD? > suboptimal or simply wrong configuration for the amount of CPU cores > costs of context switching > contending for network Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 46. WHAT TO DO INSTEAD? > know your hardware and configure accordingly > beware of virtualization (is the hypervisor lying to you?) > run load tests on the same hardware as your target production system Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 47. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 48. "...some men aren't looking for anything logical, like money. They can't be bought, bullied, reasoned, or negotiated with. Some men just want to watch the world burn." — Alfred Pennyworth, Batman, The Dark Knight Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 49. ANTI-PATTERN #6 BLOCKINGScala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 50. HOW CAN THIS HAPPEN? > calling a synchronous API > or calling an API that calls an API that calls an API... that calls a synchronous API > explicitly waiting for the completion of a Future > using Thread.sleep (don't!) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 51. WHAT TO DO INSTEAD? > if you really must (legacy API), use a dedicated dispatcher optimized for the blocking case (and limited in resources) > always use Future in combination with the pipe pattern > use the akka scheduler if you are waiting for something Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 52. ASK AND PIPE def receive = { case ComputePi(precision) => val originalSender = sender() implicit val timeout = Timeout(5.seconds) val computation: Future[Pi] = piActor ? Compute(precision, originalSender) val result = computation.recover { case t: AskTimeoutException => ComputationTimeout(originalSender, precision) } result pipeTo self case Pi(value, originalSender) => originalSender ! PiResult(value) case ComputationTimeout(originalSender, precision) => originalSender ! ComputationFailed(s"Sorry, $precision was too high.") } Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 53. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 54. A man who dares to waste one hour of time has not discovered the value of life. — Charles Darwin Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 55. ANTI-PATTERN #7 RE-INVENTING AKKA TOOLS Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 56. HOW CAN THIS HAPPEN? > not reading the documentation > not keeping up with updates Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 57. HOW CAN THIS HAPPEN? > re-inventing at-least-once delivery (Akka Persistance + AtLeastOnceDelivery) > re-inventing back-off supervision (BackoffSupervisor) > re-inventing message prioritization (*ControlAwareMailbox, *PriorityMailbox, *StablePriorityMailbox) Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 58. WHY IS THIS BAD? > see the introductory quote for this anti-pattern Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 59. WHAT TO DO INSTEAD? > read the documentation > call me Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 60. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 61. This is the way the world ends Not with a bang but a covfefe. — T.S. Eliot Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 62. ANTI-PATTERN #8 USING JAVA SERIALIZATION Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 63. HOW CAN THIS HAPPEN? > leaving the default on > Java serialization over the wire > Java serialization in Akka Persistance Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 64. WHY IS IT BAD? > performance penalty! > poor candidate for protocol evolution - message evolutions result in older components not able to process them any longer > persistance - messages and snapshots can't be processed any longer after changes Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 65. WHAT TO DO INSTEAD? > use a proper binary format > protobuf, avro, thrift Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 66. THANK YOU > Questions, comments, feedback? > Contact me at manuel@bernhardt.io / @elmanu > Check out more anti-patterns at https:// manuel.bernhardt.io Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu
  • 67. Scala Days 2017 Copenhagen - manuel.bernhardt.io - @elmanu