Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Is Your Profiler Speaking the Same Language as ...

Is Your Profiler Speaking the Same Language as You?

This session was given at JavaOne 2015

Profilers are absolute beasts. They might prove useful for pinpointing the performance issues in your Java applications, and with profilers, developers have the good fortune to be able to find the root cause of an issue at hand. However, it requires effort to actually comprehend the data collected by a profiler. Due to the inherent complexity of the data, you have to understand how it is collected—and thus understand how the profiler actually works. This presentation goes through the classic profiler features and answers questions such as What is a hotspot? What is the difference between sampling and instrumentation from the profiler’s point of view? What are the problems with either of those methods? What is the time budget of the application? And more.

Simon Maple

November 03, 2015
Tweet

More Decks by Simon Maple

Other Decks in Programming

Transcript

  1. SIMON MAPLE @SJMAPLE VIRTUAL JUG FOUNDER LONDON JUG CO-ORGANISER JAVA

    CHAMPION JAVAONE ROCKSTAR SPEAKER REBELLABS AUTHOR ABOUT ME
  2. THREAD DUMP: 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?
  3. 19

  4. 20

  5. TAMING SAFEPOINT BIAS Java Mission Control Proprietary protocol Java 7u40

    Honest Profiler JVMTI AsyncGetCallTrace https://github.com/RichardWarburton/honest-profiler
  6. public  void  businessMethod()  {
    long  start  =  System.currentTimeMillis();  

    
    work();   
    Profiler.log(System.currentTimeMillis()-­‐start);   } TRACING
  7. public  void  businessMethod()  {
    long  start  =  System.nanoTime();  

    
    work();   
    Profiler.log(System.nanoTime()-­‐start);
 } TRACING
  8. public  void  businessMethod()  {
    Profiler.start(“businessMethod”);      try  {

             work();      }  finally  {
        Profiler.log("businessMethod");
    }
 } TRACING
  9. class  Profiler  {   
    Loop  loop;
 
  

     public  static  void  start(String  method)  {
        long  now  =  loop.getTime();          …
    }  
  10. public  class  Loop  implements  Runnable  {
        private

     volatile  long  time;
        public  void  run()  {
                while  (running)  {
                        time  =  System.nanoTime();
                        sleep();
                }
        }          public  final  long  getTime()  {
                return  time;
        }  
  11. NANO SECONDS 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
  12. NANO SECONDS PUT INTO PERSPECTIVE 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 http://shipilev.net/blog/2014/nanotrusting-nanotime/ Nanotrusting the NanoTime
  13. SLEEP TIMER: TIME-SLICING & SCHEDULING MINIMUM SLEEP TIMES: Win8: 1.7

    ms (1.0 ms using JNI + socket poll) Linux: 0.1 ms OS X: 0.05 ms VirtualBox + Linux: don’t ask :) Still uses 25-50% of CPU core YIELD? Windows scheduler skips yielded threads in case of CPU starvation
  14. 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();
            }
        }
  15. 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();
            }
        }
  16. 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();
            }
        }
  17. 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();
            }
        }
  18. 57 1. Functionality - MAKE IT WORK 2. Quality 3.

    Performance 4. Security THE SOFTWARE MANTRA
  19. 58 1. Functionality - MAKE IT WORK 2. Quality -

    MAKE IT WORK WELL 3. Performance 4. Security THE SOFTWARE MANTRA
  20. 59 1. Functionality - MAKE IT WORK 2. Quality -

    MAKE IT WORK WELL 3. Performance - MAKE IT WORK FAST 4. Security THE SOFTWARE MANTRA
  21. 60 1. Functionality - MAKE IT WORK 2. Quality -

    MAKE IT WORK WELL 3. Performance - MAKE IT WORK FAST 4. Security - ? ? ? ? ? ? ? ? THE SOFTWARE MANTRA
  22. 61 1. Functionality - MAKE IT WORK 2. Quality -

    MAKE IT WORK WELL 3. Performance - MAKE IT WORK FAST 4. Security - MAKE IT WORK SECURELY THE SOFTWARE MANTRA
  23. 62 1. Functionality - MAKE IT WORK 2. Quality -

    MAKE IT WORK WELL 3. Performance - MAKE IT WORK FAST 4. Security - MAKE IT WORK SECURELY THE SOFTWARE MANTRA
  24. 65 Reactive - Wait until an issue occurs, then resolve

    it as quickly as possible. Proactive - prevent POTENTIAL issues from EVER occurring. REACTIVE OR PROACTIVE?