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 Noya Paolo <p....@fineco.it> on 2007/11/28 16:46:46 UTC

FOP Servlet Performance Problem

I'm using FOP 0.94 with JDK 1.4 for producing a simple 1 page PDF
transforming a simple XML on a Mandrake Linux release 9.2 for i586.
If I try with command line the result is about in 3 or 4 second. 
Next I write a Servlet on JRun 4.0:
 
public void init() throws ServletException {
    uriResolver = new ServletContextURIResolver(getServletContext());
    TransformerFactory tFactory = TransformerFactory.newInstance();

    tFactory.setURIResolver(uriResolver);

    //Cache del template XSLT
    try {
        Source xsltSrc =
uriResolver.resolve("servlet-context:/template/fo.xsl", null);
        cachedXSLT = tFactory.newTemplates(xsltSrc);
    } catch (Exception e) {
        throw new ServletException(e);
    }

    //config di FOP
    fopFactory = FopFactory.newInstance();
    fopFactory.setURIResolver(uriResolver);
    fopFactory.setSourceResolution(96); //96dpi
    fopFactory.setTargetResolution(96); //96dpi
}

protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
    (...)

    ByteArrayOutputStream pdf = new ByteArrayOutputStream();

    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
fopFactory.newFOUserAgent(), pdf);

    Transformer transformer = cachedXSLT.newTransformer();
    transformer.setURIResolver(uriResolver); 

    Result res = new SAXResult(fop.getDefaultHandler());

    Source src = new StreamSource(new StringReader(theXML));

    transformer.setParameter("param", "value");
    transformer.transform(src, res);

    (...)
}
 
All work fine but the latter line (transformer.transform(src, res);)
take about 40 seconds to generate PDF, I saw that during transformation
CPU usage is about 50% user and about 10% system.
Can anyone tell me what is the problem?
 
Thanks in advance for your kind attention
Paolo
 
 
 
 
 
 

Re: FOP Servlet Performance Problem

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Nov 28, 2007, at 16:46, Noya Paolo wrote:

Hi

Sorry for the late reply.

As Jeremias already indicated, profiling is one option. There are  
various tools and there is lots of documentation available on the  
internet concerning profiling of the JVM. Just Google around for  
'java profiling' and that should help you on your way.

Other than that, I see one possible cause for your issue:

> <snip />
>     Source src = new StreamSource(new StringReader(theXML));
>

While there is nothing inherently wrong about the above, depending on  
the implementation of StreamSource it is possible that this causes  
underlying calls to StringReader.read() instead of StringReader.read 
(char[], int, int), which means that your source XML gets read in one  
character at a time, which in turn would cause a noticeable slowdown...

No idea if it would help here, but maybe one of my first tries would be:

  Source src = new StreamSource(new BufferedReader(new StringReader 
(theXML)));


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: FOP Servlet Performance Problem

Posted by Noya Paolo <p....@fineco.it>.
Jeremias thanks for your reply,
can you explain me what do you mean for profile the JVM and how i can
archieve the goal?
 
sorry for my annoyance
Thanks 
 

>No idea where that could come from. I think the only thing you can do
is
>profile the JVM and find out where exactly the time is lost. When you
>say transformer.transform() takes more than 30 seconds it can still be
>one of thousand things. Profiling is the only option really.
>
>
>Jeremias Maerki
 
 

Re: FOP Servlet Performance Problem

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
No idea where that could come from. I think the only thing you can do is
profile the JVM and find out where exactly the time is lost. When you
say transformer.transform() takes more than 30 seconds it can still be
one of thousand things. Profiling is the only option really.

Jeremias Maerki



On 28.11.2007 16:46:46 Noya Paolo wrote:
> I'm using FOP 0.94 with JDK 1.4 for producing a simple 1 page PDF
> transforming a simple XML on a Mandrake Linux release 9.2 for i586.
> If I try with command line the result is about in 3 or 4 second. 
> Next I write a Servlet on JRun 4.0:
>  
> public void init() throws ServletException {
>     uriResolver = new ServletContextURIResolver(getServletContext());
>     TransformerFactory tFactory = TransformerFactory.newInstance();
> 
>     tFactory.setURIResolver(uriResolver);
> 
>     //Cache del template XSLT
>     try {
>         Source xsltSrc =
> uriResolver.resolve("servlet-context:/template/fo.xsl", null);
>         cachedXSLT = tFactory.newTemplates(xsltSrc);
>     } catch (Exception e) {
>         throw new ServletException(e);
>     }
> 
>     //config di FOP
>     fopFactory = FopFactory.newInstance();
>     fopFactory.setURIResolver(uriResolver);
>     fopFactory.setSourceResolution(96); //96dpi
>     fopFactory.setTargetResolution(96); //96dpi
> }
> 
> protected void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
>     (...)
> 
>     ByteArrayOutputStream pdf = new ByteArrayOutputStream();
> 
>     Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
> fopFactory.newFOUserAgent(), pdf);
> 
>     Transformer transformer = cachedXSLT.newTransformer();
>     transformer.setURIResolver(uriResolver); 
> 
>     Result res = new SAXResult(fop.getDefaultHandler());
> 
>     Source src = new StreamSource(new StringReader(theXML));
> 
>     transformer.setParameter("param", "value");
>     transformer.transform(src, res);
> 
>     (...)
> }
>  
> All work fine but the latter line (transformer.transform(src, res);)
> take about 40 seconds to generate PDF, I saw that during transformation
> CPU usage is about 50% user and about 10% system.
> Can anyone tell me what is the problem?
>  
> Thanks in advance for your kind attention
> Paolo
>  
>  
>  
>  
>  
>  


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