java performance - war stories

43
© 2011 Apptio, Inc. All Rights Reserved. 1 Java Performance - War Stories Paul McLachlan Apptio

Upload: starbuck

Post on 22-Mar-2016

72 views

Category:

Documents


0 download

DESCRIPTION

Java Performance - War Stories. Paul McLachlan Apptio. Performance Strategy. Performance tuning is a discipline Measure, Don’t (ever) guess Always attack #1 bottleneck first Is success possible?. Performance Strategy. Performance Strategies Call it less Make it more efficient - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 1

Java Performance -War Stories

Paul McLachlanApptio

Page 2: Java Performance - War Stories

© 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: Java Performance - War Stories

© 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: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 4

Page 5: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 5

“Perceived Performance”

Page 6: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 6

Example

Performance Tuning By Example

Page 7: Java Performance - War Stories

© 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: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 8

Add a cache

Page 9: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 9

Don’t synchronize on the DB

Page 10: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 10

Use ConcurrentHashMap

Page 11: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 11

Don’t thrash with simultaneous hits

Page 12: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 12

Don’t run out of RAM

Page 13: Java Performance - War Stories

© 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: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 14

Preload everything beforehand

Page 15: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 15

Use less RAM with .intern()

Page 16: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 16

How to make HashMap.get() faster?

Page 17: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 17

HotCache pattern

Page 18: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 18

Example

Memory Optimizations

Page 19: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 19

How Much Memory?

Page 20: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 20

How Much Memory?

Page 21: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 21

How Much Memory?org.apache.commons.collections.map.Flat3Map

Page 22: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 22

*How* Much Memory?

-XX:+UseCompressedOops

Page 23: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 23

Off Heap

Off Heap &Native Integration Tricks

Page 25: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 25

Off Heap / Mapped Wrapping Classes

Page 26: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 26

Example

Build In Instrumentation

Page 27: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 27

Visibility

Page 28: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 28

Memory Report

Page 29: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 29

Visibility

Page 30: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 30

Visibility

Page 31: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 31

/OutputThreads Servlet

Page 32: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 32

Example

Or … Tools

Page 33: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 33

Tools / YourKit

yourkit.com:

Sampling Instrumenting Heap & GC

$500 / unlimited

Page 34: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 34

How Profilers Work

Page 35: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 35

Or … Embed the Profiler

Page 36: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 36

Tools / NMon http://nmon.sourceforge.net

Page 37: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 37

Example

Reference Material

Page 38: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 38

Numbers Everyone Should Knowhttp://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf

Page 39: Java Performance - War Stories

© 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: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 40

Tools

jHiccuphttp://www.azulsystems.com/jHiccup

YourKithttp://yourkit.com/

Nmon for Linuxhttp://nmon.sourceforge.net

Page 42: Java Performance - War Stories

© 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: Java Performance - War Stories

© 2011 Apptio, Inc. All Rights Reserved. 43

JVM Intrinsicshttp://hg.openjdk.java.net/jdk6/jdk6/hotspot/file/6d13fcb3663f/ src/share/vm/classfile/vmSymbols.hpp