views:

128

answers:

1

Here is my test: I access a servlet to get the JVM to load (absorb the loading request). Then i access a JSP that has <%= 5+7 %> in it and nothing else. The first access to this JSP uses 350ms of CPU time and has latency of 200ms. Subsequent accesses only have latency and cpu time of about 20ms.

Why does the first access to the jsp after starting the servlet container take longer?

EDIT: Note that Google App Engine supposedly precompiles the jsps. I can see in the console output when I upload my app Initializing precompilation....

EDIT: It is the first access to any JSP, then subsequent accesses, even if its to a different JSP don't take long. It's as if the JSP system has some loading to do or something.

Also, this is not a loading request, I access a servlet first before accessing the JSP to absorb the loading request. Also, no loading requests ever use less than 500ms of CPU time.

+2  A: 

JSP get compiled to a class extending HttpServlet on first access/request. Some servletcontainers will compile it directly during startup (or are configureable to) so that you won't notice the "lag". Others doesn't support it and you then need to precompile the JSP files yourself and deploy your WAR with it.

I've never used it, so I can't answer from top of head, but a quick glance in its Java FAQ learns me that you can enable precompilation on startup by adding the following entry to appengine-web.xml file:

<precompilation-enabled>true</precompilation-enabled>

Update: as per the Performance section of the appengine documentation, it appears to spin up (and off) JVM's on demand, which may cause "loading requests". Here's an extract of the documentation:

What is a loading request?

Some requests run slower because App Engine needs to create a new Java virtual machine to service the request. We call that kind of request, a Loading Request. During a loading request, your application undergoes initialization (such as class loading, JIT compiling, etc) which causes the request to take longer.

For slow requests which are already close to App Engine's request deadline, the extra initialization can push it past the deadline, causing a DeadlineExceededException. What causes loading requests?

App Engine spins up JVMs on demand, so there are several reasons why you may receive a loading request:

  1. You just uploaded a new version of your application.
  2. Your application may not be getting any traffic.
  3. Your traffic has become high enough to need another JVM to scale.

You can expect that during the course of developing your application, you will often experience the first two scenarios. In comparison, for a production app receiving even a very small but steady amount of traffic, loading requests are relatively infrequent.

In other words, this is not solveable in any programmatic way. Either just live with it or consider a dedicated server with a fullworthy servletcontainer.

BalusC
Thanks Balus, I already had precompilation enabled to true though.
Kyle
Right, the loading request is significant, and in my test I absorb the loading request before accessing the JSP. Also note that it is only the first access to any JSP.
Kyle