+ All Categories
Home > Documents > Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance...

Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance...

Date post: 23-Jun-2020
Category:
Upload: others
View: 21 times
Download: 0 times
Share this document with a friend
15
Using Java Reflection to Debug Performance Issues Using Java Reflection to Debug Performance Issues Dr Heinz M. Kabutz Last updated 2016-04-28 © 2016 Heinz Kabutz – All Rights Reserved 1
Transcript
Page 1: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Using Java Reflection to Debug Performance

IssuesDr Heinz M. Kabutz Last updated 2016-04-28

© 2016 Heinz Kabutz – All Rights Reserved

1

Page 2: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Short Introduction to Speaker

lHeinz Kabutz – Born in Cape Town, South Africa, now live on Crete

– PhD Computer Science from University of Cape Town • University famous for world’s first successful heart transplant

lCreated The Java Specialists’ Newsletter – Monthly advanced newsletter for Java professionals

– http://www.javaspecialists.eu

lOne of the first Java Champions – https://java-champions.dev.java.net/

2

Page 3: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Short Introduction to Speaker

lHeinz Kabutz – Born in Cape Town, South Africa, now live on Crete

– PhD Computer Science from University of Cape Town • University famous for world’s first successful heart transplant

lCreated The Java Specialists’ Newsletter – Monthly advanced newsletter for Java professionals

– http://www.javaspecialists.eu

lOne of the first Java Champions – https://java-champions.dev.java.net/

2

Page 4: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Why Crete?

l The usual reason - wife is Greek :-)

3

Page 5: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Why Crete?

l The usual reason - wife is Greek :-)

3

Page 6: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Reflection is like Opium

lA bit too strong for every day use – But can relieve serious pain

lPlease do not become a reflection addict!

4

Page 7: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Modifying/Reading Private/Final Fields

lWe can access private fields by making it accessible – Requires security manager support

lNote: value field is final and private!

5

import java.lang.reflect.*;public class PrivateFinalFieldTest { public static void main(String... args) throws NoSuchFieldException, IllegalAccessException { Field value = String.class.getDeclaredField("value"); value.setAccessible(true); value.set("hello!", "cheers".toCharArray()); System.out.println("hello!"); }}

Page 8: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Modifying/Reading Private/Final Fields

lWe can access private fields by making it accessible – Requires security manager support

lNote: value field is final and private!

5

cheers

import java.lang.reflect.*;public class PrivateFinalFieldTest { public static void main(String... args) throws NoSuchFieldException, IllegalAccessException { Field value = String.class.getDeclaredField("value"); value.setAccessible(true); value.set("hello!", "cheers".toCharArray()); System.out.println("hello!"); }}

Page 9: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Optimization methodology

1. Load test to identify bottlenecks – Identify the easiest to fix

2. Derive a hypothesis for the cause of the bottleneck – Create a test to isolate the factor identified by the hypothesis

• This is important, we have often been fooled by profilers!

3. Alter the application or configuration

4. Test that the change improves the situation – Also make sure the system still works correctly

l Repeat process until targets are met

6

Page 10: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Big Gains Quickly

lAmdahl’s law applies – Consider an 4 layered application

• Servlet takes 10% • Business component takes 11% • EJB takes 23% • SQL takes 56%

– Scenario 1, tuning Servlet gives 20x improvement • "Google" says that servlets are slow • 0.10/20 + 0.11/1 + 0.23/1 + 0.56 /1 = 0.905

– Scenario 2, tuning SQL give 2x improvement • We measure and discover SQL is the bottleneck • 0.10/1 + 0.11/1 + 0.23/1 + 0.56/2 = 0.72

7

Page 11: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Big Gains Quickly

lAmdahl’s law applies – Consider an 4 layered application

• Servlet takes 10% • Business component takes 11% • EJB takes 23% • SQL takes 56%

– Scenario 1, tuning Servlet gives 20x improvement • "Google" says that servlets are slow • 0.10/20 + 0.11/1 + 0.23/1 + 0.56 /1 = 0.905

– Scenario 2, tuning SQL give 2x improvement • We measure and discover SQL is the bottleneck • 0.10/1 + 0.11/1 + 0.23/1 + 0.56/2 = 0.72

7

Page 12: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Big Gains Quickly

lAmdahl’s law applies – Consider an 4 layered application

• Servlet takes 10% • Business component takes 11% • EJB takes 23% • SQL takes 56%

– Scenario 1, tuning Servlet gives 20x improvement • "Google" says that servlets are slow • 0.10/20 + 0.11/1 + 0.23/1 + 0.56 /1 = 0.905

– Scenario 2, tuning SQL give 2x improvement • We measure and discover SQL is the bottleneck • 0.10/1 + 0.11/1 + 0.23/1 + 0.56/2 = 0.72

7

Page 13: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Big Gains Quickly

lAmdahl’s law applies – Consider an 4 layered application

• Servlet takes 10% • Business component takes 11% • EJB takes 23% • SQL takes 56%

– Scenario 1, tuning Servlet gives 20x improvement • "Google" says that servlets are slow • 0.10/20 + 0.11/1 + 0.23/1 + 0.56 /1 = 0.905

– Scenario 2, tuning SQL give 2x improvement • We measure and discover SQL is the bottleneck • 0.10/1 + 0.11/1 + 0.23/1 + 0.56/2 = 0.72

7

Page 14: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

System Overview - The Box

8

People Usage Patterns, Rates

Application Lock Contention

JVM Garbage Collector, Number of Threads

Hardware CPU, Memory, Disk, Network

Page 15: Using Java Reflection to Debug Performance Issues...Using Java Reflection to Debug Performance Issues Short Introduction to Speaker lHeinz Kabutz – Born in Cape Town, South Africa,

Using Java Reflection to Debug Performance Issues

Using Java Reflection to Debug Performance

IssuesDr Heinz M. Kabutz

http://www.javaspecialists.euTwitter: @heinzkabutz

Email: [email protected]

© 2016 Heinz Kabutz – All Rights Reserved

9


Recommended