JavaPorts
Javaports: A Component-based Framework for Network Computing

A Resource Monitoring SPMD Application

This is a Single Program Multiple Data (SPMD) application. Task T1 assumes the Manager's role, while the other tasks assume a Worker's role. Task T1 on the MASTER machine uses the QoS API to get and print the attributes of the machines and links used by this application.

The Configuration File for this Application

BEGIN CONFIGURATION
BEGIN DEFINITIONS
DEFINE APPLICATION "resmonitor"
DEFINE MACHINE M1="gold" MASTER
DEFINE MACHINE M2="zinc"
DEFINE MACHINE M3="copper" 
DEFINE TASK T1="monitor" NUMOFPORTS=2 
DEFINE TASK T2="monitor" NUMOFPORTS=2 
DEFINE TASK T3="monitor" NUMOFPORTS=2 
END DEFINITIONS
BEGIN ALLOCATIONS
ALLOCATE T1 M1
ALLOCATE T2 M2
ALLOCATE T3 M3
END ALLOCATIONS
BEGIN CONNECTIONS
CONNECT T1.P[0] T2.P[0]
CONNECT T1.P[1] T3.P[0]
CONNECT T2.P[1] T3.P[1]
END CONNECTIONS
END CONFIGURATION

NOTE: The above configuration file corresponds to an application built to execute on a local platform. In order to be able to run this application on another platform you will need to adjust the machine domain names (e.g. "gold", "zinc") to the machine domain names on the target cluster. For machine domain names only the machine name should suffice. Machines utilized in running an application should belong to the same domain.

The QoS Setup File

RunQoSSystem=true
MeasLinkData=true
MinMsgSize=40
MaxMsgSize=32000
NumOfPastPointsToRetain=10
NumOfProbesPerPoint=3
LocalQoSDataUpdatePeriod=30
GlobalQoSDataUpdatePeriod=60

NOTE: The above setup file (QoSSetup.txt) contains the default parameters used by the QoS middleware. Make sure that the RunQoSSystem and MeasLinkData variables are set to "true" to turn QoS monitoring on while the application is running.

Completed Java Code for the Monitor Template


package resmonitor;

import SCLASS.*;
import Lib.*;

import java.*;
import java.lang.*;
import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.io.Serializable;
import java.rmi.server.UnicastRemoteObject;

public class monitor extends Thread {
  private Port[] port_;
  private QoSService qosservice_;
  private String AppName_;
  private String TaskVarName_;

  // User class variables

  public monitor(String AppName, String TaskVarName)
  {
    super();
    AppName_ = AppName;
    TaskVarName_ = TaskVarName;
  }

  public synchronized void run () 
  {
    try {
      PortManager portmanager = new PortManager();      
      port_ = portmanager.configure(AppName_, TaskVarName_);
      qosservice_ = new QoSService(AppName_, TaskVarName_);


      // User Application code


      String exitSignal = new String("EXIT"); 
      String tvn = qosservice_.GetTaskVarName();
      int oldStamp = -1;
      int newStamp = -1;
      int maxIter = 3; 
      int iter = 0; 

      // Task T1 is the Manager 
      if(tvn != null && tvn.compareTo("T1") == 0){
        System.out.println("Monitor " + tvn + " is UP ..."); 

        while(true){
          AppView appView = null;

          newStamp = qosservice_.GetMeasStamp();

          // Obtain and print out the resoures data, only when it changes
          if(newStamp != oldStamp){
            oldStamp = newStamp;

            // get and print out the machines information
            System.out.println("---- new data ----\n>>> machines data:");
            appView = qosservice_.GetAppView();
            MachView [] mv = appView.GetMachViews();
        
            for( int m = 0; m < mv.length; m++ ){ 
              System.out.println("     * machine " + mv[m].machName + " data:");
              System.out.println("       maxCPUSpeed = " + 
                mv[m].GetAttributeValue(ResourceAttribute.MAXCPUSPEED, false) + " MHz");
              System.out.println("       Workload = " + 
                mv[m].GetAttributeValue(ResourceAttribute.WORKLOAD, false));
              System.out.println("       EffectiveSpeed = " + 
                mv[m].GetAttributeValue(ResourceAttribute.EFFECTIVESPEED, false) + " MHz");
              System.out.println("       RAMSize = " + 
                mv[m].GetAttributeValue(ResourceAttribute.RAMSIZE, false) + " bytes");
              System.out.println("       SwapSize = " + 
                mv[m].GetAttributeValue(ResourceAttribute.SWAPSIZE, false) + " bytes");
            }

            // get and print out the network links information
            System.out.println(">>> links data:");

            TaskView tv0 = qosservice_.GetTaskView();
            PortView [] pv0 = tv0.GetPortViews();

            TaskView [] tv = mv[1].GetTaskViews();
            PortView [] pv1 = tv[0].GetPortViews();
         
            System.out.println("     * Throughput from " + mv[0].machName + 
                             " to " +  mv[1].machName + " is: " +  
                             pv0[0].GetLinkAttributeValue(ResourceAttribute.THROUGHPUT, false)
                             + " bps"); 
            System.out.println("     * Throughput from " + mv[0].machName + 
                             " to " +  mv[2].machName + " is: " +  
                             pv0[1].GetLinkAttributeValue(ResourceAttribute.THROUGHPUT, false)
                             + " bps");
            System.out.println("     * Throughput from " + mv[1].machName + 
                             " to " +  mv[2].machName + " is: " +  
                             pv1[1].GetLinkAttributeValue(ResourceAttribute.THROUGHPUT, false)
                             + " bps");
            System.out.println("------------------\n");
          }

          iter++;

          // exit when maximum iteration is reached
          if(iter > maxIter)
            break;

          sleep(20000);
        }

        // send exit signals to workers
        for(int p = 0; p < port_.length; p++){
          port_[p].SyncWrite(exitSignal, 0);
        }

        System.out.println("Monitor " + tvn + " Completed ...");
      }
      else{// all other tasks are Workers
        while(true){
           // get exit signal from the Manager
           String str = (String)port_[0].SyncRead(0);

           if(str != null && str.compareTo("EXIT") == 0){ 
              System.out.println("Worker " + tvn + " Completed ...");
              break;
           }
        }
      }


      qosservice_.release();
      portmanager.release(qosservice_);
    }
    catch(Throwable e) {

      e.printStackTrace();
      System.exit(-1);
    }
  }

  public static void main (String args[]) 
  {
    monitor monitorThread = new monitor(args[0], args[1]);
    monitorThread.setPriority(Thread.MIN_PRIORITY);
    monitorThread.start();
    try {
      monitorThread.join();
    } catch(Throwable e) {
      e.printStackTrace();
      System.exit(-1);
    }
      System.exit(0);
  }
}

* NOTE: The code in blue is automatically generated by the JavaPorts Application Configuration Toolset (JPACT) based on the parsed application configuration file. While the code in black is the user code that was added to the original task templates.

:: Last update: 03/14/2010 ::