You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Berglas, Anthony" <ab...@rsasecurity.com> on 2007/10/29 10:58:37 UTC

Fix to Tomcat Jasper slow .tag compilation problem.

As described in a previous post, Jasper is *extremely* slow at compiling
.tag files packaged in a .jar.  Tens of seconds every time you touch a
new .jsp for the first time.  Almost unusable if you use .tags
extensively, as I do.

The following few lines is a hack to fix this.  The added code is marked
between // -------- AJB markers.  It effectively turns off the timestamp
checking on .jar files.

This does NOT actually introduce a bug.  There is an existing bug in
that .jsp files are not automatically recompiled if any .tags in .jars
are changed.  So you need to purge work in either case.  A proper fix
would be to check dependencies properly, at least to the .jar file
itself.  But the current fix is *much* better that the existing
behavior.

COULD SOMEBODY PLEASE ARRANGE FOR THIS CODE TO BE ADDED TO THE CURRENT
SUBVERSION REPOSITORY? 

Outstanding is to make the compilation of .tags themselves much faster,
not tens of seconds.  To do that one needs to call the Java compiler
once at the end for all the .tags, rather than once for each individual
.tag which is *much* slower.

I must admit that I got rather lost reading the Jasper source, with all
the contexts etc.  Some better comments on the classes describing their
relationships to each other would be most helpful.

Thanks,

Anthony



// Tomcat 6.0.10 Src deployed version.

public class JspCompilationContext {...

    public void compile() throws JasperException, FileNotFoundException
{
        createCompiler();

        // ------------ begin AJB
        // Hack to stop .tag files that are packaged in .jars being
recompiled for every single .jsp that uses them.
        // The hack means that .tag files will not be automatically
recompiled if they change -- you need to delete work area.
        // But that was actually an existing bug -- .jsps are not
dependent on the .tag .jars so the work area needed deleting anyway.
        // (Outstanding is to compile multiple .tags in one pass and so
make the process Much faster.)
        boolean outDated;
        if (isPackagedTagFile) outDated = ! new
File(getClassFileName()).exists();
        else outDated = jspCompiler.isOutDated();
//        AjbLog.log("### Compiler.compile " + jspUri + " pkgTagFile " +
isPackagedTagFile + " outDated " + outDated + " " + getClassFileName());
        if (outDated) {
//     if (isPackagedTagFile || jspCompiler.isOutDated()) {
//     ---------------- end AJB
            try {
                jspCompiler.removeGeneratedFiles();
                jspLoader = null;
                jspCompiler.compile();
                jsw.setReload(true);
                jsw.setCompilationException(null);
            } catch (JasperException ex) {
                // Cache compilation exception
                jsw.setCompilationException(ex);
                throw ex;
            } catch (Exception ex) {
                JasperException je = new JasperException(
 
Localizer.getMessage("jsp.error.unable.compile"),
                            ex);
                // Cache compilation exception
                jsw.setCompilationException(je);
                throw je;
            }
        }
    }

--
Dr Anthony Berglas 
Ph. +61 7 3227 4410
Mob. +61 44 838 8874
ABerglas@RSA.com; Anthony@Berglas.org


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Fix to Tomcat Jasper slow .tag compilation problem.

Posted by Mark Thomas <ma...@apache.org>.
Berglas, Anthony wrote:
> My enthusiasm for addressing these issues is dependent on the community
> being able to incorporate my fixes into the core.  Otherwise I fork
> Tomcat, not a good idea.  
> 
> My feeling is that my fix below will just be ignored.

It might not get looked at straight away. Creating a bugzilla entry
and attaching your patch means it is much less likely to get
overlooked. I haven't checked - some of the issues you highlighted may
already be in bugzilla.

I don't know if the source has changed, but a patch against the latest
code base is usually easier to work with rather than one several
versions old.

Are you intending to address all of the issues you out-lined? If this
is the case, I would rather wait for the complete solution than commit
an interim hack.

Mark

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Fix to Tomcat Jasper slow .tag compilation problem.

