Nav
You are viewing an older version of this section. Click here to see the latest version.

Profiling Mule

Profiling Mule can be useful in helping you identify memory leaks in your custom Mule ESB extensions. YourKit is a commonly used Java profiler for analyzing JVM performance. Hooking into YourKit can be achieved by [profiling using the profiler pack] or [profiling with the YourKit agent]. Both methods are described below.

There are multiple Java profiler options available. If you’re not using YourKit, visit your respective profiler’s documentation to understand how to hook into the Mule-Java process.

Profiling with the YourKit Agent

YourKit allows you to remotely attach to a Java process using the remote attach wizard. This method is especially useful when you have ssh access to the Mule Server you’d like to profile and would rather not alter the Mule code itself to begin profiling.

Attaching the Profiler Agent

  1. Download the profiler at https://www.yourkit.com/download on to the Mule server.

  2. Unpackage the profiler.

  3. Determine the pid of Mule by running jps.

    jps
  4. Capture the pid of the MuleContainerBootstrap.

    2838 MuleContainerBootstrap
    21311 Jps
  5. Within the YourKit package, open the bin directory.

    cd yjp-2015-build-15086/bin
  6. Run yph.sh including the -attach flag with the pid of MuleContainerBootstrap.

    ./yph.sh -attach 2838
  7. Verify the agent is attached

    Attaching to process 2838 using default options
    The profiler agent has attached. Waiting while it initializes...
    The agent is loaded and is listening on port 10001.
    You can connect to it from the profiler UI.
Steps above can vary in a Windows environment. Check the YourKit documentation if the steps above cannot be translated.

Connecting the YourKit UI

  1. Launch YourKit on your local machine.

  2. In Monitor Remote Applications, click Connect to remote application.

    monitor-remote-apps

  3. Setup your server username and password.

  4. Configure the SSH authentication.

    yourkit-auth

  5. Click OK.

  6. After scanning for available applications, the YourKit should now be hooked up to your Mule instance.

    yourkit-hooked-up

Profiling with the Profiler Pack

The Mule Profiler Pack uses YourKit 9.0 to provide CPU and memory profiling. To use a different version of YourKit, instead of using the Profiler Pack see the YourKit documentation for the appropriate version for instructions on how to profile a Java application. When doing this with standalone Mule, note that any JVM flags need to be prefaced with -M so that they affect the Mule process rather than the wrapper process.

Installing the Profiler Pack

The Profiler Pack is contained in the Mule Enterprise Edition download. If you are installing Mule Enterprise Edition using the graphical installer, simply select the Profiler check box when installing the product.

If you are installing Mule Community Edition, go to the downloads page, and under the latest stable community release, expand the Downloads section. You can then click the link to the .zip, .tar, or .gz version of the Profiler pack. After downloading, unpack it on top of the Mule installation.

Set the following environment variable:


          
       
1
LD_LIBRARY_PATH=$MULE_HOME/lib/native/profiler

Enabling the Profiler Agent

The Profiler agent exposes the YourKit Profiler to JMX to provide CPU and memory profiling. You configure the Profiler agent with the <management:yourkit-profiler/> element. For more information, see JMX Management.

Running the Profiler

To run the profiler, you run Mule with the -profile switch plus any extra YourKit startup options with multiple parameters separated by commas, e.g. -profile onlylocal,onexit=memory. This integration pack will automatically take care of configuration differences for Java 1.4.x and 5.x/6.x.

For example:


          
       
1
./mule -profile

Embedded Mule

If you are running Mule embedded in a webapp, the Profiler configuration is completely delegated to the owning container. Launch YourKit Profiler, Tools → Integrate with J2EE server…​ and follow the instructions. Typically, a server’s launch script is modified to support profiling, and you then use this modified start script instead of the original.