back to index     prev     next  

2. Your first Benchmark

This section describes how to write and execute a simple Benchmark.

Description

For this example, we choose to measure the time of an object creation with ProActive.newActive(). This benchmark aims to perform object creation on the same JVM, on an other local JVM and on a remote JVM.

First step : write the Benchmark

Create new class who extends testsuite.test.ProActiveBenchmark, it is an abstract class.

See this template code :


import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.core.node.Node;

import testsuite.test.ProActiveBenchmark;

public class BenchNewActive extends ProActiveBenchmark {

    public BenchNewActive() {
        super(null, "Object Creation with newActive",
            "Measure time to create an active object with newActive.");
    }

    public BenchNewActive(Node node) {
        super(node, "Object Creation with newActive",
            "Measure time to create an active object with newActive.");
    }

    public long action() throws Exception {
    }

    public void initTest() throws Exception {
    }

    public void endTest() throws Exception {
    }
}

We also override two methods from the super-class : testsuite.test.Benchmark, to check if post and pre-conditions are verified :


   public boolean postConditions() throws Exception {
   }

   public boolean preConditions() throws Exception {
   }

Implementing initTest() and endTest()

In this exampple both methods are empty, but they could be overridden in order to initialize and finalyze the benchmark.

Implementing preConditions()

We will simply verify if the node is created :


   public boolean preConditions() throws Exception {
     return getNode() != null;
   }

Implementing action()

This method measures the time of a creation of an Object with ProActive.newActive() on a specified node :


    private ReifiableObject object = null;

    public long action() throws Exception {
        ReifiableObject object;
        String className = ReifiableObject.class.getName();
        Node node = getNode();
        this.timer.start();
        object = (ReifiableObject) ProActive.newActive(className, null, node);
        this.timer.stop();
        return this.timer.getCumulatedTime();
    }

Remark :It is the benchmark's programmer who measure the time of the action with a configurable timer, see the timer part for more details.

Remark : The ReifiableObject class is a simple class who just extends java.lang.Object, implements java.io.Serilizable and has an empty constructor with no argument.

Implementing postConditions()

We will check if object is different of null and if the node contains object :


   public boolean postConditions() throws Exception {
     Object[] activeObjects = getNode().getActiveObjects();
     return (object != null) && (activeObjects != null) &&
       (activeObjects.length == 1) && activeObjects[0].equals(object);
   }

Tips : if you want to make a trace in your benchmark , you have access to a log4j logger by : getLogger() or by the variable logger

Second step : write a manager

Now, we will write a Manager to execute ou test.

For this example it is very simple, you have just to extends testsuite.manager.ProActiveBenchManager :


import testsuite.manager.ProActiveBenchManager;

public class Manager extends ProActiveBenchManager {

	public Manager() {
          super("Manager","To manage ProActive Benchmarks.");
	}
}

Override initManager() and endManager()

Normaly, you have nothing to do to initialize the manager. In this example, we choose to create benchmarks and group in this method , but you can do this in the same place where you create the manager.

Create group by initManager() :


import testsuite.group.Group;

  public void initManager() throwsException {
    Group benchGroup = new Group("Bnechmark Group","no description.");

    // adding bench in same VM
    benchGroup.add(new BenchNewActive(getSameVMNode()));
    // adding bench in local VM
    benchGroup.add(new BenchNewActive(getLocalVMNode()));
    // adding bench in remote VM
    benchGroup.add(new BenchNewActive(getRemoteVMNode()));

    // adding the group
    add(benchGroup);
  }

Create group int the same place of the manager :


  // ...
  Manager manager  = new Manager();

  Group  benchGroup = new Group("Bnechmark Group","no description.");

  // adding bench in same VM
  benchGroup.add(new BenchNewActive(getSameVMNode()));
  // adding bench in local VM
  benchGroup.add(new BenchNewActive(getLocalVMNode()));
  // adding bench in remote VM
  benchGroup.add(new BenchNewActive(getRemoteVMNode()));

  manager.add(benchGroup);
  // ...

Warning : if you override endManager() method in a ProActiveManager you must to add in this code :


super.endManager()

The reason is to delete the ProActive nodes create at the beginning.

The attribute file

Our manager is a ProActiveManager, so an attibutes file is mandatory.

Create a file Manager.prop in the same directory of the manager. This file must contains the name (or URL) of the remote host, like this :


RemoteHostname=owenii

Warning : respect the upper an lower cases.

Tips : you can use this file to specify attributes for your tests classes. You can also use a different file, in this case you must specify its path in the execute() method of the manager.

Now launch the benchmark ...

Add this code in your main method :


Manager manager = new Manager();
// the argument must have true value, because it is a ProActiveManager
// and the attributes file is obligatory
manager.execute(true);

Warning : when you use a ProActiveManager you must to had System.exit(0) at the end of the main method. If don't do that, the manager can't properly.