Posted by Peng Tuck Kwok <pe...@gmail.com>.
On 10/30/07, Berglas, Anthony <ab...@rsasecurity.com> wrote:
>
> Precompiling would not help.
>
> 1. Precompiling JSPs with .tag files is broken in Jasper, if tags call
> other tags.
>
> 2. If it were fixed I would imagine that it would still recompile each
> tag over and over again.  A precompile of a few dozen jsps would then
> take hours.
>
> The next issue to fix is the very slow one tag at a time Java compiles.
> Then the dependencies can be looked at, but the code is fairly complex.
>
> My enthusiasm for addressing these issues is dependent on the community
> being able to incorporate my fixes into the core.  Otherwise I fork
> Tomcat, not a good idea.
>
> My feeling is that my fix below will just be ignored.
>
> Anthony
>
> > -----Original Message-----
> > From: Peng Tuck Kwok [mailto:pengtuck@gmail.com]
> > Sent: Monday, October 29, 2007 8:17 PM
> > To: Tomcat Users List
> > Subject: Re: Fix to Tomcat Jasper slow .tag compilation problem.
> >
> > Would pre-compiling your jsp files help you instead? AFAIK that works
> on
> > the
> > tags so you probably don't need to touch jspc.
> >
> > On 10/29/07, Berglas, Anthony <ab...@rsasecurity.com> wrote:
> > >
> > > As described in a previous post, Jasper is *extremely* slow at
> compiling
> > > .tag files packaged in a .jar.  Tens of seconds every time you touch
> a
> > > new .jsp for the first time.  Almost unusable if you use .tags
> > > extensively, as I do.
> > >
> > > The following few lines is a hack to fix this.  The added code is
> marked
> > > between // -------- AJB markers.  It effectively turns off the
> timestamp
> > > checking on .jar files.
> > >
> > > This does NOT actually introduce a bug.  There is an existing bug in
> > > that .jsp files are not automatically recompiled if any .tags in
> .jars
> > > are changed.  So you need to purge work in either case.  A proper
> fix
> > > would be to check dependencies properly, at least to the .jar file
> > > itself.  But the current fix is *much* better that the existing
> > > behavior.
> > >
> > > COULD SOMEBODY PLEASE ARRANGE FOR THIS CODE TO BE ADDED TO THE
> CURRENT
> > > SUBVERSION REPOSITORY?
> > >
> > > Outstanding is to make the compilation of .tags themselves much
> faster,
> > > not tens of seconds.  To do that one needs to call the Java compiler
> > > once at the end for all the .tags, rather than once for each
> individual
> > > .tag which is *much* slower.
> > >
> > > I must admit that I got rather lost reading the Jasper source, with
> all
> > > the contexts etc.  Some better comments on the classes describing
> their
> > > relationships to each other would be most helpful.
> > >
> > > Thanks,
> > >
> > > Anthony
> > >
> > >
> > >
> > > // Tomcat 6.0.10 Src deployed version.
> > >
> > > public class JspCompilationContext {...
> > >
> > >     public void compile() throws JasperException,
> FileNotFoundException
> > > {
> > >         createCompiler();
> > >
> > >         // ------------ begin AJB
> > >         // Hack to stop .tag files that are packaged in .jars being
> > > recompiled for every single .jsp that uses them.
> > >         // The hack means that .tag files will not be automatically
> > > recompiled if they change -- you need to delete work area.
> > >         // But that was actually an existing bug -- .jsps are not
> > > dependent on the .tag .jars so the work area needed deleting anyway.
> > >         // (Outstanding is to compile multiple .tags in one pass and
> so
> > > make the process Much faster.)
> > >         boolean outDated;
> > >         if (isPackagedTagFile) outDated = ! new
> > > File(getClassFileName()).exists();
> > >         else outDated = jspCompiler.isOutDated();
> > > //        AjbLog.log("### Compiler.compile " + jspUri + " pkgTagFile
> " +
> > > isPackagedTagFile + " outDated " + outDated + " " +
> getClassFileName());
> > >         if (outDated) {
> > > //     if (isPackagedTagFile || jspCompiler.isOutDated()) {
> > > //     ---------------- end AJB
> > >             try {
> > >                 jspCompiler.removeGeneratedFiles();
> > >                 jspLoader = null;
> > >                 jspCompiler.compile();
> > >                 jsw.setReload(true);
> > >                 jsw.setCompilationException(null);
> > >             } catch (JasperException ex) {
> > >                 // Cache compilation exception
> > >                 jsw.setCompilationException(ex);
> > >                 throw ex;
> > >             } catch (Exception ex) {
> > >                 JasperException je = new JasperException(
> > >
> > > Localizer.getMessage("jsp.error.unable.compile"),
> > >                             ex);
> > >                 // Cache compilation exception
> > >                 jsw.setCompilationException(je);
> > >                 throw je;
> > >             }
> > >         }
> > >     }
> > >
> > > --
> > > Dr Anthony Berglas
> > > Ph. +61 7 3227 4410
> > > Mob. +61 44 838 8874
> > > ABerglas@RSA.com; Anthony@Berglas.org
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To start a new topic, e-mail: users@tomcat.apache.org
> > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > >
> > >
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: Fix to Tomcat Jasper slow .tag compilation problem.

