© 2011 apptio, inc. all rights reserved. 1 java performance - war stories paul mclachlan apptio
TRANSCRIPT
![Page 1: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/1.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 1
Java Performance -War Stories
Paul McLachlanApptio
![Page 2: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/2.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 2
Performance Strategy
Performance tuning is a discipline
– Measure, Don’t (ever) guess– Always attack #1 bottleneck first– Is success possible?
![Page 3: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/3.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 3
Performance Strategies
– Call it less– Make it more efficient– Do it in parallel
– Do it beforehand
or…
Performance Strategy
![Page 4: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/4.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 4
![Page 5: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/5.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 5
“Perceived Performance”
![Page 6: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/6.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 6
Example
Performance Tuning By Example
![Page 7: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/7.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 7
A random bottleneck
This is an example – please ignore the SQL stupidity
(Actually – all of these snippets are for explanation purposes, YAMMV)
![Page 8: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/8.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 8
Add a cache
![Page 9: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/9.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 9
Don’t synchronize on the DB
![Page 10: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/10.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 10
Use ConcurrentHashMap
![Page 11: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/11.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 11
Don’t thrash with simultaneous hits
![Page 12: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/12.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 12
Don’t run out of RAM
![Page 13: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/13.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 13
Soft References
Weak/Soft/Phantom/Final References
http://jeremymanson.blogspot.com/2009/07/how-hotspot-decides-to-clear_07.html
-XX:SoftRefLRUPolicyMSPerMB=1
![Page 14: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/14.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 14
Preload everything beforehand
![Page 15: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/15.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 15
Use less RAM with .intern()
![Page 16: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/16.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 16
How to make HashMap.get() faster?
![Page 17: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/17.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 17
HotCache pattern
![Page 18: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/18.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 18
Example
Memory Optimizations
![Page 19: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/19.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 19
How Much Memory?
![Page 20: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/20.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 20
How Much Memory?
![Page 21: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/21.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 21
How Much Memory?
org.apache.commons.collections.map.Flat3Map
![Page 22: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/22.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 22
*How* Much Memory?
-XX:+UseCompressedOops
![Page 23: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/23.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 23
Off Heap
Off Heap &Native Integration Tricks
![Page 24: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/24.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 24
“Unsafe”
http://javasourcecode.org/html/open-source/jdk/jdk-6u23/sun/misc/Unsafe.java.html
![Page 25: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/25.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 25
Off Heap / Mapped Wrapping Classes
![Page 26: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/26.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 26
Example
Build In Instrumentation
![Page 27: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/27.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 27
Visibility
![Page 28: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/28.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 28
Memory Report
![Page 29: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/29.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 29
Visibility
![Page 30: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/30.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 30
Visibility
![Page 31: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/31.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 31
/OutputThreads Servlet
![Page 32: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/32.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 32
Example
Or … Tools
![Page 33: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/33.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 33
Tools / YourKit
yourkit.com:
Sampling Instrumenting Heap & GC
$500 / unlimited
![Page 34: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/34.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 34
How Profilers Work
![Page 35: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/35.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 35
Or … Embed the Profiler
![Page 36: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/36.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 36
Tools / NMon
http://nmon.sourceforge.net
![Page 37: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/37.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 37
Example
Reference Material
![Page 38: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/38.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 38
Numbers Everyone Should Know
http://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf
![Page 39: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/39.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 39
Statistics
Relative Standard Deviation = STDEV(…)/AVERAGE(…)
Confidence = 1-TTEST(orig,control,1,2)
Throughput Average latency Max latency 90th Percentile latency
![Page 40: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/40.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 40
Tools
jHiccuphttp://www.azulsystems.com/jHiccup
YourKithttp://yourkit.com/
Nmon for Linuxhttp://nmon.sourceforge.net
![Page 41: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/41.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 41
Libraries
CLHM http://code.google.com/p/concurrentlinkedhashmap/
Guavahttp://code.google.com/p/guava-libraries/
Colthttp://acs.lbl.gov/software/colt/
Trove4Jhttp://trove.starlight-systems.com/
JDK 8 Concurrency Codehttp://gee.cs.oswego.edu/dl/concurrency-interest/index.html
![Page 42: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/42.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 42
Good Books / References
Java Memory Modelhttp://www.cs.umd.edu/~pugh/java/memoryModel/
Java Platform Performancehttp://java.sun.com/docs/books/performance/
Debugging by Thinkinghttp://www.debuggingbythinking.com/
Concurrent Programming in Javahttp://www.amazon.com/Concurrent-Programming-Java-Principles-Pattern/dp/0201310090/
![Page 43: © 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio](https://reader035.vdocument.in/reader035/viewer/2022062511/5518a324550346881f8b4974/html5/thumbnails/43.jpg)
© 2011 Apptio, Inc. All Rights Reserved. 43
JVM Intrinsics
http://hg.openjdk.java.net/jdk6/jdk6/hotspot/file/6d13fcb3663f/ src/share/vm/classfile/vmSymbols.hpp