How to tune JasperReports Server Java Xmx, Metaspace and Class space

0

How do I tune JRS so it doesn't OOM or otherwise have a service interruption?

phil_27's picture
Joined: Feb 18 2021 - 4:24pm
Last seen: 1 week 3 days ago

1 Answer:

0

Wow, that's a really good question, Phil, allow me to try and answer it for you. There's a lot to it, so lets start with the larger parts and summarise at the end. I have not been able to find anything on tuning JRS, and have had no appropriate assistance from Tibco support on how to configure their product.

DISCLAIMER: This information and pointers are just a guide, do not ever blindly just copy paste things from the internet without understanding what the change is doing. Read, change, test, rinse, repeat.

 

  1. The OS itself plus supporting applications
  2. Metaspace & Class space
  3. Xmx
  4. Garbage Collection
  5. Summary

1. OS Overhead

I only know of the land of Linux, so sorry Windows users, you're on your own here. On the server you are trying to configure JRS, ensure it is fully provisioned and set up, but ensure JRS is not running.

From the output of `ps auxf`, the column you are interested in is RSS, this is the Resident Set Size (memory in use) in KiB of each process. Find a way to total this up and add a couple of MiB for rounding, this is your OS_OVERHEAD.

Start JRS and ensure you can log in to it before continuing.

 

2. Metaspace & Class space

These two are the most complex, because "it depends". Read both of these and ensure you understand them before continuing

https://stuefe.de/posts/metaspace/sizing-metaspace/
https://stuefe.de/posts/metaspace/analyze-metaspace-with-jcmd/

`jcmd` is available on CentOS in the devel package for the version of Java you're using; ala `java-11-openjdk-devel`

In my case, the Total Usage of Both was around 170M, so I added some overhead and rounded up to 200M, this is what I set my CompressedClassSpaceSize to and, per Herr Stüffe's recommendation, set MaxMetaspaceSize to 2x that number.

 

3. Xmx

Again, it's not that simple, and it depends. Xmx is the last thing to tune and simply puts a limit on the heap, BUT, Java will allocate memory outside of the heap for other things which will cause your Java process to OOM and you'll have a bad and frustrating day wondering why the application you tuned to use 4G of RAM is actually using way more than that. In part it's because Xmx is defined (yes, counter intuitive, but read the stackoverflow below). Kudos to Matt for providing a handy tool and lots of info for tuning.

https://stackoverflow.com/a/46103476/5327286

https://medium.com/@matt_rasband/dockerizing-a-spring-boot-application-6ec9b9b41faf

 

4. Garbage collection

To find out which is the compiled default, use:

java -XX:+PrintFlagsFinal -version | grep 'GC .*='

You want to use `UseG1GC`, especially in Java 11, for $reasons.

5. Summary

Total Memory = $(cat /proc/meminfo | grep ^MemTotal | awk '{print $2}') (this is KiB)

Xmx = MEMORY_TOTAL - OS_OVERHEAD - METASPACE - CLASS_SPACE

BTW, don't mix kb with mb

Which leaves us with:

-Djs.license.directory=/dev/rick/astley -XX:+UseG1GC -XX:+CMSClassUnloadingEnabled -Xss2m -Xms512m -Xmx${XMX}m -XX:MaxMetaspaceSize=400m -XX:CompressedClassSpaceSize=200m -Dorg.apache.catalina.security.SecurityListener.UMASK=0027

Notes:

  • SecurityListener UMASK was set to make the application more secure per the log feedback from org.apache.catalina.security
  • I am actually programmatically setting Xms to 512 to ensure a minimum amount of memory for JRS to run. If the calculator I made returns a number below 512, then I set Xmx to that and hope for the best. This is only a consideration in my development environments which don't have the same resources of production.
  • My entire deployment process is scripted and we run several environments for development and testing, I encourage you all to do similarly.

If this is incorrect, please use science and provide a constructive answer/reply. I will update this post as my understanding of this all develops and as we continue testing.

phil_27's picture
Joined: Feb 18 2021 - 4:24pm
Last seen: 1 week 3 days ago
Feedback