Posted by "Berglas, Anthony" <ab...@rsasecurity.com>.
Precompiling would not help.

1. Precompiling JSPs with .tag files is broken in Jasper, if tags call
other tags.

2. If it were fixed I would imagine that it would still recompile each
tag over and over again.  A precompile of a few dozen jsps would then
take hours.

The next issue to fix is the very slow one tag at a time Java compiles.
Then the dependencies can be looked at, but the code is fairly complex.

My enthusiasm for addressing these issues is dependent on the community
being able to incorporate my fixes into the core.  Otherwise I fork
Tomcat, not a good idea.  

My feeling is that my fix below will just be ignored.

Anthony

> -----Original Message-----
> From: Peng Tuck Kwok [mailto:pengtuck@gmail.com]
> Sent: Monday, October 29, 2007 8:17 PM
> To: Tomcat Users List
> Subject: Re: Fix to Tomcat Jasper slow .tag compilation problem.
> 
> Would pre-compiling your jsp files help you instead? AFAIK that works
on
> the
> tags so you probably don't need to touch jspc.
> 
> On 10/29/07, Berglas, Anthony <ab...@rsasecurity.com> wrote:
> >
> > As described in a previous post, Jasper is *extremely* slow at
compiling
> > .tag files packaged in a .jar.  Tens of seconds every time you touch
a
> > new .jsp for the first time.  Almost unusable if you use .tags
> > extensively, as I do.
> >
> > The following few lines is a hack to fix this.  The added code is
marked
> > between // -------- AJB markers.  It effectively turns off the
timestamp
> > checking on .jar files.
> >
> > This does NOT actually introduce a bug.  There is an existing bug in
> > that .jsp files are not automatically recompiled if any .tags in
.jars
> > are changed.  So you need to purge work in either case.  A proper
fix
> > would be to check dependencies properly, at least to the .jar file
> > itself.  But the current fix is *much* better that the existing
> > behavior.
> >
> > COULD SOMEBODY PLEASE ARRANGE FOR THIS CODE TO BE ADDED TO THE
CURRENT
> > SUBVERSION REPOSITORY?
> >
> > Outstanding is to make the compilation of .tags themselves much
faster,
> > not tens of seconds.  To do that one needs to call the Java compiler
> > once at the end for all the .tags, rather than once for each
individual
> > .tag which is *much* slower.
> >
> > I must admit that I got rather lost reading the Jasper source, with
all
> > the contexts etc.  Some better comments on the classes describing
their
> > relationships to each other would be most helpful.
> >
> > Thanks,
> >
> > Anthony
> >
> >
> >
> > // Tomcat 6.0.10 Src deployed version.
> >
> > public class JspCompilationContext {...
> >
> >     public void compile() throws JasperException,
FileNotFoundException
> > {
> >         createCompiler();
> >
> >         // ------------ begin AJB
> >         // Hack to stop .tag files that are packaged in .jars being
> > recompiled for every single .jsp that uses them.
> >         // The hack means that .tag files will not be automatically
> > recompiled if they change -- you need to delete work area.
> >         // But that was actually an existing bug -- .jsps are not
> > dependent on the .tag .jars so the work area needed deleting anyway.
> >         // (Outstanding is to compile multiple .tags in one pass and
so
> > make the process Much faster.)
> >         boolean outDated;
> >         if (isPackagedTagFile) outDated = ! new
> > File(getClassFileName()).exists();
> >         else outDated = jspCompiler.isOutDated();
> > //        AjbLog.log("### Compiler.compile " + jspUri + " pkgTagFile
" +
> > isPackagedTagFile + " outDated " + outDated + " " +
getClassFileName());
> >         if (outDated) {
> > //     if (isPackagedTagFile || jspCompiler.isOutDated()) {
> > //     ---------------- end AJB
> >             try {
> >                 jspCompiler.removeGeneratedFiles();
> >                 jspLoader = null;
> >                 jspCompiler.compile();
> >                 jsw.setReload(true);
> >                 jsw.setCompilationException(null);
> >             } catch (JasperException ex) {
> >                 // Cache compilation exception
> >                 jsw.setCompilationException(ex);
> >                 throw ex;
> >             } catch (Exception ex) {
> >                 JasperException je = new JasperException(
> >
> > Localizer.getMessage("jsp.error.unable.compile"),
> >                             ex);
> >                 // Cache compilation exception
> >                 jsw.setCompilationException(je);
> >                 throw je;
> >             }
> >         }
> >     }
> >
> > --
> > Dr Anthony Berglas
> > Ph. +61 7 3227 4410
> > Mob. +61 44 838 8874
> > ABerglas@RSA.com; Anthony@Berglas.org
> >
> >
> >
---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Fix to Tomcat Jasper slow .tag compilation problem.

