Project

Profile

Help

Support #2585

closed

java.lang.OutOfMemoryError: PermGen space with saxon

Added by Arjun Kadayaprath almost 9 years ago. Updated almost 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2016-01-14
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Hi,

Arjun here from Actiance. We recently bought SaxonEE9-7-0-1J.

We are using saxon to convert xslt 3.0 with streaming to different formats such as html, xml, csv, txt etc. But facing some issues during the transformation. There is a 'java.lang.OutOfMemoryError: PermGen space' and it stops. When googled, we found another similar thread in the saxon forum. Please find the link below.

https://saxonica.plan.io/issues/1833

We are using a 64 bit 1.7 JVM and have configured Xmx as 4096m. And when we have around 3.5 GB left in the heap, it throws an OutOfMemoryError: PermGen and stops. The permGen configured is 128m. We tried changing it to 256m and 512m respectively. But as a result, it runs for some more time and stops with OOM Error after some time. We also tried using -XX:+UseConcMarkSweepGC, -XX:+CMSPermGenSweepingEnabled and -XX:+CMSClassUnloadingEnabled JVM Args. But no luck.

We are using the saxon transformer in a multi threaded environment with a thread pool size 5. Maximum concurrent transformations as of now is 5.

Attaching the profile dump screen shot in case it helps. But it shows just the heap usage.

Please let us know what we can do in this case.

Thanks,

-Arjun.


Files

saxonProfileFileSnapShot.png (35.8 KB) saxonProfileFileSnapShot.png Heap Memory utilization during OOM. Snap shot from profile dump. Arjun Kadayaprath, 2016-01-14 15:26
Actions #1

Updated by Michael Kay almost 9 years ago

My guess would be that it is the same issue, namely memory occupied by generated bytecode. How large is the stylesheet?

If it is the size of the bytecode that's causing the problem, then you may be able to solve the problem by increasing PermGen space, (note that -Xmx makes no difference to this), but the simplest fix is probably to disable bytecode generation for the stylesheet in question. It's unlikely the impact on execution time will be more than 25% or so.

I assume you are compiling the stylesheet once as an XsltExecutable (or JAXP Templates), and then using it repeatedly by creating a new Transformer for each transformation?

Actions #2

Updated by Arjun Kadayaprath almost 9 years ago

Michael Kay wrote:

My guess would be that it is the same issue, namely memory occupied by generated bytecode. How large is the stylesheet?

If it is the size of the bytecode that's causing the problem, then you may be able to solve the problem by increasing PermGen space, (note that -Xmx makes no difference to this), but the simplest fix is probably to disable bytecode generation for the stylesheet in question. It's unlikely the impact on execution time will be more than 25% or so.

I assume you are compiling the stylesheet once as an XsltExecutable (or JAXP Templates), and then using it repeatedly by creating a new Transformer for each transformation?

Thanks for the prompt reply. Yes, we do have to test the same with huge xmls. But right now the use case is with a permGen size configured as 128m, we are converting xmls to html almost 1200 times and it throws 'java.lang.OutOfMemoryError: PermGen space' and stops. If we increase it to 256m/512m it is able to do something like for eg 3K/6K transformations and stops. And the permGen is not getting cleaned up. In the thread mentioned (https://saxonica.plan.io/issues/1833) , I could see the workaround as assigning the transformer to null. Will this work in our case? Or is there any permanent solution added to this issue on the saxon library itself?

Thanks,

-Arjun.

Actions #3

Updated by Arjun Kadayaprath almost 9 years ago

Michael Kay wrote:

My guess would be that it is the same issue, namely memory occupied by generated bytecode. How large is the stylesheet?

If it is the size of the bytecode that's causing the problem, then you may be able to solve the problem by increasing PermGen space, (note that -Xmx makes no difference to this), but the simplest fix is probably to disable bytecode generation for the stylesheet in question. It's unlikely the impact on execution time will be more than 25% or so.

I assume you are compiling the stylesheet once as an XsltExecutable (or JAXP Templates), and then using it repeatedly by creating a new Transformer for each transformation?

Thanks for the prompt reply. Yes, we do have to test the same with huge xmls. But right now the use case is with a permGen size configured as 128m, we are converting xmls to html almost 1200 times and it throws 'java.lang.OutOfMemoryError: PermGen space' and stops. If we increase it to 256m/512m it is able to do something like for eg 3K/6K transformations and stops. And the permGen is not getting cleaned up. In the thread mentioned (https://saxonica.plan.io/issues/1833) , I could see the workaround as assigning the transformer to null. Will this work in our case? Or is there any permanent solution added to this issue on the saxon library itself?

Also we are not using the XsltExecutables. Our sample code is something like,

import com.saxonica.config.EnterpriseTransformerFactory;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.stream.StreamResult;

import javax.xml.transform.stream.StreamSource;

// Initialized once

TransformerFactory factory = new EnterpriseTransformerFactory();

// Called every time as one per transformation.

Transformer transformer = factory.newTransformer(new StreamSource(xsltFile));

transformer.transform(src, new StreamResult(fileOutputStream));

Let me know in case you need more details regarding this.

Thanks,

-Arjun.

Actions #4

Updated by Michael Kay almost 9 years ago

Your code is recompiling the stylesheet on every transformation. (I assume it is the same stylesheet each time?). This is bad news from a performance perspective, because compiling the stylesheet is an expensive operation. But it's especially bad when bytecode is generated, because the bytecode is loaded into PermGen and is not easily garbage collected (also, bytecode generation takes time, so it is only really useful if the code is executed repeatedly.)

So if you possibly can, change your application to only compile the stylesheet once (by creating a Templates object). If that's not achievable, then switch off byte-code generation.

Actions #5

Updated by Arjun Kadayaprath almost 9 years ago

Thanks a lot Michael for the input. Let us make the changes and try it. And will revert in case we face any issue.

Thanks,

-Arjun

Actions #6

Updated by Arjun Kadayaprath almost 9 years ago

"change your application to only compile the stylesheet once (by creating a Templates object). If that's not achievable, then switch off byte-code generation."

I changed the application to compile the style sheet once per run. Which means the 1000+ transformations will do the compilation once. Would you still recommend to disable byte code generation? Switching off byte code will add an increased 25% time. But it will help us not increasing the permGen memory utilization? And as it is a one time compilation, we can afford to have 25% increase in the transformer creation time too.

Please let us know what you recommend.

Thank you very much,

-Arjun

Actions #7

Updated by Michael Kay almost 9 years ago

  • Tracker changed from Bug to Support

Transferring this to the Support tracker as it's clear we aren't talking about a product bug.

Sorry to leave the last question unanswered: please let us know whether you still have a problem.

Actions #8

Updated by Michael Kay almost 8 years ago

  • Status changed from New to Closed
  • Priority changed from High to Normal

Please register to edit this issue

Also available in: Atom PDF