• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Grid gain paper

Grid gain paper






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds


Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Grid gain paper Grid gain paper Document Transcript

    • Installing and Running GridGain- GridGain DefinitionGridGain is a grid computing platform for Java. It is developed in Java for Java developers and isa natural extension of the latest Java development methodologies.2.0 Description of Experiment and Defining RequirementsThe goal of the experiment is to setup GridGain and run a gridded application on the platform.Hardware Architecture: Dell Dimension 8200Software Configuration:Processor – Intel Pentium 4 1.8GHzRAM – 512mbOperating System – Fedora Core 6Installed Software: 1) GridGain – 1.5.1 – obtained free from http://www.gridgain.com 2) Java 1.6 – obtained free from http://java.sun.com/javase/6/ 3) Eclipse – obtained free from http://www.eclipse.org3 Setting up software and hardwareThis section details how we set up Java 1.6, Eclipse, and GridGain3.1 Setting up Java 1.6Installation of Java 1.6 was straightforward. After obtaining the installation (bin) files, we ranthe program and Java was installed However, this new installation did not replace the java file in /usr/bin, which is the defaultcommand run whenever the java command is issued. Thus, the system continued to use the oldjava installation. We created a symbolic link in the /usr/bin folder called java that pointed to thelocation of the newly installed java file. The syntax is sudo ln –s <location of new java file>java. This operation would fail if there already is a file called java in /usr/bin. It is wise torename the current java file before creating the link. The syntax to rename the file would be
    • mv java <new name for java file>. The version of Java installation can be checked by runningthe command java –version.3.2 Setting up GridGain 1.5We encountered one problem when we tried to install GridGain. GridGain requires that aJAVA_HOME environment variable be set. This environment variable points to the location ofthe java installation that GridGain would use. This Java installation has to be version 1.5 or later.To set this environment variable, we added the line export JAVA_HOME=<location of javainstallation> to the /etc/profile file. After the variable was set, the GridGain installation runsmoothly.Running a node of GridGain presented us with new problems. GridGain requires that aGRIDGAIN_HOME environment variable be set. This environment variable points to theinstallation folder of GridGain. The environment variable is set in the same way as theJAVA_HOME environment variable. The line export GRIDGAI _HOME=<location ofGridGain installation> is added to /etc/profile file.In order to give GridGain access to other computers on the network, multicast should be enabledon the local computer. However, multicast is turned off by default. To turn it on, we run thecommand route –add –net netmask dev eth0This however did not fully solve the problem. The local firewall was blocking GridGain’sattempts to contact other computers. To turn the firewall off, we run the command sudo/sbin/service iptables stopAfter these steps, the node started up.3.3 Setting up EclipseEclipse runs without a problem after downloading and extracting it. It should be noted thatEclipse 3 requires Java Experiment Setup and CodeWe decided to implement a gridded merge sort application. The merge sort algorithm splits theinput to sort the items. This makes it an easy algorithm to distribute over several nodes.4.1 How Merge Sort worksThe algorithm recursively splits the input array into smaller arrays until each array has a size ofone. It then puts the array back together, sorting the items before putting them in the array.How the Gridded Merge Sort works. It recursively splits the input array until the constituentarrays are below a specified size. The arrays are then sent to remote nodes for execution. Each
    • node runs the merge sort algorithm and returns a sorted version of the array it received. Thesesorted arrays are then merged to form the whole sorted array.4.2 Programming in GridGainThe documentation and API for GridGain can be found athttp://www.gridgain.com/javadoc/org/gridgain/grid/package-summary.html.4.3 Experiment SetupI used a modified form of the merge sort algorithm implementation found on the site …To set up the experiment, we first started up the Eclipse IDE. We created a new Java project.After this, we added the GridGain libraries to the build path of the project.4.4 CodeThe merge sort class extends the GridTaskSplitAdapter class. The GridTaskSplitAdapter adaptercan be used when jobs can be randomly assigned to available grid nodes. This adapter issufficient in most homogenous environments where all nodes are equally suitable for executinggrid job. Therefore, this is perfect for our needs. The code that does the sorting is readilyavailable on the internet and is omitted from this report.The abstract method split() must controls how the task is split up into jobs. This implementationof the split method recursively splits the array until it reaches a specified size.public Collection<? extends GridJob> split(int gridSize, int[] A) throwsGridException { List<GridJob> jobs = new ArrayList<GridJob>(array.size()); if (A.length<=10)//add array to list of jobs if it meets thesize requirement { jobnum++; array.add(A); System.out.println("Job "+ jobnum + (" added")); } else //recursively split arrays if size is greater than 10 { int mid = A.length/2; int k = mid; int[] B = new int[mid]; int[] C = new int[(A.length-mid)]; for (int i = 0; i<mid; i++)
    • { B[i]=A[i]; } for (int i = 0; i<(A.length-mid); i++) { C[i]=A[k]; k++; } split(gridSize, B);//recursively split arrays split(gridSize, C); //recursively split arrays } //assign each task to a job for (final int [] arra : array) { jobs.add(new GridJobAdapter<int[]>(arra)//create jobsfrom items in the job list { public Serializable execute()//code for each job toexecute { System.out.println("Sorting... Be patient"); MergeSort.sort(arra); nodecount++; System.out.println("Node "+ nodecount + "results ..."); for (int i = 0; i<arra.length; i++) System.out.println(arra[i]+ " "); System.out.println(""); return arra; } }); } return jobs; }When the task is split, each individual task is assigned to a job (GridJobAdapter). Each jobexecutes the code found in the execute method of the GridJobAdapter. This implementation ofthe execute method calls the sort method of the class. When the job is complete, the results areput in a collection and returned.The reduce method aggregates the job results received from the split method. Thisimplementation of the split method merges the sorted arrays into one sorted array. It uses ahelper method called collapse.
    • public Serializable reduce(List<GridJobResult> results) throws GridException//aggregates results from grids { int[] sorted = new int[5]; Vector<int[]> store = new Vector<int[]>(); for (GridJobResult res : results)//get data from successful gridjobs { store.add((int[]) res.getData()); } while (store.size()>2)//merge individual arrays received fromgrids collapse(store); if (store.size()<= 2) { if (store.size()==2) { sorted = newint[(store.elementAt(0).length+store.elementAt(1).length)]; merge(store.elementAt(0), store.elementAt(1), sorted); } if (store.size()==1) { sorted = new int[store.elementAt(0).length]; sorted = store.elementAt(0); } } return sorted; } }private void collapse(Vector<int[]> store) { int size = store.size(); if (size==2) return; else { int[] temp = newint[(store.lastElement().length+store.elementAt(size-2).length)]; merge(store.lastElement(), store.elementAt(size-2),temp); store.add(size-2, temp); store.setSize(size-1); return ; } }The gridded merge sort application is complete. All that is required now is the driver. The driver containsthe main method. It starts the grid, and tells the grid what to execute. Here is the code for my driver.
    • import java.util.Random;import org.gridgain.grid.Grid;import org.gridgain.grid.GridException;import org.gridgain.grid.GridFactory;public class MergeSortExample{ /** * @param args */ public static void main(String[] args) throws GridException{ GridFactory.start();//starts the grid try { Grid grid = GridFactory.getGrid();//creates an instance ofa grid int[] test = new int[1000]; Random jon = new Random(); for (int i=0; i<1000; i++) { test[i] = jon.nextInt(1000); } for (int i = 0; i<test.length; i++) System.out.print(test[i] + " "); test =(int[])grid.execute(MergeSort.class.getName(),test).get(); System.out.println("The gridded sort result is ..."); for (int i = 0; i<test.length; i++) { System.out.print(test[i] + " "); } System.out.println(""); } finally { GridFactory.stop(true);//stops the grid } }}
    • 5.0 Results of ExperimentTo test the setup, I run three GridGain nodes on the host computer. One node run from theEclipse IDE and the others were standalone nodes. I also run three additional nodes on aWindows machine. I did this to see if GridGain could really distribute across different operatingsystems. Below are screen shots of the nodes from both machines. The first screenshot is fromthe host machine.The top two visible windows are the standalone GridGain nodes. The window at the bottom isthe node from Eclipse IDE and it displays part of the results of the final sorted arrayThe next screenshot shows the nodes run on the Windows box.
    • The three GridGain nodes and the results of their computation can be seen here.6.0 ConclusionWe were able to achieve the goals we set for ourselves for the experiment. We installedGridGain and successfully run an application on it. GridGain provides a great API for quickdevelopment of gridded applications. Anyone who can program in Java can quickly catch on tothe GridGain API and be writing applications in no time. As demonstrated by the experiment, theunderlying architecture of the remote nodes does not matter to GridGain. It can distribute jobs toremote computers that run different operating systems and have different hardwareimplementations. This is one of the big advantages of grid computing, and GridGain implementsit very well.