1 August 2011

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.

 
Install the SDK and after a restart of Eclipse we are ready to create a Web Application with the necessary App Engine Libraries using the New Web Application Project… menu as below.




This bring up the deploy dialogue as below where I selected the App Engine project settings…

This brings up the settings dialogue as below where I pondered where to get an Application ID from. 


I clicked the My applications… link and had to sign in and verify my account by SMS then this took me to the Google App Engine start page as below where I created the application and gave it a name c2b2autoscale.

I clicked the My applications… link and had to sign in and verify my account by SMS then this took me to the Google App Engine start page as below where I created the application and gave it a name c2b2autoscale.


I returned to the App Engine dialogue and filled in the application ID and on returning to the deploy dialogue I could select deploy from Eclipse and see the console output as below:

Created staging directory at: 'C:\Users\c2b2\AppData\Local\Temp\appcfg4909847011665884737.tmp'
Scanning for jsp files.
Scanning files on local disk.
Initiating update.
Cloning 2 static files.
Cloning 33 application files.
Uploading 2 files.
Uploaded 1 files.
Uploaded 2 files.
Initializing precompilation...
Deploying new version.
Will check again in 1 seconds.
Will check again in 2 seconds.
Closing update: new version is ready to start serving.
Uploading index definitions.
Deployment completed successfully

I returned to the My Applications page as below.


Then selecting the application link I got to the dashboard as below.

So it was time to exercise the application which I could from a URL such as http://c2b2autoscale.appspot.com/rest/WSInvoker?processType=slowProcess&amount=1 which would give me a response as below.

 

In the next posting I’ll explore what URLs are available and how I put some load on the service to test the scaling.

Pete Raymond

If you enjoyed this post, why not subscribe to our feed?


Enter your email address:



No comments :

Post a Comment