« Back

How Do I Profile Liferay for Better Performance?

Company Blogs June 5, 2008 By James Min Staff

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:



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.



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.



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)
export LD_LIBRARY_PATH="$_YH_/bin/linux-x86-32:$LD_LIBRARY_PATH"
JAVA_TOOL_OPTIONS="-agentlib:yjpagent=sessionname=Tomcat $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.



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.




Threaded Replies Author Date
Great article James! We're really going to... Rob Sonke June 6, 2008 12:45 AM
Rob, I edited to make the images a little... James Min June 6, 2008 6:08 AM
Great article! Do you know of any... Not Me June 11, 2008 12:39 PM
I don't know of any that are free that I've... James Min June 12, 2008 9:33 AM
Thanks James! Never mind... It's worth asking =) Not Me June 13, 2008 4:52 AM
I have used the Netbeans profiler before with... Alex Brdar September 15, 2008 12:14 PM
Hi, Any guides for windows? I have two tomcats... Achmed Tyrannus Albab May 24, 2011 2:20 AM
It should work the same way for Windows. If you... James Min May 24, 2011 8:29 AM
Got it working. Thanks mate. Achmed Tyrannus Albab June 15, 2011 3:30 AM

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.
Posted on 6/6/08 12:45 AM.
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.
Posted on 6/6/08 6:08 AM in reply to Rob Sonke.
Great article!

Do you know of any implementation of YourKit but open source and free?

Posted on 6/11/08 12:39 PM in reply to James Min.
I don't know of any that are free that I've used personally, but there are other Java profilers out there.
Posted on 6/12/08 9:33 AM in reply to Mariano Cifre.
Thanks James!

Never mind... It's worth asking =)
Posted on 6/13/08 4:52 AM in reply to James Min.
I have used the Netbeans profiler before with Tomcat, it has some good profiling options and is free!
Posted on 9/15/08 12:14 PM.
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?

Posted on 5/24/11 2:20 AM.
It should work the same way for Windows. If you are having problem with Yourkit, I suggest looking in their online help: http://yourkit.com/docs/95/help/index.jsp
Posted on 5/24/11 8:29 AM in reply to Achmed Tyrannus Albab.
Got it working. Thanks mate.
Posted on 6/15/11 3:30 AM in reply to James Min.