You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Dominik Stadler <do...@dynatrace.com> on 2010/07/19 10:53:04 UTC

Keeping memory usage low when FOP is not running and avoid open file handles after FOP is run

Hi,

my use-case is to have FOP integrated into a larger server application, where FOP is only executed sporadically.

We already evaluated running FOP externally, but had severe trouble doing so for various reasons. Therefore we need to try to keep memory usage of FOP as low as possible when it is not running, I already had to do some workarounds to keep FOP from storing memory in caches or in thread locals, partly also the XML implementation from Sun interferes and keeps the whole FOP SAX Handler as thread local. Also any intermediate files need to be removed when FOP is finished rendering, something that caused me a bit of headache last week.

I have one final item that I just found and would like to get input if there is a better solution:
The FOUserAgent holds an element "imageSessionContext" which holds SoftReferences to Source/ImageSource elements via AbstractImageSessionContext.sessionSources. The memory for these items is cleaned correctly when we un-reference the FOUserAgent object, however the Source-items still hold a file-handle via the InputStream that is included in StreamSource/ImageStreamSource object. The effect is that I cannot remove intermediate image files that are used during PDF generation, but would like to delete after the PDF is created.

Currently I employ an ugly hack where I remember the file-names and afterwards use FOUserAgent.getImageSessionContext().getSource() to retrieve the Source and do the "close()" on the item manually.

-          Is this a bug, as file handles are kept open this way and are only given up, when the SoftReference is collected? So this can easily cause "out of handle" type of errors if a lot of memory is available and thus SoftReferences are not collected for a long time.
-          Is there a way to not keep these references in the first run? I use different images throughout the document, so image caching is not very useful for me anyway.

Thanks... Dominik.

Dominik Stadler, Team Lead
F +43 732 210100008 | E dominik.stadler@dynatrace.com<ma...@dynatrace.com> | Skype: stadler.dominik
dynaTrace is Continuous APM >> Monitor. Resolve. Prevent. >>
Web: http://www.dynatrace.com<http://www.dynatrace.com/> | Blog: http://blog.dynatrace.com<http://blog.dynatrace.com/>
Learn about dynaTrace in 2 minutes<http://www.dynatrace.com/twominutedemo/Default.aspx> | Forrester rates dynaTrace "On Fire"<http://applicationperformance.dynatrace.com/Forrester_Business_Transaction_Management_Report.html>. Get your copy of the report here<http://applicationperformance.dynatrace.com/Forrester_Business_Transaction_Management_Report.html>.
This e-mail message, including any attachments, is confidential and may contain legally privileged information. This message is intended solely for the use of the addressee. Use by others is prohibited. Disclosure, copying and distribution of this information to third parties is not permitted. If you have received this message in error, please notify us immediately and delete it from your system. The integrity and security of this message cannot be guaranteed and it may be subject to data corruption, interception and unauthorized amendment, for which we accept no liability.


RE: Keeping memory usage low when FOP is not running and avoid open file handles after FOP is run

Posted by Dominik Stadler <do...@dynatrace.com>.
Ok, I have reported https://issues.apache.org/bugzilla/show_bug.cgi?id=49621

Thanks... Dominik.

-----Original Message-----
From: Peter Hancock [mailto:peter.hancock@gmail.com] 
Sent: Montag, 19. Juli 2010 17:22
To: fop-users@xmlgraphics.apache.org
Subject: Re: Keeping memory usage low when FOP is not running and avoid open file handles after FOP is run

Hi Dominik,

This could well be a bug, akin to the issue dealt with here
https://issues.apache.org/bugzilla/show_bug.cgi?id=49060

Pete

