SlideShare a Scribd company logo
1 of 31
Download to read offline
FP and Performance
Beyond Big
“O” Notation
Jamie Allen
Director of Consulting
Who Am I?

• Director of

Consulting for

• Author of

Effective Akka

@jamie_allen
2
Big “O” Notation

3
Many Developers Don’t Look Further

4
Reactive Applications

5
What is Performance?
Latency

Throughput

Footprint

6
Power Consumption!

7
There are no standards
The only rules you must follow is your
non-functional requirements!

8
We Love Functional Programming!
• But what is it?
•Just first class functions?
•Referential transparency?
•Immutability?
•Category theory?

9
Abstractions!
• They help us
reason about
our logic
• Decoupling
• Simplicity
• Correctness
• Reuse

10
Double Edged Sword
• We live in a world of abstractions
already!
•Languages on the JVM are DSL for bytecode
•Bytecode is an abstraction over macro
instructions
•Macro instructions are an abstraction over
micro instructions

11
JVM == Imperative
• The JVM is built to execute imperative
logic very fast
• The more we stray from imperative logic
constructs, the more we pay in terms of
performance

12
Penalties
• Increased allocations
• More bytecode executed to perform
tasks
• Less control over runtime performance

13
There Is A Fine Line Here
• We love to write “elegant” code, but this
is defined by your personal aesthetic
•Some people love prefix notation and sexpressions
•Some people see beauty in c-style constructs

14
Rap Genius

15
What About The Environment?

16
We Can’t Ignore the Cost!

17
Languages Impose Constraints
• “Choose-a-phone” languages versus those
with strictly defined language constructs

18
Languages “Pick” Abstractions For You
• Example: CSP versus Actor models
•Why must we choose?
•Why can’t we have both in libraries?
•Why can’t both be relevant to solving
problems in an application?

19
We Need to be Treated Like Adults!
• Every program will behave differently
• Choosing a language that imposes strict
rules forces us to make ugly choices

20
How Many Libs Have Performance
Tests?
• Very few
• You give up
control of your
ability to optimize
when you use
libraries

21
Asynchrony
• A wonderful tool for leveraging cores on
a machine
• Not faster than a single thread per se
• We must pay attention to Amdahl’s Law

22
Hardware
From the bottom up, computers
understand queues and message passing

23
Things to Avoid
• Parallel Collections
• STM
• Returns out of closures
• Boxing
• Lambdas! :)

24
Digression: Don’t Use OSX
• It’s lousy for doing performance analysis
• The JVM has issues, particularly with
visibility

25
Tools Also Have Issues
• Many tools only give you information
after the JVM is at a safepoint
• What does that tell us about our memory
consumption or thread stacks?

26
Tools That I Trust
•
•
•
•

jHiccup (pauses and stalls)
Java Microbenchmarking Harness
PrintGCStats (post-mortem tool on GC output in file)
GC:
• jClarity Censum
• GarbageCat
• VisualVM with Visual GC plugin

• htop (visualize user vs kernel usage)
• dstat (replaces vmstat, iostat and ifstat)
• --cpu, --mem, --aio, --top-io, --top-bio

• OProfile (system wide Linux profiler)

27
Pinning to Cores
• Use numactl for pinning to cores and
sockets
• taskset pins to cores only, no control
over cross-socket communication, which
has latency penalties, but useful for
laptop tests

28
JVM Flags to Use
• Pay close attention to the output from:
• +PrintGCDetails
• +PrintGCDateStamp
• +PrintGCCause
• +PrintGCApplicationStoppedTime
• +PrintTenuringDistribution (age of objects in survivor
spaces)
• +PrintSafepointStatistics (reason and timings)
• +PrintFlagsFinal (show entire JVM config)
• +PrintAssembly (must use
+UnlockDiagnosticVMOptions)

29
Don’t Overuse Memory Barriers
• Volatile variables aren’t required for
every field
• Think about how to organize updates to
fields and then update ONE volatile var
last to publish all

30
Thank You!

31

More Related Content

What's hot

Vyacheslav Voronchuk ''Enhancing durability of ReactJS applications with Elm ...
Vyacheslav Voronchuk ''Enhancing durability of ReactJS applications with Elm ...Vyacheslav Voronchuk ''Enhancing durability of ReactJS applications with Elm ...
Vyacheslav Voronchuk ''Enhancing durability of ReactJS applications with Elm ...
OdessaJS Conf
 

What's hot (12)

Vyacheslav Voronchuk ''Enhancing durability of ReactJS applications with Elm ...
Vyacheslav Voronchuk ''Enhancing durability of ReactJS applications with Elm ...Vyacheslav Voronchuk ''Enhancing durability of ReactJS applications with Elm ...
Vyacheslav Voronchuk ''Enhancing durability of ReactJS applications with Elm ...
 