Get the results

Results in your console :


System.out.println(manager);

If you want all details :


manager.setVerbatim(true);

For benchmarks it is more interesting to export results in a HTML file. Indeed, you have average, min, max, STDEV and charts to help you to analyse all results

Example of HTML results

Object Creation

Object Creation with newActive and turnActive.

Messages of Object Creation :

9/18/2003 at 13:0:32.527 [RESULT] Object Creation with newActive -- Same VM : no message [SUCCESS] See the chart Max=113ms Moy=24.0ms STDEV=24.64ms --> Min 1ms

9/18/2003 at 13:0:36.693 [RESULT] Object Creation with turnActive -- Same VM : no message [SUCCESS] See the chart Max=98ms Moy=41.0ms STDEV=32.20ms --> Min 1ms

9/18/2003 at 13:0:43.425 [RESULT] Object Creation with newActive -- Local VM : no message [SUCCESS] See the chart Max=376ms Moy=67.03ms STDEV=83.73ms --> Min 6ms

9/18/2003 at 13:0:50.434 [RESULT] Object Creation with turnActive -- Local VM : no message [SUCCESS] See the chart Max=326ms Moy=69.82ms STDEV=86.15ms --> Min 6ms

9/18/2003 at 13:0:53.297 [RESULT] Object Creation with newActive -- Remote VM : no message [SUCCESS] See the chart Max=290ms Moy=28.03ms STDEV=50.79ms --> Min 5ms

9/18/2003 at 13:0:55.980 [RESULT] Object Creation with turnActive -- Remote VM : no message [SUCCESS] See the chart Max=250ms Moy=26.32ms STDEV=53.46ms --> Min 5ms

9/18/2003 at 13:0:55.982 [RESULT] : Group : Object Creation, Moy in 42.7ms Runs : 600 Errors : 0

To see all results of this group in a BarChart.

All the Code

BenchnewActive.java

import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.core.node.Node;

import testsuite.test.ProActiveBenchmark;
import util.ReifiableObject;

public class BenchNewActive extends ProActiveBenchmark {

    private ReifiableObject object = null;

    public BenchNewActive() {
        super(null, "Object Creation with newActive",
            "Measure time to create an active object with newActive.");
    }

    public BenchNewActive(Node node) {
        super(node, "Object Creation with newActive",
            "Measure time to create an active object with newActive.");
    }

    public long action() throws Exception {
        String className = ReifiableObject.class.getName();
        Node node = getNode();
        this.timer.start();
        object = (ReifiableObject) ProActive.newActive(className, null, node);
        this.timer.stop();
        return this.timer.getCumulatedTime();
    }

    public void initTest() throws Exception {
        // nothing to do
    }

    public void endTest() throws Exception {
        // nothing to do
    }

    public boolean preConditions() throws Exception {
        return getNode() != null;
    }
    
    public boolean postConditions() throws Exception {
	Object[] activeObjects = getNode().getActiveObjects();
	return (object != null) && (activeObjects != null) &&
	(activeObjects.length == 1) && activeObjects[0].equals(object);
    }
}

ReifiableObject.java

import java.io.Serializable;

public class ReifiableObject implements Serializable {

	public ReifiableObject() {
	}

}

Manager.prop

RemoteHostname=owenii

Manager.java

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.HTMLLayout;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.WriterAppender;

import testsuite.group.Group;

import testsuite.manager.ProActiveBenchManager;

import java.io.File;

public class Manager extends ProActiveBenchManager {
    private Logger logger = Logger.getLogger(Test1.class);

    public Manager() {
        super("Manager","To manage ProActive Benchmarks.");
        // Log in a HTML file
        HTMLLayout layout = new HTMLLayout();
        WriterAppender appender = null;
        try {
            FileOutputStream output = new FileOutputStream(
                    "/net/home/adicosta/output2.html");
            appender = new WriterAppender(layout, output);
        } catch (Exception e) {
        }
        logger.addAppender(appender);
        BasicConfigurator.configure();
        logger.setLevel(Level.DEBUG);
    }

    public void initManager() throws Exception {
        Group benchGroup = new Group("Bnechmark Group","no description.");

        // adding bench in same VM
        benchGroup.add(new BenchNewActive(getSameVMNode()));
        // adding bench in local VM
        benchGroup.add(new BenchNewActive(getLocalVMNode()));
        // adding bench in remote VM
        benchGroup.add(new BenchNewActive(getRemoteVMNode()));

        // adding the group
        add(benchGroup);
    }

    public static void main(String[] args) {
        Manager manager = new Manager();

        // To run all benchmarks 100 times
        manager.setNbRuns(100);

        // Execute all benchmarks
        manager.execute(true);

        //Write results in a HTML file
        try {
            File file = new File(System.getProperty("user.home") +
                    File.separatorChar + "results.html");
            manager.toHTML(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.exit(0);
    }
}