On Mon, Jul 19, 2010 at 9:53 AM, Dominik Stadler
<do...@dynatrace.com> wrote:
> Hi,
>
>
>
> my use-case is to have FOP integrated into a larger server application,
> where FOP is only executed sporadically.
>
>
>
> We already evaluated running FOP externally, but had severe trouble doing so
> for various reasons. Therefore we need to try to keep memory usage of FOP as
> low as possible when it is not running, I already had to do some workarounds
> to keep FOP from storing memory in caches or in thread locals, partly also
> the XML implementation from Sun interferes and keeps the whole FOP SAX
> Handler as thread local. Also any intermediate files need to be removed when
> FOP is finished rendering, something that caused me a bit of headache last
> week.
>
>
>
> I have one final item that I just found and would like to get input if there
> is a better solution:
>
> The FOUserAgent holds an element "imageSessionContext" which holds
> SoftReferences to Source/ImageSource elements via
> AbstractImageSessionContext.sessionSources. The memory for these items is
> cleaned correctly when we un-reference the FOUserAgent object, however the
> Source-items still hold a file-handle via the InputStream that is included
> in StreamSource/ImageStreamSource object. The effect is that I cannot remove
> intermediate image files that are used during PDF generation, but would like
> to delete after the PDF is created.
>
>
>
> Currently I employ an ugly hack where I remember the file-names and
> afterwards use FOUserAgent.getImageSessionContext().getSource() to retrieve
> the Source and do the "close()" on the item manually.
>
>
>
> -          Is this a bug, as file handles are kept open this way and are
> only given up, when the SoftReference is collected? So this can easily cause
> "out of handle" type of errors if a lot of memory is available and thus
> SoftReferences are not collected for a long time.
>
> -          Is there a way to not keep these references in the first run? I
> use different images throughout the document, so image caching is not very
> useful for me anyway.
>
>
>
> Thanks. Dominik.
>
>
>
> Dominik Stadler, Team Lead
> F +43 732 210100008 | E dominik.stadler@dynatrace.com | Skype:
> stadler.dominik
>
> dynaTrace is Continuous APM >> Monitor. Resolve. Prevent. >>
>
> Web: http://www.dynatrace.com | Blog: http://blog.dynatrace.com
>
> Learn about dynaTrace in 2 minutes | Forrester rates dynaTrace "On Fire".
> Get your copy of the report here.
>
> This e-mail message, including any attachments, is confidential and may
> contain legally privileged information. This message is intended solely for
> the use of the addressee. Use by others is prohibited. Disclosure, copying
> and distribution of this information to third parties is not permitted. If
> you have received this message in error, please notify us immediately and
> delete it from your system. The integrity and security of this message
> cannot be guaranteed and it may be subject to data corruption, interception
> and unauthorized amendment, for which we accept no liability.
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Keeping memory usage low when FOP is not running and avoid open file handles after FOP is run

Posted by Peter Hancock <pe...@gmail.com>.
Hi Dominik,

This could well be a bug, akin to the issue dealt with here
https://issues.apache.org/bugzilla/show_bug.cgi?id=49060

Pete

On Mon, Jul 19, 2010 at 9:53 AM, Dominik Stadler
<do...@dynatrace.com> wrote:
> Hi,
>
>
>
> my use-case is to have FOP integrated into a larger server application,
> where FOP is only executed sporadically.
>
>
>
> We already evaluated running FOP externally, but had severe trouble doing so
> for various reasons. Therefore we need to try to keep memory usage of FOP as
> low as possible when it is not running, I already had to do some workarounds
> to keep FOP from storing memory in caches or in thread locals, partly also
> the XML implementation from Sun interferes and keeps the whole FOP SAX
> Handler as thread local. Also any intermediate files need to be removed when
> FOP is finished rendering, something that caused me a bit of headache last
> week.
>
>
>
> I have one final item that I just found and would like to get input if there
> is a better solution:
>
> The FOUserAgent holds an element “imageSessionContext” which holds
> SoftReferences to Source/ImageSource elements via
> AbstractImageSessionContext.sessionSources. The memory for these items is
> cleaned correctly when we un-reference the FOUserAgent object, however the
> Source-items still hold a file-handle via the InputStream that is included
> in StreamSource/ImageStreamSource object. The effect is that I cannot remove
> intermediate image files that are used during PDF generation, but would like
> to delete after the PDF is created.
>
>
>
> Currently I employ an ugly hack where I remember the file-names and
> afterwards use FOUserAgent.getImageSessionContext().getSource() to retrieve
> the Source and do the “close()” on the item manually.
>
>
>
> -          Is this a bug, as file handles are kept open this way and are
> only given up, when the SoftReference is collected? So this can easily cause
> “out of handle” type of errors if a lot of memory is available and thus
> SoftReferences are not collected for a long time.
>
> -          Is there a way to not keep these references in the first run? I
> use different images throughout the document, so image caching is not very
> useful for me anyway.
>
>
>
> Thanks… Dominik.
>
>
>
> Dominik Stadler, Team Lead
> F +43 732 210100008 | E dominik.stadler@dynatrace.com | Skype:
> stadler.dominik
>
> dynaTrace is Continuous APM >> Monitor. Resolve. Prevent. >>
>
> Web: http://www.dynatrace.com | Blog: http://blog.dynatrace.com
>
> Learn about dynaTrace in 2 minutes | Forrester rates dynaTrace “On Fire”.
> Get your copy of the report here.
>
> This e-mail message, including any attachments, is confidential and may
> contain legally privileged information. This message is intended solely for
> the use of the addressee. Use by others is prohibited. Disclosure, copying
> and distribution of this information to third parties is not permitted. If
> you have received this message in error, please notify us immediately and
> delete it from your system. The integrity and security of this message
> cannot be guaranteed and it may be subject to data corruption, interception
> and unauthorized amendment, for which we accept no liability.
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org