20140228 fp and_performance
DESCRIPTION
TRANSCRIPT
![Page 1: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/1.jpg)
FP and PerformanceBeyond Big
“O” NotationJamie Allen
Director of Consulting
![Page 2: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/2.jpg)
Who Am I?
2
• Director of Consulting for
• Author of Effective Akka
@jamie_allen
![Page 3: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/3.jpg)
Big “O” Notation
3
![Page 4: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/4.jpg)
Many Developers Don’t Look Further
4
![Page 5: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/5.jpg)
Reactive Applications
5
![Page 6: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/6.jpg)
What is Performance?
6
Throughput
Latency
Footprint
![Page 7: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/7.jpg)
Power Consumption!
7
![Page 8: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/8.jpg)
There are no standards
The only rules you must follow is your non-functional requirements!
8
![Page 9: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/9.jpg)
We Love Functional Programming!• But what is it?
•Just first class functions?•Referential transparency?•Immutability?•Category theory?
9
![Page 10: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/10.jpg)
Abstractions!• They help us reason about our logic• Decoupling• Simplicity• Correctness• Reuse
10
![Page 11: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/11.jpg)
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
![Page 12: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/12.jpg)
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
![Page 13: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/13.jpg)
Penalties• Increased allocations• More bytecode executed to perform tasks• Less control over runtime performance
13
![Page 14: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/14.jpg)
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 s-expressions
•Some people see beauty in c-style constructs
14
![Page 15: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/15.jpg)
Rap Genius
15
![Page 16: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/16.jpg)
What About The Environment?
16
![Page 17: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/17.jpg)
We Can’t Ignore the Cost!
17
![Page 18: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/18.jpg)
Languages Impose Constraints• “Choose-a-phone” languages versus those
with strictly defined language constructs
18
![Page 19: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/19.jpg)
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
![Page 20: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/20.jpg)
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
![Page 21: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/21.jpg)
How Many Libs Have Performance Tests?
• Very few• You give up control of your ability to optimize when you use libraries
21
![Page 22: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/22.jpg)
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
![Page 23: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/23.jpg)
HardwareFrom the bottom up, computers
understand queues and message passing
23
![Page 24: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/24.jpg)
Things to Avoid
• Parallel Collections• STM• Returns out of closures• Boxing• Lambdas! :)
24
![Page 25: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/25.jpg)
Digression: Don’t Use OSX• It’s lousy for doing performance analysis• The JVM has issues, particularly with visibility
25
![Page 26: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/26.jpg)
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
![Page 27: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/27.jpg)
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
![Page 28: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/28.jpg)
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
![Page 29: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/29.jpg)
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
![Page 30: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/30.jpg)
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
![Page 31: 20140228 fp and_performance](https://reader033.vdocuments.us/reader033/viewer/2022050816/54c642264a79596b248b459e/html5/thumbnails/31.jpg)
Thank You!
31