How Do I Profile Liferay for Better Performance?

Want to tune Liferay for better performance? There are several things that you can do. There is no magic wand that turbo charges your web app. There is this wiki article which has some properties you can set:

http://wiki.liferay.com/index.php/Performance

 

But in the end, Liferay is a Java web application that runs in the JVM. Hence, you have to do some JVM tuning. Java profiling can be very useful in pinpointing potential problem areas and bottlenecks. We don't necessarily endorse a particular Java profiler, but I'll just give an example using YourKit. Java profiling and tuning is largely an iterative process. You profile, analyze, tune... rinse, repeat. Everyone's app is different. But in the end you want to make CPU and memory usage more efficient, resulting in faster response and performance.

 

Requirements:

1) A working Liferay installation on Tomcat
2) YourKit for the platform your app is running, on as well as the platform you want to run the profiler from.

 

Basic Concept:

1) You have to run Tomcat with profiling enabled.
2) You then run the profiler client and attach it to that web app. It will find it because it was started with profiling enabled.

 

Steps:

1) Set up Tomcat to be profiled

There are excellent steps here, but here it is for your benefit:

Run the wizard:

java -jar lib/yjp.jar -integrate

 

That should create a script: tomcat/bin/startup_with_yjp.sh

What is the difference you ask? Well, it is simply the startup.sh file with some extra libraries, enabling it to be profiled. You run this script when you profile, not in production. Here's a diff:

 

 

It basically added:

# Generated with YourKit Java Profiler 7.5.0
# Path to proper version of profiler agent library (Linux, 32-bit JVM)
_YH_="/opt/yjp-7.5.0"
export LD_LIBRARY_PATH="$_YH_/bin/linux-x86-32:$LD_LIBRARY_PATH"
JAVA_TOOL_OPTIONS="-agentlib:yjpagent=sessionname=Tomcat $JAVA_TOOL_OPTIONS"
export JAVA_TOOL_OPTIONS
.
.
.
JAVA_OPTS="-Xrunyjpagent:sessionname=Tomcat $JAVA_OPTS"
export JAVA_OPTS

 

2) Let's start Tomcat with the new script.

It should output something like this in the log:

Picked up JAVA_TOOL_OPTIONS: -agentlib:yjpagent=sessionname=Tomcat 
[YourKit Java Profiler 7.5.0] Using JVMTI (10.0-b22;Sun Microsystems Inc.; mixed mode, sharing;
Linux;32 bit JVM)
[YourKit Java Profiler 7.5.0] Profiler agent is listening on port 10001...
[YourKit Java Profiler 7.5.0] *** HINT ***: To get profiling results, connect to the application
from the profiler UI
Jun 5, 2008 7:17:30 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent

3) Start up the YourKit profiler.

/opt/yjp-7.5.0/yjp.sh

 

Click "Connect to locally running profiled application..." and it will find the Tomcat you just started! From there, it will create new tab with a profile of your app.

 

Take snapshots

You can see what your web app is doing live. Click "Start CPU Profiling" but uncheck "Profile J2EE" so you can focus on just Liferay.

 

To analyze deeper, you need to take a performance snapshot and memory snapshot.

 

To get a really useful snapshot, you will need to run some sort of load generator, such as JMeter. Then take the snapshots. From there you can identify "hot spots" and make tweaks from there. Again, this is an iterative process, until you get what you want.


JVM Tuning?
I can't really recommend specific JVM tuning settings, because, as I stated before, every app is different. You need to identify problem areas and address those as they come along. Needless to say, there is some JVM expertise required here. You can also hire Liferay's consulting services for a custom solution that fits your system's performance requirements. 

Anyhow, that should get you started. There is a lot of helpful info here on diagnosis: http://yourkit.com/docs/75/help/

Read up on how to troubleshoot performance problems and how to use and interpet the data in YourKit.

 

GOOD LUCK!

 

Blogs
Great article James!

We're really going to profile too. Just one question, would it be possible that you upload the images with a higher quality. These are hardly readable. Thanks in advance.
Rob, I edited to make the images a little better. The screenshots of YourKit I couldn't display full-size in this post or else it would make the page look too strange, but you can right click and "view image" if you want to see them full-size.
I have used the Netbeans profiler before with Tomcat, it has some good profiling options and is free!
Hi,
Any guides for windows?
I have two tomcats on my server/pc.
Problem is, its not detecting my Liferay tomcat , but only the other (via wizard).
Any chance?

Regards,
Achmed.