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 Thomas Yip <ty...@stelvio.com> on 2007/03/12 16:52:46 UTC

Performance issue XSL:FO

Hi,

I'm generating a PDF on the fly from my servlet. I use transformer to
do XSL:FO translation:

1> StringReader xmlStream = new StringReader(xmlWriter.toString());
2> Source src = new StreamSource(xmlStream);
3> Result res = new SAXResult(fop.getDefaultHandler());
4> transformer.transform(src, res);

However line#4 seems to be taking a lot of time to execute (around 40
seconds).

When I run it using the FOP command line (with the same XML content),
for instance:

>> fop -xml myXml.xml -xsl myXsl.xsl -pdf outPDF.pdf

It takes only about 3 seconds.

- Can anybody tell me why it takes so much longer from my servlet?
- Is there a way to improve the performance when run it from my
servlet?

By the way, I use FOP version 0.93.
I'm running my servlet in an application server (BEA Weblogic 9.2
using jdk150_06).

Thanks for your help.
Thomas



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


Re: Performance issue XSL:FO

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Mar 12, 2007, at 16:52, Thomas Yip wrote:

> 1> StringReader xmlStream = new StringReader(xmlWriter.toString());
> 2> Source src = new StreamSource(xmlStream);
> 3> Result res = new SAXResult(fop.getDefaultHandler());
> 4> transformer.transform(src, res);
>
> However line#4 seems to be taking a lot of time to execute (around 40
> seconds).

If I judge correctly, then what's causing the slowdown might just be  
line #1, but it's only when the transform is initiated that it  
becomes apparent this is a Bad idea...

Where does the xmlWriter come from? What is its type? Try to find a  
more efficient way than first converting it in into a String and  
wrapping a StringReader around it.


Cheers,

Andreas


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


Re: Performance issue XSL:FO

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Mar 12, 2007, at 18:43, Thomas Yip wrote:

Hi again,

> Yes, I did log the time as follow:
>
>> long time1 = System.currentTimeMillis();
>> transformer.transform(src, res);
>> long time2 = System.currentTimeMillis();
>
> And the difference between time2 and time1 is really about 40 seconds.
> In command line, I redo the same test with the same XML and it takes
> only 5 seconds.
>
> I will try to increase the memory allocated to my apps server though
> to see if there's a significant improvement and I'll let you know.
>
> However, can the performance be affected if I have a XSL file that
> includes many others XSL files when it is being used in a servlet, for
> instance:

See my previous reply. I think the problem is not in the XSLT stage,  
but actually happens before that.

Firstly, xmlWriter.toString() probably involves conversion/encoding  
from bytes to characters. If the XML is large, then this also  
consumes a significant amount of memory, as it will allocate a  
backing char[] that is as long as the XML string. If you'd try this  
with a 50MB XML-file in a servlet environment with a relatively small  
amount of memory if calculated 'per user/process', then you're  
already bound to run into trouble...

Then a StringReader is constructed around it. This is not very costly  
(yet!).

Subsequently, you feed this StringReader into the constructor of a  
StreamSource. If you look in the Javadocs of that particular  
constructor, notice the remark that its use is actually discouraged.

Finally, the transform is initiated, and I fear that behind the  
scenes, there is absolutely no buffering done in the StringReader, so  
your XML-string gets read back in /one/ character at a time...

Conclusion: if you can, in any way, avoid the StringReader and  
construct the StreamSource using an InputStream, preferably  
BufferedInputStream, that should speed things up considerably IIC...


HTH!

Cheers,

Andreas


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


Re: Performance issue XSL:FO

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 12.03.2007 19:59:26 Abel Braaksma wrote:
> Thomas Yip wrote:
> > [...]
> > <xsl:include href="../template1.xsl" />
> > <xsl:include href="template2.xsl"/>
> > <xsl:include href="template3.xsl" />
> > <xsl:include href="template4.xsl" />
> > <xsl:include href="template5.xsl" />
> >
> > [...]
> >
> > <!-- Body -->
> > <fo:flow flow-name="xsl-region-body">
> >   fo:block>
> >     <xsl:call-template name="template1" /> <!--in template1.xsl-->
> >     <xsl:call-template name="template2" /> <!--in template2.xsl-->
> >     <xsl:call-template name="template3" /> <!--in template3.xsl-->
> >     <xsl:call-template name="template4" /> <!--in template4.xsl-->
> >     <xsl:call-template name="template5" /> <!--in template5.xsl-->
> >   </fo:block>
> > </fo:flow>
> > [...]
> 
> Now it is XSLT, not XSL-FO. I thought the XSL-FO process was causing the 
> trouble (see your own OP).
> 
> I don't see why this (including many stylesheets) would cause you 
> problems with running XSLT.

I agree. Actually, the whole thing should be faster in a servlet since
you don't have the VM warmup time. Plus in a servlet you can make sure
you reuse the TransformerFactory and the FopFactory and finally reusing
the JAXP Templates object representing the stylesheet could also help
optimizing as the stylesheet wouldn't have to be parsed each time.