Why akka
Why akkaWhy akka
Why akka
 
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
 
Performance optimization techniques for Java code
Performance optimization techniques for Java codePerformance optimization techniques for Java code
Performance optimization techniques for Java code
 
02 cldc
02 cldc02 cldc
02 cldc
 
From Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@LohikaFrom Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@Lohika
 
How netty works internally
How netty works internallyHow netty works internally
How netty works internally
 
Lesson1 intro
Lesson1 introLesson1 intro
Lesson1 intro
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
Secure Development with Android (Enrique Lopez Manas Technology Stream)
Secure Development with Android (Enrique Lopez Manas Technology Stream)Secure Development with Android (Enrique Lopez Manas Technology Stream)
Secure Development with Android (Enrique Lopez Manas Technology Stream)
 
Journey through the ML model deployment to production @DSC5
Journey through the ML model deployment to production @DSC5Journey through the ML model deployment to production @DSC5
Journey through the ML model deployment to production @DSC5
 
Journey through the ML model deployment to production by Stanko Kuveljic
Journey through the ML model deployment to production by Stanko KuveljicJourney through the ML model deployment to production by Stanko Kuveljic
Journey through the ML model deployment to production by Stanko Kuveljic
 

Similar to 20140228 fp and_performance

The economies of scaling software - Abdel Remani
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remani
jaxconf
 
The Economies of Scaling Software
The Economies of Scaling SoftwareThe Economies of Scaling Software
The Economies of Scaling Software
Abdelmonaim Remani
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
Eonblast
 
32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlays
myrajendra
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
xlight
 

Similar to 20140228 fp and_performance (20)

Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Oracle Fuson Middleware Diagnostics, Performance and TroubleshootOracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
 
Java-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdfJava-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdf
 
The economies of scaling software - Abdel Remani
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remani
 
The Economies of Scaling Software
The Economies of Scaling SoftwareThe Economies of Scaling Software
The Economies of Scaling Software
 
Cloud Native Compiler
Cloud Native CompilerCloud Native Compiler
Cloud Native Compiler
 
