The good news for people suffering with this issue (and that is all App Engine developers I would say) is that the GAE team has accepted the issue and introduced it into their roadmap - "Ability to reserve instances to reduce application loading overhead". Personally I really won't mind paying for my own JVM instance if it's not too expensive, and I would guess that this is probably the direction the GAE team will go.
My "quick-fix" (or hack) for this issue at least until the GAE team sorts it out, is to ping your app every few minutes to keep the JVM "warm". Here I've created a blank servlet that gets called by the AE background cron.xml tasks every few minutes...
web.xml:
... <servlet> <display-name>BlankServlet</display-name> <servlet-name>BlankServlet</servlet-name> <servlet-class>my.package.BlankServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>BlankServlet</servlet-name> <url-pattern>/blank.html</url-pattern> </servlet-mapping> ...
BlankServlet.java:
public class BlankServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { // Nothing needed here. } }
cron.xml:
<?xml version="1.0" encoding="UTF-8"?> <cronentries> <cron> <url>/blank.html</url> <description>Ping a blank page to keep the JVM warm</description> <schedule>every 5 minutes</schedule> </cron> </cronentries>You could of course ping your main welcome page instead but you might have some code in your pages that you might not want to be executed by an automatic process - maybe your Google Analytics javascript for example.