RichFaces DocumentBuilder performance issue
Environment
- JBoss Enterprise Application Platform (EAP)
- 5.1.0
- 5.1.1
- RichFaces
- 3.3.1.SP1
- 3.3.1.SP2
Issue
- The Richfaces creates a org.apache.xerces.jaxp.DocumentBuilder instance for each request. This causes bad performance.
- We have profiled out application and it seems 80+% of the object allocations are org.ajax4jsf.context.ResponseWriterContentHandler.
calling javax.xml.parsers.DocumentBuilderFactory.newInstance() at least once for every page request.
Resolution
Please update to EAP 5.1.2. This issue was tracked by the JIRA Content from issues.jboss.org is not included.RF-10035 and fixed in RichFaces 3.3.1.SP3 which is included in EAP 5.1.2.
One-off patch for EAP 5.1.0 is available from here: This content is not included.Fix RF-10035 DocumentBuilder performance issue, which was tracked by the JIRA Content from issues.jboss.org is not included.JBPAPP-6166.
Root Cause
This is a bug. The Richfaces creates a org.apache.xerces.jaxp.DocumentBuilder instance for each request. The creation of the org.apache.xerces.jaxp.DocumentBuilder instance is very expensive.
Diagnostic Steps
Take thread dump several times. The following stack trace appears.
java.lang.Thread.State: BLOCKED (on object monitor)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
- waiting to lock <0xfffffffe700000e0> (a sun.misc.Launcher$AppClassLoader)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1299)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1229)
at org.apache.xerces.impl.dv.ObjectFactory.findProviderClass(Unknown Source)
at org.apache.xerces.impl.dv.ObjectFactory.newInstance(Unknown Source)
at org.apache.xerces.impl.dv.DTDDVFactory.getInstance(Unknown Source)
at org.apache.xerces.impl.dv.DTDDVFactory.getInstance(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.<init>(Unknown Source)
at org.apache.xerces.parsers.XIncludeAwareParserConfiguration.<init>(Unknown Source)
at org.apache.xerces.parsers.XIncludeAwareParserConfiguration.<init>(Unknown Source)
at sun.reflect.GeneratedConstructorAccessor5.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.newInstance(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown Source)
at org.ajax4jsf.context.ResponseWriterContentHandler.<init>(ResponseWriterContentHandler.java:48)
at org.ajax4jsf.context.ViewResources$HeadResponseWriter.<init>(ViewResources.java:259)
...(snip)...
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.