CodeScene: Get Deep Insights into Your (Clojure) Code [Clojure Vienna meetup ...
CodeScene: Get Deep Insights into Your (Clojure) Code [Clojure Vienna meetup ...CodeScene: Get Deep Insights into Your (Clojure) Code [Clojure Vienna meetup ...
CodeScene: Get Deep Insights into Your (Clojure) Code [Clojure Vienna meetup ...
 
Microservices: The Best Practices
Microservices: The Best PracticesMicroservices: The Best Practices
Microservices: The Best Practices
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
SSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJSSSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJS
 
Hadoop Operations: Keeping the Elephant Running Smoothly
Hadoop Operations: Keeping the Elephant Running SmoothlyHadoop Operations: Keeping the Elephant Running Smoothly
Hadoop Operations: Keeping the Elephant Running Smoothly
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
 
Scaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHPScaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHP
 
Scaling High Traffic Web Applications
Scaling High Traffic Web ApplicationsScaling High Traffic Web Applications
Scaling High Traffic Web Applications
 
32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlays
 
Memory Profiling
Memory ProfilingMemory Profiling
Memory Profiling
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Fixing_Twitter
Fixing_TwitterFixing_Twitter
Fixing_Twitter
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Towards "write once - run whenever possible" with Safety Critical Java af Ben...
Towards "write once - run whenever possible" with Safety Critical Java af Ben...Towards "write once - run whenever possible" with Safety Critical Java af Ben...
Towards "write once - run whenever possible" with Safety Critical Java af Ben...
 

More from shinolajla

20150411 mutability matrix of pain scala
20150411 mutability matrix of pain scala20150411 mutability matrix of pain scala
20150411 mutability matrix of pain scala
shinolajla
 
Effective akka scalaio
Effective akka scalaioEffective akka scalaio
Effective akka scalaio
shinolajla
 
Effective actors japanesesub
Effective actors japanesesubEffective actors japanesesub
Effective actors japanesesub
shinolajla
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 

More from shinolajla (18)

20180416 reactive is_a_product_rs
20180416 reactive is_a_product_rs20180416 reactive is_a_product_rs
20180416 reactive is_a_product_rs
 
20180416 reactive is_a_product
20180416 reactive is_a_product20180416 reactive is_a_product
20180416 reactive is_a_product
 
20161027 scala io_keynote
20161027 scala io_keynote20161027 scala io_keynote
20161027 scala io_keynote
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
 
20160524 ibm fast data meetup
20160524 ibm fast data meetup20160524 ibm fast data meetup
20160524 ibm fast data meetup
 
20160520 The Future of Services
20160520 The Future of Services20160520 The Future of Services
20160520 The Future of Services
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas
 
20160317 lagom sf scala
20160317 lagom sf scala20160317 lagom sf scala
20160317 lagom sf scala
 
Effective Akka v2
Effective Akka v2Effective Akka v2
Effective Akka v2
 
20150411 mutability matrix of pain scala
20150411 mutability matrix of pain scala20150411 mutability matrix of pain scala
20150411 mutability matrix of pain scala
 
Reactive applications tools of the trade huff po
Reactive applications   tools of the trade huff poReactive applications   tools of the trade huff po
Reactive applications tools of the trade huff po
 
Effective akka scalaio
Effective akka scalaioEffective akka scalaio
Effective akka scalaio
 
Cpu Caches
Cpu CachesCpu Caches
Cpu Caches
 
Real world akka recepies v3
Real world akka recepies v3Real world akka recepies v3
Real world akka recepies v3
 
Effective actors japanesesub
Effective actors japanesesubEffective actors japanesesub
Effective actors japanesesub
 
Effective Actors
Effective ActorsEffective Actors
Effective Actors
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
CPU Caches
CPU CachesCPU Caches
CPU Caches
 

20140228 fp and_performance

  • 1. FP and Performance Beyond Big “O” Notation Jamie Allen Director of Consulting
  • 2. Who Am I? • Director of Consulting for • Author of Effective Akka @jamie_allen 2
  • 4. Many Developers Don’t Look Further 4
  • 8. There are no standards The only rules you must follow is your non-functional requirements! 8
  • 9. We Love Functional Programming! • But what is it? •Just first class functions? •Referential transparency? •Immutability? •Category theory? 9
  • 10. Abstractions! • They help us reason about our logic • Decoupling • Simplicity • Correctness • Reuse 10
  • 11. Double Edged Sword • We live in a world of abstractions already! •Languages on the JVM are DSL for bytecode •Bytecode is an abstraction over macro instructions •Macro instructions are an abstraction over micro instructions 11
  • 12. JVM == Imperative • The JVM is built to execute imperative logic very fast • The more we stray from imperative logic constructs, the more we pay in terms of performance 12
  • 13. Penalties • Increased allocations • More bytecode executed to perform tasks • Less control over runtime performance 13
  • 14. There Is A Fine Line Here • We love to write “elegant” code, but this is defined by your personal aesthetic •Some people love prefix notation and sexpressions •Some people see beauty in c-style constructs 14
  • 16. What About The Environment? 16
  • 17. We Can’t Ignore the Cost! 17
  • 18. Languages Impose Constraints • “Choose-a-phone” languages versus those with strictly defined language constructs 18
  • 19. Languages “Pick” Abstractions For You • Example: CSP versus Actor models •Why must we choose? •Why can’t we have both in libraries? •Why can’t both be relevant to solving problems in an application? 19
  • 20. We Need to be Treated Like Adults! • Every program will behave differently • Choosing a language that imposes strict rules forces us to make ugly choices 20
  • 21. How Many Libs Have Performance Tests? • Very few • You give up control of your ability to optimize when you use libraries 21
  • 22. Asynchrony • A wonderful tool for leveraging cores on a machine • Not faster than a single thread per se • We must pay attention to Amdahl’s Law 22
  • 23. Hardware From the bottom up, computers understand queues and message passing 23
  • 24. Things to Avoid • Parallel Collections • STM • Returns out of closures • Boxing • Lambdas! :) 24
  • 25. Digression: Don’t Use OSX • It’s lousy for doing performance analysis • The JVM has issues, particularly with visibility 25
  • 26. Tools Also Have Issues • Many tools only give you information after the JVM is at a safepoint • What does that tell us about our memory consumption or thread stacks? 26
  • 27. Tools That I Trust • • • • jHiccup (pauses and stalls) Java Microbenchmarking Harness PrintGCStats (post-mortem tool on GC output in file) GC: • jClarity Censum • GarbageCat • VisualVM with Visual GC plugin • htop (visualize user vs kernel usage) • dstat (replaces vmstat, iostat and ifstat) • --cpu, --mem, --aio, --top-io, --top-bio • OProfile (system wide Linux profiler) 27
  • 28. Pinning to Cores • Use numactl for pinning to cores and sockets • taskset pins to cores only, no control over cross-socket communication, which has latency penalties, but useful for laptop tests 28
  • 29. JVM Flags to Use • Pay close attention to the output from: • +PrintGCDetails • +PrintGCDateStamp • +PrintGCCause • +PrintGCApplicationStoppedTime • +PrintTenuringDistribution (age of objects in survivor spaces) • +PrintSafepointStatistics (reason and timings) • +PrintFlagsFinal (show entire JVM config) • +PrintAssembly (must use +UnlockDiagnosticVMOptions) 29
  • 30. Don’t Overuse Memory Barriers • Volatile variables aren’t required for every field • Think about how to organize updates to fields and then update ONE volatile var last to publish all 30