Google Datastore NoSQL persistence service
Use a data persistence service with a NoSQL data model
Develop and deploy a custom web application on a PaaS infrastructure
Conduct performance tests and observe the auto-scaling mechanisms of the platform
Assess how quickly resources (quotas) are used up
Before working on the tasks of this exercise create a Google account and set up a development environment as described in Task 1.
Task 1 Preparing a Google App Engine development environment
Set up a Google account
You can either use an existing Google account (if you are using one of Google's services such as GMail you already have an account) or you may decide to create a separate account. We recommend to use separate accounts for private and study-related activities.
In your browser navigate to https://console.cloud.google.com/projectselector/appengine/create.
If you want to use an existing account, sign in, otherwise click on More options > Create account and follow the instructions.
When the setup is completed you should see the message App Engine Dashboard - To view this page, select a project.
Set up the development environment on your machine
You can choose between downloading a virtual machine image with the development environment already set up (Ubuntu 16.04 LTS desktop) or you can choose to install the required software on your machine, which is described in the following.
If you use the VM, log in with user id
labuser and password
gae8. Then run the following commands in a terminal to authenticate
with your Google account:
gcloud init gcloud auth application-default login
If you don't want to use the VM, the setup of the development environment consists of the steps detailed below. If you run into trouble, please consult the Google App Engine Java 8 Quickstart.
Make sure your computer has Java SE Development Kit (JDK) 8 installed.
Download and install git.
Download and install the Google Cloud SDK.
After you download and install invoke the following commands:
gcloud init gcloud auth application-default login
Install the Cloud SDK
gcloud components install app-engine-java
You must have Maven 3.5 installed. Determine whether Maven 3.5 is installed by invoking the following command:
If you don't have the proper version of Maven installed:
Download and install Eclipse IDE for Java EE Developers version 4.7.x/Oxygen that you will find on the Eclipse packages download page.
Install the Cloud Tools for Eclipse plug-in: Start Eclipse and select Help > Eclipse Marketplace.... Search for Google Cloud. Select Google Cloud Tools for Eclipse and install.
Task 2 Deployment of a simple web application
In this task you will create a simple web application. You will first test it on your local machine using a web application server included in the SDK, then you will deploy it on Google App Engine.
Create a simple web application as follows.
Start Eclipse. Sign in to your Google account: Click the Google Cloud Platform toolbar button (a hexagon in Google colors) and select Sign in to Google....
Create a new project: click the Google Cloud Platform toolbar button and select Create New Project > Google App Engine Standard Java Project.
Give the project a Project name of LabGAE and a Package of ch.hesso.mse.labgae. Leave the other parameters at their default values.
The wizard creates a complete project with a directory structure and a number of files.
Inspect the Servlet the wizard has created: Open the
srcfolder that contains the Java source code and navigate to
main/java/ch/hesso/mse/labgae. Open the
HelloAppEngine.javafile in that folder. What does the code do?
Note the annotation starting with
@WebServletin front of the Servlet. It maps the route
helloto the Servlet. Normally these mappings are defined in the deployment descriptor of the web app (the deployment descriptor is the file
webapp/WEB-INF). The mappings are needed by the web application server to route the incoming HTTP requests to the right Servlets.
Inspect the Google App Engine configuration file
webapp/WEB-INF. What information does it contain?
Test the web application on your local machine using an application server embedded in the Google Cloud SDK as follows:
Run the project locally: Select the project you created and bring up the context menu. Select Run As > App Engine. In the center window Eclipse's built-in web browser should launch on http://localhost:8080/ and show a page titled Hello App Engine!. Click on the available Servlet. You should see the message Hello App Engine!.
Observe the lower pane of the Eclipse window: the Servers view should open. It shows the local web application server executing. You can stop the server by selecting it and clicking the red stop button. Also inspect the Console view. In this view appear log messages of the web application server. If everyting went OK the message INFO: Dev App Server is now running is displayed.
When you have finished testing, click the red square in the Servers view or Console view to stop the server.
Deploy the web application on Google App Engine as follows:
Log into the Cloud Platform console: https://console.cloud.google.com/projectselector/appengine/create. Create a new Cloud Platform project.
Create a name for your project (for example mse-tclcomp-yourlastname). Enter this name into the field Project Name. Google will create a globally unique project identifier based on that name. Write it down as you will need it later.
You will be prompted to select the region where you want your App Engine application located. Select a region close to you.
After you created the project navigate to the App Engine Dashboard and make sure the project is selected in the drop-down menu in the blue bar at the top.
Deploy the web application in the cloud:
In Eclipse select the project's top folder. Bring up the context menu and select Deploy to App Engine Standard .... A wizard appears asking you to select a Cloud Platform project. Select the one you just created and click Deploy.
Observe the messages of the deployment process in the Console view. You should see Eclipse's internal web browser coming up, displaying the deployed application (Hello App Engine!). Click on the Servlet to verify that it works.
Test the web application on App Engine:
In your browser open http://projectid.appspot.com/ where you replace projectid with the project identifier you created earlier. You should see the application running on App Engine.
In the Cloud Platform console navigate to the App Engine dashboard. Reload the Servlet a few times in your browser. After some time you should see your requests appear in the dashboard graph.
Task 3: Develop a Servlet that uses the Datastore
In this task you will write a test Servlet that writes data to the Datastore. You will use it later to test the write performance of the Datastore.
The Servlet shall work as follows:
The Servlet will be called DatastoreWrite and will respond to HTTP requests that are sent to the URI path /datastorewrite.
For each HTTP request it receives, the Servlet shall write an entity to the datastore.
The Servlet will receive the data for the entity in the query part of the URI of the HTTP request.
The query part of a URI starts after the question mark '?' and continues until the end. It contains a number of field-value pairs of the form
Example: To add a new entity describing a book to the datastore one would send the following URI in the HTTP request:
The Servlet should be able to deal with arbitrary field-value pairs. Each field-value pair shall become a property of the entity. The field name becomes the property name and the field value the property value.
The Servlet should treat the fields named _kind and ___key__ specially. The field ___kind__ shall indicate the kind of the entity. It is mandatory. The field ___key__ shall contain the key name of the entity. It is optional. If not present, the Servlet shall let the Datastore generate the key.
Example: When the Servlet is invoked with the URI given above, it should write an entity of kind book with key name 837094 and the properties author: John Steinbeck and title: The Grapes of Wrath to the datastore.
Hints for writing the Servlet:
We provide a sample Servlet that shows how to use the Datastore API to write an entity, DatastoreWriteSimple.java, which can be found on the same parent page that led you to this document.
The Datastore API documentation can be found at https://cloud.google.com/appengine/docs/standard/java/datastore/entities.
The Javadoc of the Servlet API can be found at http://docs.oracle.com/javaee/7/api/ (Oracle hasn't published the Javadoc of version 8 yet, but version 7 remains valid). The Servlet API is in the packages javax.servlet.*.
Recommendation: To make JavaDoc easier to search use the JavaDoc Search Frame extension for Chrome or Firefox.
To access the data in the query part of the URI use the methods
To develop and test the Servlet perform the following steps:
Create a new Servlet and write its code.
Test the Servlet on your local machine as described in the previous task. The test web application server contains a local datastore that will receive the data. To examine the data in the datastore open the local console at http://localhost:8888/_ah/admin/.
After you have tested it successfully deploy the Servlet to App Engine.
Test the Servlet on App Engine. To examine the data in the datastore open the Cloud Platform console, open the hamburger menu and select Datastore > Entities.
Copy the Servlet into the report.
Copy a screenshot of the local and the App Engine console with the Datastore Viewer.
Task 4: Test the performance of Datastore writes
In this task you will performance test the App Engine platform with a load generator. You will compare the performance of normal request processing and request processing that involves Datastore write operations.
Download and install on your local machine JMeter from http://jmeter.apache.org/.
First test the performance of normal request processing using the Servlet generated by the wizard.
Open JMeter and create a new test plan as described in this Fred Puls blog post: JMeter quick start. In the HTTP Request sampler set the Server name or IP to the domain name of your application. Leave the Path empty to invoke the Servlet generated by the wizard.
In the App Engine console open the Dashboard.
Run a test.
In the dashboard observe the graph of the incoming requests, the number of instances and the latency.
Test the performance of the Servlet that writes to the Datastore.
In the HTTP Request sampler specify a Path that will invoke the Servlet and make it write an entity to the Datastore. To avoid writing always the same entity do not specify the key name so that the Datastore generates a new ID each time.
Repeat the test.
At the end of the tests observe in detail how much resources were used. In the console click on Quota Details.
For each performance test copy a screenshot of the JMeter Graph Results listener and the App Engine Dashboard view into the report.
What response times do you observe in the test tool for each Servlet?
Compare the response times shown by the test tool and the App Engine console. Explain the difference.
How much resources have you used running these tests? From the Quota Details view of the console determine the non-zero resource quotas (Daily quota different from 0%). Explain each with a sentence. To get a sense of everything that is measured click on Show resources not in use.
Let's suppose you become suspicious that the automatic scaling of instances is not working correctly. How would you use the App Engine console to verify? Give an example of how the automatic scaling could fail. Which measures shown in the console would you use to detect this failure?