Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does JSP compilation take so long?  RSS feed

 
Darryl A. J. Staflund
Ranch Hand
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Can anyone explain the reason why JSPs take so long to compile. I have an EJB application consisting of about 300+ files that takes no longer than a minute to compile. If I use '<load-on-starup />' to force compilation of the JSPs when Tomcat first starts, an additional 5-10 minutes is needed to compile the 51 JSP files that make up my app.
What is it about JSPs that take them so long to compile?
Darryl
 
Kok Choon Ling
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It takes time to parse the jsp, generate servlet (*.java) file in your work folder, then finaly compile the servlet (*.java). I think most of the time is used on convert jsp to servlet.
 
Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I think when you have a website that has 300 or more jsp/servlets files it is better not to load them all at startup. Choose just those that take the longest time to execute and load them only but do not load all 300 or even more.
You can also use <load-on-startup>1</load-on-startup> and <load-on-startup>2</load-on-startup> to load files in sequence.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How large are those JSP files?
Are they full of Java code that might be moved to JavaBeans or taglibs?
Bill
 
Darryl A. J. Staflund
Ranch Hand
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
The JSP files are pretty small actually as they consist of JSP segments that are put together within a larger Tiles definition (NB: I am using Struts for development.) The average JSP is no more than 30 lines long -- comments included.
I will certainly use selective compilation if the problem becomes burdensome. For the moment, I am just curious as to why it takes a long time to compile a JSP -- especially in comparison to the speed of Java class compilation.
Oh! And apart from the JSP files (51 of them), my site only consists of 1 servlet -- the Struts controller. All other classes (the value objects, EJB code, etc.) have the same load time as before. For example, my app has about 30 EJBs -- a mix of entity, session, and message-driven beans -- and these take no more than 3-5 seconds total to load.
Darryl
[ July 04, 2003: Message edited by: Darryl A. J. Staflund ]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I have an EJB application consisting of about
> 300+ files that takes no longer than a minute
> to compile

So your ANT task (or whatever) re-compiles *all* 300 files in a minute, and not just those that have changed ? Just curious about that one.

>For example, my app has about 30 EJBs -- a mix
> of entity, session, and message-driven beans --
> and these take no more than 3-5 seconds total
> to load.

Well, loading is different than compiling.

As for the JSP compiler... a common complaint with Jasper (the Tomcat JSP compiler) is that it is VERY slow. Each container has it's own and I've never heard of anyone attempting to use a jsp compiler from one container, in another. It's probably not a built-in configurable option. On the other hand, you can "precompile" your JSPs, in which case you can from the command line, use any jsp compiler you want (that you can legally obtain). I know that resin, weblogic and pramati all have their own jsp compilers, and they all have pre-compile ANT tasks.

The JSP compiler gets you to the *.java file. Then the Sun compiler takes over. There is also an alternate to this compiler (jikes, for example).

So it's slow because it's a two step process, and maybe your container's JSP compiler wasn't built for speed, since its used once in the lifetime of the webapp.
 
Darryl A. J. Staflund
Ranch Hand
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> So your ANT task (or whatever) re-compiles
> *all* 300 files in a minute, and not just those
> that have changed ? Just curious about that one.
That is correct. The first thing I do in my Ant code is delete the existing classfiles. The build then continues with a compilation of the source files, generation of the java docs, creation of the jars / ears / wars, and ultimate deployment of the application.

> As for the JSP compiler... a common complaint
> with Jasper (the Tomcat JSP compiler) is that
> it is VERY slow.
Tell me about it :-)

> On the other hand, you can "precompile" your
> JSPs, in which case you can from the command
> line, use any jsp compiler you want (that you
> can legally obtain).
I tried precompiling it by hand using Tomcat's jspc command and performance was slow but better than what I am encountering using the '<load-on-startup />'. I tend to stay away from using the command line, though, because I can't cleanly integrate JSPC into my Ant script (the Ant jspc task is pretty flaky) and I don't really want to go outside the Ant script to run external batch files, etc. Maybe I should reconsider, though this doesn't feel like a good move to me.
> I know that resin, weblogic and pramati all
> have their own jsp compilers, and they all have
> pre-compile ANT tasks.
I am using JBoss 3.2.1 with Tomcat 4.1.24 (?). So we are using Tomcat's JSPC compiler and associated Ant task.

> The JSP compiler gets you to the *.java file.
> Then the Sun compiler takes over. There is also
> an alternate to this compiler (jikes, for
> example).
Oh! And we are using Jikes from within Ant. I don't think Jikes is being used by JSPC however. Do you know if this would bring a been performance increase with it?

> So it's slow because it's a two step process,
> and maybe your container's JSP compiler wasn't
> built for speed, since its used once in the
> lifetime of the webapp.
I have always been annoyed with the speed of JSP precompilation. It is the one factor that kept me away from JSP development for a long time. I guess this is just a personal opinion but I cannot, for the life of me, understand, why JSP's have to compile so slowly. I know I can precompile them, compile them at startup, set switches to work with cached classes if they haven't been modified, etc. But I still think that web-based Java apps are 'slow'. I guess my past experience working with technologies like Perl, ColdFusion (including Java-based MX), and ASP.NET suggest to me that something in the way of performance can be improved here.
Oh well. I'll stop grumbling :-) Java is pretty nice too in other ways.
Darryl
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could this be a memory / disk thrashing problem? Thats the only thing I can think of that causes that kind of delay.
How does one control the amount of memory the compiler gets for JSP anyway???
Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!