Auto scaling with Google App Engine Part 1

This post provides a quick run through of using Google App Engine to host a simple REST application developed with Jersey (http://jersey.java.net/). I read the tutorial (http://www.vogella.de/articles/REST/article.html) to get going but decided to use Google App Engine for hosting as I’m interested in cloud auto scaling features.

My test application allows me to either request a method waits by using Thread.sleep() or consumes CPU by looping through the creation of a String. The length of time the application will wait and the number of thousand times a String will be created in the highCpu scenario is specified by the amount. The application exposes a REST interface which takes two parameters as below:
 
 
// This method is called if the request is HTML
       @GET
       @Produces(MediaType.TEXT_HTML)
       public String doProcess(
                     @QueryParam("processType") String processType,
                     @QueryParam("amount") int amount

              ) {

The process type can either be called slowProcess or highCpu and gets used as below.

       public void consumeCpu(int amount){
              for (int i = 0; i < amount * 1000; i++){
                     String s = new String("");
              }
       }
      
       public void timedMethod(int delay){
              log.debug("about to sleep thread for " + delay + "ms");
              try {
                     Thread.sleep(delay);
              } catch (InterruptedException e) {
                     log.error( e);
              }

       }

 

Enough of the code how do you get it running on Google’s servers? First you must use Google’s SDK which is available as an Eclipse plugin as described in http://code.google.com/appengine/docs/java/tools/eclipse.html. That article refers to using up to Eclipse 3.6 Helios however a bit more searching takes you to http://code.google.com/eclipse/docs/download.html which provides the download details for the 3.7 Indigo release I’m using. In Eclipse using Help -> Install New Software… You add the http://dl.google.com/eclipse/plugin/3.7 to the Work With field as below.