Exploring further

Let's profile another application that creates a lot of (500) threads; each thread creates ArrayList of 1,000,000 Double values, populating it with random numbers:

class AThread implements Runnable { 
    String name = "default"; 
    private Random numGenerator = new Random(); 
    private ArrayList<Double> list = new ArrayList<Double>(10_00_000); 
 
    AThread(String name) { 
        this.name = name; 
    } 
    public void run() { 
        for (int i = 0; i < 10_00_000; i++) { 
            list.add(numGenerator.nextDouble()); 
            System.out.println("Allocated : " + name + "[" + i + "]"); 
        } 
    } 
} 
public class TestFlightRecorder { 
    public static void main(String... args) throws Exception { 
        for (int i = 0; i < 500; i++) { 
            new Thread(new AThread("Thread" + i)).start(); 
        } 
    } 
} 

Let's execute the preceding TestFlightRecorder application, profiling it with JFR using Epsilon GC (to check whether we also get any data on the memory allocation) for 10 seconds:

    > java 
      -XX:+UnlockExperimentalVMOptions 
      -XX:+UseEpsilonGC 
      -XX:StartFlightRecording,filename=Epsilon.jfr 
         TestFlightRecorder

Here's the landing page when you open Epsilon.jfr in MC:

Before we discuss the results shown by MC in detail, let's quickly revisit the TestFlightRecorder application that was profiled. TestFlightRecorder creates 500 instances of the AThread class. The AThread class implements Runnable. On starting, each AThread instance creates ArrayList of 1,000,000 Double values, populates them with random values and outputs them to the console.

Let's visit the preceding screenshot now—MC displays a consolidated report on how your application fares overall. It includes the environment of the machine that is executing your Java application, the JVM internals, and blocking of threads on locks in your application. Here's a quick listing of these categories:

  • Java Application
  • Context Switches (indent)
  • Java Blocking (indent)
  • JVM Internals
  • Environment

Since MC reports that this application is performing poorly on the Context Switches and thread blocking categories, let's browse through the options under the Java Application category on the left-side panel menu in MC and figure out which option will include the relevant information. As you will notice, the Lock Instances option displays an exclamation mark right next to it. The following screenshot indicates what you will see when you click on it:

The preceding screenshot shows that all 500 threads that you created in the TestFlightRecorder application were blocking on PrintStream and Object. It even displays the total blocked time, that is, 2 hours and 40 minutes (calculated collectively for all blocked threads—for 20 seconds of application profiling).

Since the JFR profiler records the profiled data in a binary format to a file, you can view this data with MC at a later time and figure out a whole lot of other issues. For instance, if you click on Processes, you'll know that your CPU is being used by a lot of other processes that are being executed on your host machine, which can also include auto software updates. Make sure you switch all of these off. Let's say you are tuning the performance of your application on the server.

Here's what you see if you click on Processes in MC (of course, the results will vary across systems):

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.151.107