Wednesday, October 21, 2009

JVM Coldstart on Google App Engine

When your application sitting on app engine has been idling for a while, app engine tends to shutdown the jvm instance containing your app, presumably to conserve limited resources.

I find that a problem because getting the application initially started up can be a slow and expensive process.

But the problem can be solved with cron jobs that call a url in your application at set intervals, thereby keeping your jvm all nice and warmed up.

Check out the documentation on the site.

All you've got to do is:
create cron.xml and place it in your WEB-INF folder


<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/recache</url>
<description>Repopulate the cache every 2  minutes</description>

<schedule>every 2 minutes</schedule>
</cron>
<cron>
<url>/weeklyreport</url>
<description>Mail out a weekly report</description>
<schedule>every monday 08:30</schedule>
<timezone>America/New_York</timezone>
</cron>
</cronentries>

2 comments:

  1. Do you have any idea what is the time lapse for a jvm to shutdown ?

    ReplyDelete
  2. used to be about a minute, but even after setting a cron job to keep it alive it still shuts down

    ReplyDelete