SlideShare a Scribd company logo
1 of 57
Download to read offline
8 AKKA ANTI-PATTERNS
YOU'D BETTER BE AWARE OF
SCALA ITALY 2017 ROME
MANUEL BERNHARDT / @ELMANU
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHY THIS TALK?
Tools, of course, can be the subtlest of traps
— Neil Gaiman
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
MANUEL.BERNHARDT.IO
> Helping teams to get started with
reactive systems
> Lightbend training partner (Fast
Track to Akka, Advanced Akka, Fast
Track to Scala)
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
If you want to make enemies, try
to change something.
— Woodrow Wilson
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #1
GLOBAL MUTABLE STATE
Scala Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHY IS THIS BAD?
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
Scala Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
The two enemies of human
happiness are pain and boredom.
— Arthur Schopenhauer
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #2
FLAT ACTOR HIERARCHIES
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
HOW CAN IT HAPPEN?
"Ceci n'est pas une hierarchie" - Magritte, 1928
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
IF YOUR ACTOR SYSTEM HAS NO HIERARCHY
YOU ARE MISSING THE POINT.
Scala Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
Build hierarchies.
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
The mother of excess is not joy
but joylessness.
— Friedrich Nietzsche
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #3
TOO MANY ACTOR SYSTEMS
Scala Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHAT TO DO INTEAD?
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
Bulkheading with custom dispatchers
Scala Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
"Words, words, words."
— William Shakespeare, Hamlet
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #4
LOGGING (THE WRONG WAY)
Scala Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
All that we see or seem is but a
dream within a dream.
— Edgar Allan Poe
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #5BEING OUT OF TOUCH WITH THE HARDWARE
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
XKCDE 2
2
http://xkcd.com/1764/
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHY IS THIS A BAD THING?
Scala Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #6
BLOCKINGScala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
> calling a synchronous API
> explicitly waiting for the completion of a Future
> using Thread.sleep (don't!)
Scala Italy 2017 Rome - 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 Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
A man who dares to waste one
hour of time has not discovered
the value of life.
— Charles Darwin
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #7
RE-INVENTING AKKA TOOLS
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
> not reading the documentation
> not keeping up with updates
Scala Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHY IS THIS BAD?
> see the introductory quote for this anti-pattern
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
> read the documentation
> call me
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
This is the way the world ends
Not with a bang but a whimper.
— T.S. Eliot
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
ANTI-PATTERN #8
USING JAVA SERIALIZATION
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
HOW CAN THIS HAPPEN?
> leaving the default on
> Java serialization over the wire
> Java serialization in Akka Persistance
Scala Italy 2017 Rome - 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
WHAT TO DO INSTEAD?
> use a proper binary format
> protobuf, avro, thrift
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
THANK YOU
> Questions, comments, feedback?
> Contact me at manuel@bernhardt.io / @elmanu
> Check out my blog at https://manuel.bernhardt.io
Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu

More Related Content

Similar to 8 Akka anti-patterns you'd better be aware of

Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6
Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6
Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6Lightbend
 
Hidden features in ActiveRecord and the future
Hidden features in ActiveRecord and the futureHidden features in ActiveRecord and the future
Hidden features in ActiveRecord and the futureTejas Bubane
 
MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
MySQL - Scale Out @ CloudParty 2013 Milano Talent GardenMySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
MySQL - Scale Out @ CloudParty 2013 Milano Talent GardenCorley S.r.l.
 
manifest file on SCORM 1.2
manifest file on SCORM 1.2manifest file on SCORM 1.2
manifest file on SCORM 1.2aureliomld
 
Oop vs functional stop the fight and start building message driven serverle...
Oop vs functional   stop the fight and start building message driven serverle...Oop vs functional   stop the fight and start building message driven serverle...
Oop vs functional stop the fight and start building message driven serverle...Alessandro Confetti
 
Alessandro Confetti - Oop vs functional: stop the fight and start building me...
Alessandro Confetti - Oop vs functional: stop the fight and start building me...Alessandro Confetti - Oop vs functional: stop the fight and start building me...
Alessandro Confetti - Oop vs functional: stop the fight and start building me...Codemotion
 
Alessandro Confetti - Oop vs functional: stop the fight and start building me...
Alessandro Confetti - Oop vs functional: stop the fight and start building me...Alessandro Confetti - Oop vs functional: stop the fight and start building me...
Alessandro Confetti - Oop vs functional: stop the fight and start building me...Codemotion
 
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
 
Once you go cloud you never go down - by Enter - festival ICT 2015
Once you go cloud you never go down - by Enter - festival ICT 2015Once you go cloud you never go down - by Enter - festival ICT 2015
Once you go cloud you never go down - by Enter - festival ICT 2015festival ICT 2016
 
Once you go cloud you never go down
Once you go cloud you never go downOnce you go cloud you never go down
Once you go cloud you never go downDrupalDay
 
Am i doing deployments right v2
Am i doing deployments right v2Am i doing deployments right v2
Am i doing deployments right v2Matteo Emili
 
Learn how to build decentralized and serverless html5 applications with embar...
Learn how to build decentralized and serverless html5 applications with embar...Learn how to build decentralized and serverless html5 applications with embar...
Learn how to build decentralized and serverless html5 applications with embar...Alessandro Confetti
 
Learn how to build decentralized and serverless html5 applications with Embar...
Learn how to build decentralized and serverless html5 applications with Embar...Learn how to build decentralized and serverless html5 applications with Embar...
Learn how to build decentralized and serverless html5 applications with Embar...Codemotion
 
Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Anand Sampat
 
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus44CON
 
Sinatra Rack And Middleware
Sinatra Rack And MiddlewareSinatra Rack And Middleware
Sinatra Rack And MiddlewareBen Schwarz
 
ITea&Coffee: React best practices
ITea&Coffee: React best practicesITea&Coffee: React best practices
ITea&Coffee: React best practicesAgata Piórkowska
 
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...ITCamp
 
Fast Slim Correct: The History and Evolution of JavaScript.
Fast Slim Correct: The History and Evolution of JavaScript.Fast Slim Correct: The History and Evolution of JavaScript.
Fast Slim Correct: The History and Evolution of JavaScript.John Dalziel
 

Similar to 8 Akka anti-patterns you'd better be aware of (20)

Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6
Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6
Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6
 
Hidden features in ActiveRecord and the future
Hidden features in ActiveRecord and the futureHidden features in ActiveRecord and the future
Hidden features in ActiveRecord and the future
 
MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
MySQL - Scale Out @ CloudParty 2013 Milano Talent GardenMySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
 
manifest file on SCORM 1.2
manifest file on SCORM 1.2manifest file on SCORM 1.2
manifest file on SCORM 1.2
 
MariaDB workshop
MariaDB workshopMariaDB workshop
MariaDB workshop
 
Oop vs functional stop the fight and start building message driven serverle...
Oop vs functional   stop the fight and start building message driven serverle...Oop vs functional   stop the fight and start building message driven serverle...
Oop vs functional stop the fight and start building message driven serverle...
 
Alessandro Confetti - Oop vs functional: stop the fight and start building me...
Alessandro Confetti - Oop vs functional: stop the fight and start building me...Alessandro Confetti - Oop vs functional: stop the fight and start building me...
Alessandro Confetti - Oop vs functional: stop the fight and start building me...
 
Alessandro Confetti - Oop vs functional: stop the fight and start building me...
Alessandro Confetti - Oop vs functional: stop the fight and start building me...Alessandro Confetti - Oop vs functional: stop the fight and start building me...
Alessandro Confetti - Oop vs functional: stop the fight and start building me...
 
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
 
Once you go cloud you never go down - by Enter - festival ICT 2015
Once you go cloud you never go down - by Enter - festival ICT 2015Once you go cloud you never go down - by Enter - festival ICT 2015
Once you go cloud you never go down - by Enter - festival ICT 2015
 
Once you go cloud you never go down
Once you go cloud you never go downOnce you go cloud you never go down
Once you go cloud you never go down
 
Am i doing deployments right v2
Am i doing deployments right v2Am i doing deployments right v2
Am i doing deployments right v2
 
Learn how to build decentralized and serverless html5 applications with embar...
Learn how to build decentralized and serverless html5 applications with embar...Learn how to build decentralized and serverless html5 applications with embar...
Learn how to build decentralized and serverless html5 applications with embar...
 
Learn how to build decentralized and serverless html5 applications with Embar...
Learn how to build decentralized and serverless html5 applications with Embar...Learn how to build decentralized and serverless html5 applications with Embar...
Learn how to build decentralized and serverless html5 applications with Embar...
 
Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)
 
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
 
