How to Troubleshoot Apps for the Modern Connected Worker
Â
Grid gain paper
1. Installing and Running GridGain-1.5.1
1.0 GridGain Definition
GridGain is a grid computing platform for Java. It is developed in Java for Java developers and is
a natural extension of the latest Java development methodologies.
2.0 Description of Experiment and Defining Requirements
The goal of the experiment is to setup GridGain and run a gridded application on the platform.
Hardware Architecture: Dell Dimension 8200
Software Configuration:
Processor â Intel Pentium 4 1.8GHz
RAM â 512mb
Operating System â Fedora Core 6
Installed 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.org
3 Setting up software and hardware
This section details how we set up Java 1.6, Eclipse, and GridGain
3.1 Setting up Java 1.6
Installation of Java 1.6 was straightforward. After obtaining the installation (bin) files, we ran
the program and Java was installed
However, this new installation did not replace the java file in /usr/bin, which is the default
command run whenever the java command is issued. Thus, the system continued to use the old
java installation. We created a symbolic link in the /usr/bin folder called java that pointed to the
location 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 to
rename the current java file before creating the link. The syntax to rename the file would be
2. mv java <new name for java file>. The version of Java installation can be checked by running
the command java âversion.
3.2 Setting up GridGain 1.5
We encountered one problem when we tried to install GridGain. GridGain requires that a
JAVA_HOME environment variable be set. This environment variable points to the location of
the 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 java
installation> to the /etc/profile file. After the variable was set, the GridGain installation run
smoothly.
Running a node of GridGain presented us with new problems. GridGain requires that a
GRIDGAIN_HOME environment variable be set. This environment variable points to the
installation folder of GridGain. The environment variable is set in the same way as the
JAVA_HOME environment variable. The line export GRIDGAI _HOME=<location of
GridGain installation> is added to /etc/profile file.
In order to give GridGain access to other computers on the network, multicast should be enabled
on the local computer. However, multicast is turned off by default. To turn it on, we run the
command route âadd ânet 224.0.0.0 netmask 240.0.0.0 dev eth0
This however did not fully solve the problem. The local firewall was blocking GridGainâs
attempts to contact other computers. To turn the firewall off, we run the command sudo
/sbin/service iptables stop
After these steps, the node started up.
3.3 Setting up Eclipse
Eclipse runs without a problem after downloading and extracting it. It should be noted that
Eclipse 3 requires Java 1.6.
4.0 Experiment Setup and Code
We decided to implement a gridded merge sort application. The merge sort algorithm splits the
input to sort the items. This makes it an easy algorithm to distribute over several nodes.
4.1 How Merge Sort works
The algorithm recursively splits the input array into smaller arrays until each array has a size of
one. 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 constituent
arrays are below a specified size. The arrays are then sent to remote nodes for execution. Each
3. node runs the merge sort algorithm and returns a sorted version of the array it received. These
sorted arrays are then merged to form the whole sorted array.
4.2 Programming in GridGain
The documentation and API for GridGain can be found at
http://www.gridgain.com/javadoc/org/gridgain/grid/package-summary.html.
4.3 Experiment Setup
I 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 Code
The merge sort class extends the GridTaskSplitAdapter class. The GridTaskSplitAdapter adapter
can be used when jobs can be randomly assigned to available grid nodes. This adapter is
sufficient in most homogenous environments where all nodes are equally suitable for executing
grid job. Therefore, this is perfect for our needs. The code that does the sorting is readily
available on the internet and is omitted from this report.
The abstract method split() must controls how the task is split up into jobs. This implementation
of the split method recursively splits the array until it reaches a specified size.
public Collection<? extends GridJob> split(int gridSize, int[] A) throws
GridException {
List<GridJob> jobs = new ArrayList<GridJob>(array.size());
if (A.length<=10)//add array to list of jobs if it meets the
size 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++)
4. {
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 jobs
from items in the job list
{
public Serializable execute()//code for each job to
execute
{
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 job
executes the code found in the execute method of the GridJobAdapter. This implementation of
the execute method calls the sort method of the class. When the job is complete, the results are
put in a collection and returned.
The reduce method aggregates the job results received from the split method. This
implementation of the split method merges the sorted arrays into one sorted array. It uses a
helper method called collapse.
5. 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 grid
jobs
{
store.add((int[]) res.getData());
}
while (store.size()>2)//merge individual arrays received from
grids
collapse(store);
if (store.size()<= 2)
{
if (store.size()==2)
{
sorted = new
int[(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 = new
int[(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 contains
the main method. It starts the grid, and tells the grid what to execute. Here is the code for my driver.
6. 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 of
a 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
}
}
}
7. 5.0 Results of Experiment
To test the setup, I run three GridGain nodes on the host computer. One node run from the
Eclipse IDE and the others were standalone nodes. I also run three additional nodes on a
Windows machine. I did this to see if GridGain could really distribute across different operating
systems. Below are screen shots of the nodes from both machines. The first screenshot is from
the host machine.
The top two visible windows are the standalone GridGain nodes. The window at the bottom is
the node from Eclipse IDE and it displays part of the results of the final sorted array
The next screenshot shows the nodes run on the Windows box.
8. The three GridGain nodes and the results of their computation can be seen here.
6.0 Conclusion
We were able to achieve the goals we set for ourselves for the experiment. We installed
GridGain and successfully run an application on it. GridGain provides a great API for quick
development of gridded applications. Anyone who can program in Java can quickly catch on to
the GridGain API and be writing applications in no time. As demonstrated by the experiment, the
underlying architecture of the remote nodes does not matter to GridGain. It can distribute jobs to
remote computers that run different operating systems and have different hardware
implementations. This is one of the big advantages of grid computing, and GridGain implements
it very well.