Posted by Peng Tuck Kwok <pe...@gmail.com>.
Would pre-compiling your jsp files help you instead? AFAIK that works on the
tags so you probably don't need to touch jspc.

On 10/29/07, Berglas, Anthony <ab...@rsasecurity.com> wrote:
>
> As described in a previous post, Jasper is *extremely* slow at compiling
> .tag files packaged in a .jar.  Tens of seconds every time you touch a
> new .jsp for the first time.  Almost unusable if you use .tags
> extensively, as I do.
>
> The following few lines is a hack to fix this.  The added code is marked
> between // -------- AJB markers.  It effectively turns off the timestamp
> checking on .jar files.
>
> This does NOT actually introduce a bug.  There is an existing bug in
> that .jsp files are not automatically recompiled if any .tags in .jars
> are changed.  So you need to purge work in either case.  A proper fix
> would be to check dependencies properly, at least to the .jar file
> itself.  But the current fix is *much* better that the existing
> behavior.
>
> COULD SOMEBODY PLEASE ARRANGE FOR THIS CODE TO BE ADDED TO THE CURRENT
> SUBVERSION REPOSITORY?
>
> Outstanding is to make the compilation of .tags themselves much faster,
> not tens of seconds.  To do that one needs to call the Java compiler
> once at the end for all the .tags, rather than once for each individual
> .tag which is *much* slower.
>
> I must admit that I got rather lost reading the Jasper source, with all
> the contexts etc.  Some better comments on the classes describing their
> relationships to each other would be most helpful.
>
> Thanks,
>
> Anthony
>
>
>
> // Tomcat 6.0.10 Src deployed version.
>
> public class JspCompilationContext {...
>
>     public void compile() throws JasperException, FileNotFoundException
> {
>         createCompiler();
>
>         // ------------ begin AJB
>         // Hack to stop .tag files that are packaged in .jars being
> recompiled for every single .jsp that uses them.
>         // The hack means that .tag files will not be automatically
> recompiled if they change -- you need to delete work area.
>         // But that was actually an existing bug -- .jsps are not
> dependent on the .tag .jars so the work area needed deleting anyway.
>         // (Outstanding is to compile multiple .tags in one pass and so
> make the process Much faster.)
>         boolean outDated;
>         if (isPackagedTagFile) outDated = ! new
> File(getClassFileName()).exists();
>         else outDated = jspCompiler.isOutDated();
> //        AjbLog.log("### Compiler.compile " + jspUri + " pkgTagFile " +
> isPackagedTagFile + " outDated " + outDated + " " + getClassFileName());
>         if (outDated) {
> //     if (isPackagedTagFile || jspCompiler.isOutDated()) {
> //     ---------------- end AJB
>             try {
>                 jspCompiler.removeGeneratedFiles();
>                 jspLoader = null;
>                 jspCompiler.compile();
>                 jsw.setReload(true);
>                 jsw.setCompilationException(null);
>             } catch (JasperException ex) {
>                 // Cache compilation exception
>                 jsw.setCompilationException(ex);
>                 throw ex;
>             } catch (Exception ex) {
>                 JasperException je = new JasperException(
>
> Localizer.getMessage("jsp.error.unable.compile"),
>                             ex);
>                 // Cache compilation exception
>                 jsw.setCompilationException(je);
>                 throw je;
>             }
>         }
>     }
>
> --
> Dr Anthony Berglas
> Ph. +61 7 3227 4410
> Mob. +61 44 838 8874
> ABerglas@RSA.com; Anthony@Berglas.org
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>