Sinatra Rack And Middleware
Sinatra Rack And MiddlewareSinatra Rack And Middleware
Sinatra Rack And Middleware
 
ITea&Coffee: React best practices
ITea&Coffee: React best practicesITea&Coffee: React best practices
ITea&Coffee: React best practices
 
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
 
Fast Slim Correct: The History and Evolution of JavaScript.
Fast Slim Correct: The History and Evolution of JavaScript.Fast Slim Correct: The History and Evolution of JavaScript.
Fast Slim Correct: The History and Evolution of JavaScript.
 

More from 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
 

More from 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
 

Recently uploaded

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 

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

  • 1. 8 AKKA ANTI-PATTERNS YOU'D BETTER BE AWARE OF SCALA ITALY 2017 ROME MANUEL BERNHARDT / @ELMANU Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 2. WHY THIS TALK? Tools, of course, can be the subtlest of traps — Neil Gaiman Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 3. MANUEL.BERNHARDT.IO > Helping teams to get started with reactive systems > Lightbend training partner (Fast Track to Akka, Advanced Akka, Fast Track to Scala) Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 4. If you want to make enemies, try to change something. — Woodrow Wilson Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 5. ANTI-PATTERN #1 GLOBAL MUTABLE STATE Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 6. > 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 7. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 8. WHY IS THIS BAD? Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 9. Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 10. Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 11. Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 12. Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 13. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 14. The two enemies of human happiness are pain and boredom. — Arthur Schopenhauer Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 15. ANTI-PATTERN #2 FLAT ACTOR HIERARCHIES Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 16. HOW CAN IT HAPPEN? "Ceci n'est pas une hierarchie" - Magritte, 1928 Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 17. IF YOUR ACTOR SYSTEM HAS NO HIERARCHY YOU ARE MISSING THE POINT. Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 18. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 19. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 20. WHAT TO DO INSTEAD? Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 21. WHAT TO DO INSTEAD? Build hierarchies. Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 22. The mother of excess is not joy but joylessness. — Friedrich Nietzsche Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 23. ANTI-PATTERN #3 TOO MANY ACTOR SYSTEMS Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 24. HOW CAN IT HAPPEN? > eagerly wanting to isolate things > and not understanding how Akka works > (but the intent is good) Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 25. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 26. WHAT TO DO INTEAD? Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 27. WHAT TO DO INSTEAD? Bulkheading with custom dispatchers Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 28. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 29. "Words, words, words." — William Shakespeare, Hamlet Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 30. ANTI-PATTERN #4 LOGGING (THE WRONG WAY) Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 31. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 32. WHY IS THIS BAD? > actor sytems are meant to process millions of messages per second > getting logging wrong has a huge performance impact Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 33. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 34. All that we see or seem is but a dream within a dream. — Edgar Allan Poe Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 35. ANTI-PATTERN #5BEING OUT OF TOUCH WITH THE HARDWARE Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 36. HOW CAN THIS HAPPEN? XKCDE 2 2 http://xkcd.com/1764/ Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 37. WHY IS THIS A BAD THING? Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 38. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 39. WHY IS THIS BAD? > suboptimal or simply wrong configuration for the amount of CPU cores > costs of context switching > contending for network Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 40. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 41. "...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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 42. ANTI-PATTERN #6 BLOCKINGScala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 43. HOW CAN THIS HAPPEN? > calling a synchronous API > explicitly waiting for the completion of a Future > using Thread.sleep (don't!) Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 44. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 45. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 46. A man who dares to waste one hour of time has not discovered the value of life. — Charles Darwin Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 47. ANTI-PATTERN #7 RE-INVENTING AKKA TOOLS Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 48. HOW CAN THIS HAPPEN? > not reading the documentation > not keeping up with updates Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 49. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 50. WHY IS THIS BAD? > see the introductory quote for this anti-pattern Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 51. WHAT TO DO INSTEAD? > read the documentation > call me Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 52. This is the way the world ends Not with a bang but a whimper. — T.S. Eliot Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 53. ANTI-PATTERN #8 USING JAVA SERIALIZATION Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 54. HOW CAN THIS HAPPEN? > leaving the default on > Java serialization over the wire > Java serialization in Akka Persistance Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 55. 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 Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 56. WHAT TO DO INSTEAD? > use a proper binary format > protobuf, avro, thrift Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu
  • 57. THANK YOU > Questions, comments, feedback? > Contact me at manuel@bernhardt.io / @elmanu > Check out my blog at https://manuel.bernhardt.io Scala Italy 2017 Rome - manuel.bernhardt.io - @elmanu