Debugging slow Liferay pages in production
Production slowness is rarely mysterious once you stop guessing and start measuring. The instinct to add a cache or bump JVM memory before knowing where the time goes is how teams spend a week fixing the wrong layer. A slow Liferay page is almost always slow in one specific place, and the job is to find that place with evidence.
Measure before you change anything
Start by capturing where the time is actually spent. A single slow request, traced end to end, tells you more than hours of speculation. Liferay and the surrounding stack expose enough signal to localize the problem quickly.
- Browser Network tab: is the time in the server response, or in downloading assets afterward?
- Server access logs: measure the response time of the HTML document alone, isolated from static resources.
- Database slow query log: enable it temporarily to catch queries crossing a threshold during the slow request.
- Thread dumps: take three a few seconds apart under load to see where threads are actually blocked.
The usual suspects
Across many production portals, slow pages cluster around a small number of causes. Checking them in rough order of frequency resolves most cases:
| Symptom | Likely cause | First check |
|---|---|---|
| One page slow, others fine | Expensive query or N+1 in that page's logic | DB slow query log |
| All pages slow | Cache misconfiguration or undersized heap | Cache hit rate, GC logs |
| Slow only under load | Thread pool or connection pool exhaustion | Thread dumps, pool metrics |
| Slow first hit, fast after | Cold cache or lazy initialization | Warm-up behavior |
Find the N+1 query
The most common single cause is a loop that issues one query per item. It is invisible with ten records and catastrophic with ten thousand. A quick way to confirm it is to log query counts per request and look for numbers that scale with the data on the page.
// Symptom: query count grows with the number of articles
for (JournalArticle article : articles) {
// each call hits the database again
User author = userLocalService.getUser(article.getUserId());
render(article, author);
}
// Fix: batch the lookup once, then resolve in memory
Set<Long> userIds = articles.stream()
.map(JournalArticle::getUserId).collect(toSet());
Map<Long, User> authors = userLocalService
.getUsers(userIds).stream()
.collect(toMap(User::getUserId, u -> u));Build a repeatable checklist
Once you have solved a few of these, the value is in writing down the sequence so the next incident is faster: trace one request, isolate the slow layer, confirm with the matching metric, then change exactly one thing and re-measure. Slow-page debugging becomes routine engineering rather than firefighting when the process is the same every time.