Is your profiler speaking the same language as you? -- Docklands JUG
-
Upload
simon-maple -
Category
Technology
-
view
468 -
download
1
Transcript of Is your profiler speaking the same language as you? -- Docklands JUG
![Page 1: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/1.jpg)
Is your profiler speaking the same language as you?
Simon Maple @sjmaple
![Page 2: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/2.jpg)
@sjmapleSimon Maple -
![Page 3: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/3.jpg)
Agenda
• Performance Tools • Performance by numbers • Sampling vs Tracing • XRebel • JRebel
3
![Page 4: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/4.jpg)
![Page 5: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/5.jpg)
Performance Tools
• Java Monitoring Tools
• Java Profilers
• Java Testing Tools
5
![Page 6: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/6.jpg)
Performance report
6
![Page 7: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/7.jpg)
RebelLabs reports
7
![Page 8: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/8.jpg)
8
![Page 9: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/9.jpg)
9
![Page 10: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/10.jpg)
10
![Page 11: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/11.jpg)
11
![Page 12: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/12.jpg)
12
![Page 13: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/13.jpg)
13
![Page 14: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/14.jpg)
14
![Page 15: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/15.jpg)
15
![Page 16: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/16.jpg)
The Journey of Performance
16
![Page 17: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/17.jpg)
https://twitter.com/shipilev/status/578193813946134529
![Page 18: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/18.jpg)
A
BC
D E
Performance
Code complexity
![Page 19: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/19.jpg)
Improving
OptimizingLast 5% Last 1%
A
BC
D E
![Page 20: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/20.jpg)
Profiling
CPU
Tracing Sampling
Memory
Usage Allocation
We are only talking about this part today
![Page 21: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/21.jpg)
JVM has ability to produce thread dump:Press Ctrl+Break on Windows
kill -3 PID on *nix
"http-nio-8080-exec-1" #40 daemon prio=5 os_prio=31 tid=0x00007fd7057ed800 nid=0x7313 runnable java.lang.Thread.State: RUNNABLE at o.s.s.p.w.OwnerController.processFindForm(OwnerController.java:89) at s.r.NativeMethodAccessorImpl.invoke0(Native Method) at s.r.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at s.r.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at j.l.r.Method.invoke(Method.java:497)
What is a sample?
![Page 22: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/22.jpg)
Sampling interval : 20 ms
Sample count: 4
![Page 23: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/23.jpg)
Sampling interval : 1 ms
Sample count: 100+
![Page 24: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/24.jpg)
Sampling
main()foo()bar()baz()
never captured :(
![Page 25: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/25.jpg)
Safepoint bias
Safepoints
main()foo()bar()baz()
![Page 26: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/26.jpg)
Safepoint bias
Safepoints
main()foo()bar()baz()
![Page 27: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/27.jpg)
Taming safepoint bias
Java Mission ControlProprietary protocolJava 7u40
Honest Profiler
https://github.com/RichardWarburton/honest-profiler
AsyncGetCallTraceJVMTI
NB! not documented
![Page 28: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/28.jpg)
public void businessMethod() { long start = System.currentTimeMillis(); work(); Profiler.log(System.currentTimeMillis()-‐start); }
Tracing (Instrumentation)
![Page 29: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/29.jpg)
Tracing
public void businessMethod() { long start = System.nanoTime(); work(); Profiler.log(System.nanoTime()-‐start);}
![Page 30: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/30.jpg)
Tracing
public void businessMethod() { Profiler.start(“businessMethod"); try { work(); } finally { Profiler.log("businessMethod"); }}
![Page 31: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/31.jpg)
System.nanoTimeSystem.currentTimeMillisParallel thread updating easily accessible memory location
sleep-wakeup-update
yield-wakeup-update
busy-loop-update
![Page 32: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/32.jpg)
class Profiler { Loop loop; public static void start(String method) { long now = loop.getTime(); … }
![Page 33: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/33.jpg)
public class Loop implements Runnable { private volatile long time; public void run() { while (running) { time = System.nanoTime(); sleep(); } }
public final long getTime() { return time; }
Busy Loop
![Page 34: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/34.jpg)
Nano seconds put into perspective
Reading memory is not free. It takes cycles = nanoseconds
Each (software) layer is not free. JVM, JNI, OS, HW
http://shipilev.net/blog/2014/nanotrusting-nanotime/
Nanotrusting the NanoTime
![Page 35: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/35.jpg)
Nano seconds put into perspective
http://shipilev.net/blog/2014/nanotrusting-nanotime/
Nanotrusting the NanoTime
granularity_nanotime: 26.300 +- 0.205 ns latency_nanotime: 25.542 +- 0.024 ns
granularity_nanotime: 29.322 +- 1.293 ns latency_nanotime: 29.910 +- 1.626 ns
granularity_nanotime: 371,419 +- 1,541 ns latency_nanotime: 14,415 +- 0,389 ns
Linux
Solaris
Windows
![Page 36: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/36.jpg)
Sleep timer: time-slicing & schedulingMinimum sleep times:
Win8: 1.7 ms (1.0 ms using JNI + socket poll)Linux: 0.1 msOS X: 0.05 msVirtualBox + Linux: don’t ask :)Still uses 25-50% of CPU core
Yield?Windows scheduler skips yielded threads in case of CPU starvation
![Page 37: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/37.jpg)
public class Loop implements Runnable { private volatile long time; public void run() { while (running) { time = System.nanoTime(); sleep(); } } private void sleep() { if (!MiscUtil.isWindows()) { Thread.yield(); } }
Busy Loop
![Page 38: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/38.jpg)
public class Loop implements Runnable { private volatile long time; public void run() { while (running) { time = System.nanoTime(); sleep(); } } private void sleep() { if (!MiscUtil.isWindows()) { Thread.yield(); } }
Busy Loop
![Page 39: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/39.jpg)
Busy Looppublic class Loop implements Runnable { private volatile long time; public void run() { while (running) { time = System.nanoTime(); sleep(); } } private void sleep() { if (!MiscUtil.isWindows()) { Thread.yield(); } }
![Page 40: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/40.jpg)
public class Loop implements Runnable { private volatile long time; public void run() { while (running) { time = System.nanoTime(); sleep(); } } private void sleep() { if (!MiscUtil.isWindows()) { Thread.yield(); } }
Busy Loop
![Page 41: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/41.jpg)
main()foo()bar()baz()
Tracing
relatively higher overhead for fast methods :(
![Page 42: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/42.jpg)
Database accessWeb ServicesRMI
Various application layers3rd-party components
HTTP sessionExceptions
CachesFile system access
View renderingSerializationGC
What other performance considerations should we have?
![Page 43: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/43.jpg)
Questions you should be asking……..……..……..……..
![Page 44: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/44.jpg)
Questions you should be askingWhere was most of the time spent?How many SQL queries were executed?How much time did the external calls take?
What’s my HTTP session state?Is caching working properly?
Is there any excessive work done by the app?
![Page 45: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/45.jpg)
Most improvement gained here!This is where we should focus first!
A
BC
D E
![Page 46: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/46.jpg)
![Page 47: Is your profiler speaking the same language as you? -- Docklands JUG](https://reader031.fdocuments.in/reader031/viewer/2022030218/58868b3f1a28abf6158b53cb/html5/thumbnails/47.jpg)
Download trials and get FREE shirts :)
JRebel: http://0t.ee/docklandsjr
XRebel: http://0t.ee/docklandsxr
47