Exercise 4. XMLResource Save and Load Options

What This Exercise Is About

Using the generated code for the PurchaseOrder model, you will experiment how the serialization and deserialization performance is affected by the XMLResource save and load options.

For your reference, here again is the UML class diagram describing the purchase order model:

Extended PO model


What You Should Be Able To Do

At the end of the lab, you should be able to:

Required Materials

General Advice / Warnings

Exercise Instructions

This exercise is carried out entirely using the Eclipse Software Development Kit (SDK) version 3.2 with the Eclipse Modeling Framework (EMF) 2.2 installed into it. The exercise instructions refer to this product as either Eclipse or as "the workbench".

These instructions are located in the exercises/Exercise4_Save_Load_Options folder. If you browse into this location by expanding the folders, you should find one additional folder: org.eclipse.emf.tutorial.advanced.po. This is an Eclipse project that you will import into your workspace to complete this exercise.

You will need to use the class SaveLoadOptionsTest to perform this exercise. The purpose of this class is to provide a test that can be easily customized in order to measure the effects of the XMLResource save and load options. Basically, when executed, this class:

  1. Measures the time spent saving XMLResources
    1. Creates a resource in memory with a small number of instances of the PurchaseOrder model
    2. Saves the resource to an output stream multiple times, printing out the average of each save
    3. Repeats the steps above for a resource with more instances of the model.
  2. Measures the time spent loading XMLResources
    1. Creates a resource in memory with a small number of instances of the PurchaseOrder model
    2. Creates an input stream from the output stream created when the resource is saved
    3. Loads the resource from the input stream multiple times, printing out the average of each load
    4. Repeats the steps above for a resource with more instances of the model.

Directions

Step A: Verify workbench configuration

  1. See Exercise 1, Step A.

Step B: Import the project into the workspace

  1. See Exercise 1, Step B.

Step C: Analyze the SaveLoadOptionsTest class

  1. Open the SaveLoadOptionsTest located in the org.eclipse.emf.tutorial.advanced.test package. A very handy way of doing this is to use the Java's perspective Ctrl+Shift+T shortcut, that can be used to open any Java type.
  2. Analyze the code paying special attention to:
    1. The saveModel and loadModel methods that you will change in order to exercise the different XMLResource options.
    2. The TEST_SAVE and TEST_LOAD constants that enable the different tests performed by this class.
    3. The NUMBER_OF_REPETITIONS constant that specifies how many times a resource is saved or loaded during one execution of the test.

Step D: Execute the SaveLoadOptionsTest class

  1. Select Run... from the Run toolbar drop-down or menu.
  2. Expand Java Application, select SaveLoadOptionsTest and click the Run.
  3. The test should run for a few minutes and output the save and load measurements. You should write down the numbers produced. They represent the time spent in each operation when only the default options are used.

Step E: Measure the effects of the different save and load options

  1. Uncomment the options available in the saveModel and loadModel methods and run the tests for various combinations of options.
  2. Write down the results and compare with the previous results.

One important remark to be made is that this is a very simplistic way of measuring the performance impacts of changing the save and load options. If the impact is not significant, the numbers will only be different if the amount of repetitions is much larger than the initial value proposed. In this case we would also need to consider the influence of the garbage collection and other Java intrinsic issues. A more robust approach would be to use a specialized tool to do the measurements.


Summary

You experimented with the XMLResource save and load options, measuring how they can affect the performance of an application.