java.lang.OutOfMemoryError: Java heap space

Thanks again @vmassol.
Answering your questions in the order.

  1. I’ve tried with 4GB max JVM memory to import 1GB and 2GB files.
  2. Tried with 17Mb XAR file and the import is fine.

Got the JVM memory details.
Tomcat Instance 1: Trying import on this instance.

Current size of heap in bytes: 1073741824
Maximum size of heap in bytes. 1073741824
Amount of free memory within the heap in bytes: 674365448

Tomcat Instance 2:

Current size of heap in bytes: 4479516672
Maximum size of heap in bytes. 32178700288
Amount of free memory within the heap in bytes: 2765465000

Instance 1 memory config in systemd:

Environment='JAVA_OPTS='-Xmx4096m -Xms4096m'
Environment='CATALINA_OPTS=-Xms4096m -Xmx4096m -XX:MaxPermSize=4096m -server -XX:+UseParallelGC -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true'

Instance 2 memory config in systemd:

Environment='JAVA_OPTS='-Xmx4096m -Xms4096m'
Environment='CATALINA_OPTS=-Xms4096m -Xmx4096m -XX:MaxPermSize=4096m -server -XX:+UseParallelGC -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true'

So, Instance2 is taking max memory as ~4GB but Instance1 is taking max memory as ~1GB.
Hence, this is the root cause for the JVM OOM error.

Ok so you have your solution I think: increase the memory on instance 1 to be more than 1GB. Note that 1GB is really the minimal memory to make XWiki work, see https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Performances/#HMemory

PS: I don’t know how to setup the memory for Tomcat on your system. But if it works for instance2 with the same setup maybe you just don’t have enough memory on the machine. Maybe try to stop instance2 (you don’t need it for the import since you have the XAR already) and only start instance1. In any case, this is no longer an XWiki issue but a Tomcat one (or an OS one). I’m not an expert on these unfortunately.

Thank you.

Given 4GB memory for both the instances but still not working And instance1-XWiki groovy script says 1GB though allocated is 4GB. And Tired with 8 GB on instance-1 but still not fixed. Tried by stopping the instance-2 but still no improvement. Now, to test further - I can’t stop and remove Instance-2 completely since it is the production wiki now.
Will check on Tomcat side, Assuming that running both tomcat servers as systemd service caused this issue.