You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Carlo Marchiori (JIRA)" <xa...@xml.apache.org> on 2005/05/09 17:54:04 UTC
[jira] Created: (XALANJ-2117) OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
--------------------------------------------------------------------------------------
Key: XALANJ-2117
URL: http://issues.apache.org/jira/browse/XALANJ-2117
Project: XalanJ2
Type: Bug
Components: Xalan
Versions: 2.6
Environment: generic
Reporter: Carlo Marchiori
This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).
The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)
---------------------------------------------------------------------
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Prova
{
public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
{
final TransformerFactory newInstance = TransformerFactory.newInstance();
final Object monitor = new Object ();
for (;;)
{
synchronized (monitor)
{
new Thread ()
{
public void run ()
{
try
{
synchronized (monitor)
{
Source xsl = new StreamSource ("prova.xsl");
Transformer transformer = newInstance.newTransformer(xsl);
Source xml = new StreamSource ("prova.xml");
transformer.transform(xml, new StreamResult ("ouput.xml"));
monitor.notify();
}
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}.start();
monitor.wait();
Thread.yield();
}
}
}
}
---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Updated: (XALANJ-2117) OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
Posted by "Carlo Marchiori (JIRA)" <xa...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XALANJ-2117?page=all ]
Carlo Marchiori updated XALANJ-2117:
------------------------------------
Attachment: XMLReaderManager.java
I've tried the WeakHashMap way and it works fine: each cached parser is garbage collected with the thread it's associated to through the a thread local reference.
The program posted previously works perfectly with this patch, so I attach my new version of XMLReaderManager.
> OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
> --------------------------------------------------------------------------------------
>
> Key: XALANJ-2117
> URL: http://issues.apache.org/jira/browse/XALANJ-2117
> Project: XalanJ2
> Type: Bug
> Components: Xalan
> Versions: 2.6
> Environment: generic
> Reporter: Carlo Marchiori
> Attachments: XMLReaderManager.java, src.zip
>
> This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).
> The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)
> ---------------------------------------------------------------------
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.TransformerFactoryConfigurationError;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class Prova
> {
>
> public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
> {
> final TransformerFactory newInstance = TransformerFactory.newInstance();
> final Object monitor = new Object ();
>
> for (;;)
> {
> synchronized (monitor)
> {
> new Thread ()
> {
> public void run ()
> {
> try
> {
> synchronized (monitor)
> {
> Source xsl = new StreamSource ("prova.xsl");
> Transformer transformer = newInstance.newTransformer(xsl);
> Source xml = new StreamSource ("prova.xml");
> transformer.transform(xml, new StreamResult ("ouput.xml"));
> monitor.notify();
> }
> }
> catch (Exception e)
> {
> e.printStackTrace();
> System.exit(1);
> }
> }
> }.start();
> monitor.wait();
> Thread.yield();
> }
>
> }
> }
> }
> ---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Resolved: (XALANJ-2117) OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
Posted by "Henry Zongaro (JIRA)" <xa...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XALANJ-2117?page=all ]
Henry Zongaro resolved XALANJ-2117:
-----------------------------------
Resolution: Duplicate
Fix Version: CurrentCVS
This problem is a duplicate of XALANJ-1844.
> OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
> --------------------------------------------------------------------------------------
>
> Key: XALANJ-2117
> URL: http://issues.apache.org/jira/browse/XALANJ-2117
> Project: XalanJ2
> Type: Bug
> Components: Xalan
> Versions: 2.6
> Environment: generic
> Reporter: Carlo Marchiori
> Fix For: CurrentCVS
> Attachments: XMLReaderManager.java, XMLReaderManager.java, src.zip
>
> This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).
> The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)
> ---------------------------------------------------------------------
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.TransformerFactoryConfigurationError;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class Prova
> {
>
> public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
> {
> final TransformerFactory newInstance = TransformerFactory.newInstance();
> final Object monitor = new Object ();
>
> for (;;)
> {
> synchronized (monitor)
> {
> new Thread ()
> {
> public void run ()
> {
> try
> {
> synchronized (monitor)
> {
> Source xsl = new StreamSource ("prova.xsl");
> Transformer transformer = newInstance.newTransformer(xsl);
> Source xml = new StreamSource ("prova.xml");
> transformer.transform(xml, new StreamResult ("ouput.xml"));
> monitor.notify();
> }
> }
> catch (Exception e)
> {
> e.printStackTrace();
> System.exit(1);
> }
> }
> }.start();
> monitor.wait();
> Thread.yield();
> }
>
> }
> }
> }
> ---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Updated: (XALANJ-2117) OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
Posted by "Brian Minchau (JIRA)" <xa...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XALANJ-2117?page=all ]
Brian Minchau updated XALANJ-2117:
----------------------------------
Fix Version: 2.7
(was: CurrentCVS)
> OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
> --------------------------------------------------------------------------------------
>
> Key: XALANJ-2117
> URL: http://issues.apache.org/jira/browse/XALANJ-2117
> Project: XalanJ2
> Type: Bug
> Components: Xalan
> Versions: 2.6
> Environment: generic
> Reporter: Carlo Marchiori
> Fix For: 2.7
> Attachments: XMLReaderManager.java, XMLReaderManager.java, src.zip
>
> This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).
> The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)
> ---------------------------------------------------------------------
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.TransformerFactoryConfigurationError;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class Prova
> {
>
> public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
> {
> final TransformerFactory newInstance = TransformerFactory.newInstance();
> final Object monitor = new Object ();
>
> for (;;)
> {
> synchronized (monitor)
> {
> new Thread ()
> {
> public void run ()
> {
> try
> {
> synchronized (monitor)
> {
> Source xsl = new StreamSource ("prova.xsl");
> Transformer transformer = newInstance.newTransformer(xsl);
> Source xml = new StreamSource ("prova.xml");
> transformer.transform(xml, new StreamResult ("ouput.xml"));
> monitor.notify();
> }
> }
> catch (Exception e)
> {
> e.printStackTrace();
> System.exit(1);
> }
> }
> }.start();
> monitor.wait();
> Thread.yield();
> }
>
> }
> }
> }
> ---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Updated: (XALANJ-2117) OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
Posted by "Carlo Marchiori (JIRA)" <xa...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XALANJ-2117?page=all ]
Carlo Marchiori updated XALANJ-2117:
------------------------------------
Attachment: XMLReaderManager.java
It is still questionable if the cache is useful.
In the application which led me to discover the bug I find thread local cached parsers which keep in memory up to 10MB (yes, megabyte) of data. In a server it's not strange to have tens of threads, so there is a potential memory loss of hundreds of MB. I think this is unacceptable.
So I post a new version of XMLReaderManager with cache disabled.
> OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
> --------------------------------------------------------------------------------------
>
> Key: XALANJ-2117
> URL: http://issues.apache.org/jira/browse/XALANJ-2117
> Project: XalanJ2
> Type: Bug
> Components: Xalan
> Versions: 2.6
> Environment: generic
> Reporter: Carlo Marchiori
> Attachments: XMLReaderManager.java, XMLReaderManager.java, src.zip
>
> This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).
> The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)
> ---------------------------------------------------------------------
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.TransformerFactoryConfigurationError;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class Prova
> {
>
> public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
> {
> final TransformerFactory newInstance = TransformerFactory.newInstance();
> final Object monitor = new Object ();
>
> for (;;)
> {
> synchronized (monitor)
> {
> new Thread ()
> {
> public void run ()
> {
> try
> {
> synchronized (monitor)
> {
> Source xsl = new StreamSource ("prova.xsl");
> Transformer transformer = newInstance.newTransformer(xsl);
> Source xml = new StreamSource ("prova.xml");
> transformer.transform(xml, new StreamResult ("ouput.xml"));
> monitor.notify();
> }
> }
> catch (Exception e)
> {
> e.printStackTrace();
> System.exit(1);
> }
> }
> }.start();
> monitor.wait();
> Thread.yield();
> }
>
> }
> }
> }
> ---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Commented: (XALANJ-2117) OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
Posted by "Carlo Marchiori (JIRA)" <xa...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XALANJ-2117?page=comments#action_64994 ]
Carlo Marchiori commented on XALANJ-2117:
-----------------------------------------
Sorry for not having spotted the duplication before.
I don't known which solution was adopted for issue 1844, yet it is still questionable if the cache is useful, even after the resolution of the bug which kept in memory parsers after the associated thread died.
In the application which led me to discover the bug I found thread local cached parsers which kept in memory up to 10MB (yes, megabyte) of data each. In a server it's not strange to have tens of live threads, so there is a potential memory loss of hundreds of MB. I think this is unacceptable.
In issue XALANJ-1844 there is a link to an IBM fixpack, yet the link is broken. May you please point me to the correct site?
Thanks,
Carlo.
> OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
> --------------------------------------------------------------------------------------
>
> Key: XALANJ-2117
> URL: http://issues.apache.org/jira/browse/XALANJ-2117
> Project: XalanJ2
> Type: Bug
> Components: Xalan
> Versions: 2.6
> Environment: generic
> Reporter: Carlo Marchiori
> Fix For: CurrentCVS
> Attachments: XMLReaderManager.java, XMLReaderManager.java, src.zip
>
> This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).
> The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)
> ---------------------------------------------------------------------
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.TransformerFactoryConfigurationError;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class Prova
> {
>
> public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
> {
> final TransformerFactory newInstance = TransformerFactory.newInstance();
> final Object monitor = new Object ();
>
> for (;;)
> {
> synchronized (monitor)
> {
> new Thread ()
> {
> public void run ()
> {
> try
> {
> synchronized (monitor)
> {
> Source xsl = new StreamSource ("prova.xsl");
> Transformer transformer = newInstance.newTransformer(xsl);
> Source xml = new StreamSource ("prova.xml");
> transformer.transform(xml, new StreamResult ("ouput.xml"));
> monitor.notify();
> }
> }
> catch (Exception e)
> {
> e.printStackTrace();
> System.exit(1);
> }
> }
> }.start();
> monitor.wait();
> Thread.yield();
> }
>
> }
> }
> }
> ---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Commented: (XALANJ-2117) OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
Posted by "Carlo Marchiori (JIRA)" <xa...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XALANJ-2117?page=comments#action_64818 ]
Carlo Marchiori commented on XALANJ-2117:
-----------------------------------------
At least the m_inUse variable of XMLReaderManager instances should be turned into a WeakHashMap (now it is simply an HashMap), so that, when a thread dies and is garbage collected, the associated parser (through the ThreadLocal m_readers variable) is not prevented from being garbage collected.
Otherwise caching may be completely turned off. Is parser creation such a resource demanding operation? parserfactory creation is, because there is the service api mechanism, which may imply reading an external file. So the cache may be restricted to the parserfactory.
This bug is related to bug 1980 (http://issues.apache.org/jira/browse/XALANJ-1980). When I analyzed the Websphere memorydump using the HeapWizard program, I obtained the same results described there (namely abundance of AxesWalker objects as heap roots). These results are in my opinion an HeapWizard misrepresentation. When I actually analyzed the same memorydump using HeapAnalyzer, a similar tool supported by IBM, it gave me a completely differente picture, in which the memory leak is correctly assigned to the parser cache.
> OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
> --------------------------------------------------------------------------------------
>
> Key: XALANJ-2117
> URL: http://issues.apache.org/jira/browse/XALANJ-2117
> Project: XalanJ2
> Type: Bug
> Components: Xalan
> Versions: 2.6
> Environment: generic
> Reporter: Carlo Marchiori
> Attachments: src.zip
>
> This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).
> The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)
> ---------------------------------------------------------------------
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.TransformerFactoryConfigurationError;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class Prova
> {
>
> public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
> {
> final TransformerFactory newInstance = TransformerFactory.newInstance();
> final Object monitor = new Object ();
>
> for (;;)
> {
> synchronized (monitor)
> {
> new Thread ()
> {
> public void run ()
> {
> try
> {
> synchronized (monitor)
> {
> Source xsl = new StreamSource ("prova.xsl");
> Transformer transformer = newInstance.newTransformer(xsl);
> Source xml = new StreamSource ("prova.xml");
> transformer.transform(xml, new StreamResult ("ouput.xml"));
> monitor.notify();
> }
> }
> catch (Exception e)
> {
> e.printStackTrace();
> System.exit(1);
> }
> }
> }.start();
> monitor.wait();
> Thread.yield();
> }
>
> }
> }
> }
> ---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Updated: (XALANJ-2117) OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
Posted by "Carlo Marchiori (JIRA)" <xa...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XALANJ-2117?page=all ]
Carlo Marchiori updated XALANJ-2117:
------------------------------------
Attachment: src.zip
A complete example causing the OutOfMemoryError. The code is in my opinion completely legal as of JAXP, so the crash should not happen.
> OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances
> --------------------------------------------------------------------------------------
>
> Key: XALANJ-2117
> URL: http://issues.apache.org/jira/browse/XALANJ-2117
> Project: XalanJ2
> Type: Bug
> Components: Xalan
> Versions: 2.6
> Environment: generic
> Reporter: Carlo Marchiori
> Attachments: src.zip
>
> This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).
> The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)
> ---------------------------------------------------------------------
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.TransformerFactoryConfigurationError;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> public class Prova
> {
>
> public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
> {
> final TransformerFactory newInstance = TransformerFactory.newInstance();
> final Object monitor = new Object ();
>
> for (;;)
> {
> synchronized (monitor)
> {
> new Thread ()
> {
> public void run ()
> {
> try
> {
> synchronized (monitor)
> {
> Source xsl = new StreamSource ("prova.xsl");
> Transformer transformer = newInstance.newTransformer(xsl);
> Source xml = new StreamSource ("prova.xml");
> transformer.transform(xml, new StreamResult ("ouput.xml"));
> monitor.notify();
> }
> }
> catch (Exception e)
> {
> e.printStackTrace();
> System.exit(1);
> }
> }
> }.start();
> monitor.wait();
> Thread.yield();
> }
>
> }
> }
> }
> ---------------------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org