Anyway, if the command-line is that much faster than inside the servlet
the problem must be somewhere else: Either to little memory and the VM
is constantly garbage collecting or some other thing (maybe like Andreas
indicated) is wrong. I'd try to divide all the steps and measure them
separately to find the culprit.

Jeremias Maerki


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


Re: Performance issue XSL:FO

Posted by Abel Braaksma <ab...@xs4all.nl>.
Thomas Yip wrote:
> [...]
> <xsl:include href="../template1.xsl" />
> <xsl:include href="template2.xsl"/>
> <xsl:include href="template3.xsl" />
> <xsl:include href="template4.xsl" />
> <xsl:include href="template5.xsl" />
>
> [...]
>
> <!-- Body -->
> <fo:flow flow-name="xsl-region-body">
>   fo:block>
>     <xsl:call-template name="template1" /> <!--in template1.xsl-->
>     <xsl:call-template name="template2" /> <!--in template2.xsl-->
>     <xsl:call-template name="template3" /> <!--in template3.xsl-->
>     <xsl:call-template name="template4" /> <!--in template4.xsl-->
>     <xsl:call-template name="template5" /> <!--in template5.xsl-->
>   </fo:block>
> </fo:flow>
> [...]

Now it is XSLT, not XSL-FO. I thought the XSL-FO process was causing the 
trouble (see your own OP).

I don't see why this (including many stylesheets) would cause you 
problems with running XSLT.

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


RE: Performance issue XSL:FO

Posted by Thomas Yip <ty...@stelvio.com>.
Hi Abel,

Thank you for your reply. Sorry, I copied/pasted my last email sent to
the other mailing list and forgot to be more specific.

Yes, I did log the time as follow:

> long time1 = System.currentTimeMillis();
> transformer.transform(src, res);
> long time2 = System.currentTimeMillis();

And the difference between time2 and time1 is really about 40 seconds.
In command line, I redo the same test with the same XML and it takes
only 5 seconds.

I will try to increase the memory allocated to my apps server though
to see if there's a significant improvement and I'll let you know.

However, can the performance be affected if I have a XSL file that
includes many others XSL files when it is being used in a servlet, for
instance:

[...]
<xsl:include href="../template1.xsl" />
<xsl:include href="template2.xsl"/>
<xsl:include href="template3.xsl" />
<xsl:include href="template4.xsl" />
<xsl:include href="template5.xsl" />

[...]

<!-- Body -->
<fo:flow flow-name="xsl-region-body">
  fo:block>
    <xsl:call-template name="template1" /> <!--in template1.xsl-->
    <xsl:call-template name="template2" /> <!--in template2.xsl-->
    <xsl:call-template name="template3" /> <!--in template3.xsl-->
    <xsl:call-template name="template4" /> <!--in template4.xsl-->
    <xsl:call-template name="template5" /> <!--in template5.xsl-->
  </fo:block>
</fo:flow>
[...]

Thanks again for your help,
Thomas

-----Original Message-----
From: Abel Braaksma [mailto:abel.online@xs4all.nl] 
Sent: Monday, March 12, 2007 12:05 PM
To: fop-users@xmlgraphics.apache.org
Subject: Re: Performance issue XSL:FO

Thomas Yip wrote:
> 4> transformer.transform(src, res);
>
> However line#4 seems to be taking a lot of time to execute (around
40
> seconds).

Thomas, good to see you here. But it would be much easier for us to
help 
you if you at least answered my questions that I raised in the
original 
thread on the xsl-list, especially to those that are a member of both 
lists (and many are). Also, if your statement "seems to be" is changed

in "is", add a little code snippet that on itself illustrates the
problem.

And I like to repeat my experience with FOP 0.93 here: I use it from a

servlet with no performance hit whatsoever, but both memory consuming
of 
FOP and in-memory serialization of the HTTP output stream can be
causing 
this. But first and foremost: add time logging statements to make sure

your statement above holds.

Cheers,
-- Abel Braaksma

---------------------------------------------------------------------
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: Performance issue XSL:FO

Posted by Abel Braaksma <ab...@xs4all.nl>.
Thomas Yip wrote:
> 4> transformer.transform(src, res);
>
> However line#4 seems to be taking a lot of time to execute (around 40
> seconds).

Thomas, good to see you here. But it would be much easier for us to help 
you if you at least answered my questions that I raised in the original 
thread on the xsl-list, especially to those that are a member of both 
lists (and many are). Also, if your statement "seems to be" is changed 
in "is", add a little code snippet that on itself illustrates the problem.

And I like to repeat my experience with FOP 0.93 here: I use it from a 
servlet with no performance hit whatsoever, but both memory consuming of 
FOP and in-memory serialization of the HTTP output stream can be causing 
this. But first and foremost: add time logging statements to make sure 
your statement above holds.

Cheers,
-- Abel Braaksma

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