"OutOfMemoryError: Java Heap Space" Multiple Display Macros in a page slow down the server

Hi,

I’m using XWiki 13.0 Debian + MySQL.

My users have the requirement of the parent page being an amalgamation of all its nested pages. We approached this requirement by using the display macro multiple times in a single page.

Each parent page contains 16 nested pages. This means that the parent page will use the display macro 16 times. Upon implementation, we had no issues loading/viewing the parent pages.

Recently, our site went “live”, increasing the number of concurrent users to ~100. At the same time, we started experiencing OutOfMemoryError: Java Heap Space with a particular parent page, whose nested pages have approximately 300 images in total, whenever a user accesses the above mentioned parent page. This required a server reboot everytime to “fix” it and I have since disabled access to the offending parent page.

I also discovered that this issue is not limited to this page only. Another parent page, whose nested pages have slightly lesser media content than the offending page, causes a site wide slow down whenever accessed. This page would load its content, however, some components would not load properly; e.g. the navigation panels do not load, the “3 dot” menus become unresponsive.

This has led me to suspect that the display macro may have some performance limitations. Is this a known limitation? Are there any alternative solutions to my user requirements?

There’s no known limitations. The issue is probably simply the display of 300 large images on the same page.

How much memory did you give to the JVM? Please see https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Performances/#HMemory

Thx

Note: This is a lot (100 TPS is a lot!). You’ll need to size your servlet container properly and possibly even use XWiki clustering. Unless you mean 100 users but not at the same time which would be a lot lower than 100 TPS.

If you don’t have in-house skills, you may want to contact a company offering professional support for XWiki to help you out, see https://www.xwiki.org/xwiki/bin/view/Main/Support#HProfessionalSupport

BTW not using a LTS for production is a bit dangerous :wink: Unless it’s not critical.

Thanks for the response, I am definitely still a beginner at administrating XWiki, appreciate the help. I’ve set up glowroot to monitor the transactions previously and the throughput of all web transactions is 23.4 per minute, is this higher than 100 TPS?

I had allocated -Xmx2048m initially, but I still experience the OOM error. Increasing it to -Xmx3072m still does not resolve it.

edit: corrected -Xmx3056m to -Xmx3072m

This mean 100 transactions per second! So 23.4 per minute is definitely a lot lower (it’s not even 1 per second! that’s a very very low active site) :wink:

I would double check if you set this correctly to make sure it’s really used. You could run https://snippets.xwiki.org/xwiki/bin/view/Extension/JMX%20Access#HExample1%3AAccessingJVMinformation or https://snippets.xwiki.org/xwiki/bin/view/Extension/Available%20Memory

Or check it with glowroot if you have it installed for the xwiki instance.

This is what I got from the available memory script
image

Which is close to -Xmx3072m args in setenv.sh that I specified.

CATALINA_OPTS=“$JAVA_OPTS -server -Xmx3072m -Dfile.encoding=utf-8 -Djava.awt.headless=true -XX:+UseParallelGC -XX:MaxGCPauseMillis=100 -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true -javaagent:/home/clpladmin/glowroot/glowroot.jar”

Is it a possibility that the instantaneous TPS is higher than 100 at the time that the offending page was accessed? From the IP access logs, each image in a page translates to a GET request to the server. Does this mean that accessing that page would lead to at least ~300 GET requests at that moment?

That doesn’t look right. You said you’re using the display macro and this macro doesn’t do any HTTP call. Maybe you’re doing something different like wrapping the calls to display with an async macro? Maybe you could show us your content?

A small snippet from the access log

To be precise, there’s 245 images in total, and the logs actually have exactly 245 lines of GET requests to “download/…”.

The content is a table of contents at the beginning, followed by 16 display macros with an access rights script.

{{toc/}}

{{velocity}}
#if ($services.security.authorization.hasAccess(‘view’, ‘somespace.WebHome’))
= page title =
{{display reference=“.nestedpagespace.WebHome”/}}
#end
{{/velocity}}

Would the velocity macro cause the HTTP call?

So indeed for each image displayed there’s a call to a HTTP GET done by the browser to download and then display the image, so that’s actually perfectly normal (I forgot about the browser in my previous reply!).