SlideShare une entreprise Scribd logo
1  sur  8
Télécharger pour lire hors ligne
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
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
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++)
{
                                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.
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.
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
               }

         }

}
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.
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.

Contenu connexe

Tendances

Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Paul King
 
XSpect, a lightweight library to make your code reusable and maintainable.
XSpect, a lightweight library to make your code reusable and maintainable.XSpect, a lightweight library to make your code reusable and maintainable.
XSpect, a lightweight library to make your code reusable and maintainable.
岡諭 李
 
concurrency gpars
concurrency gparsconcurrency gpars
concurrency gpars
Paul King
 
망고100 보드로 놀아보자 19
망고100 보드로 놀아보자 19망고100 보드로 놀아보자 19
망고100 보드로 놀아보자 19
종인 전
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
Gabriele Lana
 

Tendances (20)

Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
XSpect, a lightweight library to make your code reusable and maintainable.
XSpect, a lightweight library to make your code reusable and maintainable.XSpect, a lightweight library to make your code reusable and maintainable.
XSpect, a lightweight library to make your code reusable and maintainable.
 
concurrency gpars
concurrency gparsconcurrency gpars
concurrency gpars
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Mathemetics module
Mathemetics moduleMathemetics module
Mathemetics module
 
The Ring programming language version 1.2 book - Part 78 of 84
The Ring programming language version 1.2 book - Part 78 of 84The Ring programming language version 1.2 book - Part 78 of 84
The Ring programming language version 1.2 book - Part 78 of 84
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest Matchers
 
망고100 보드로 놀아보자 19
망고100 보드로 놀아보자 19망고100 보드로 놀아보자 19
망고100 보드로 놀아보자 19
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
 
Autoboxing And Unboxing In Java
Autoboxing And Unboxing In JavaAutoboxing And Unboxing In Java
Autoboxing And Unboxing In Java
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
Workflows ss
Workflows ssWorkflows ss
Workflows ss
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
Saving lives with rx java
Saving lives with rx javaSaving lives with rx java
Saving lives with rx java
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 

Similaire à Grid gain paper

Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
knight1128
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
info309708
 

Similaire à Grid gain paper (20)

Flink Batch Processing and Iterations
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and Iterations
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
J2SE 5
J2SE 5J2SE 5
J2SE 5
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Gephi Toolkit Tutorial
Gephi Toolkit TutorialGephi Toolkit Tutorial
Gephi Toolkit Tutorial
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Part 1 - Written AnswersDownload the GridWriter.zip file and exami.pdf
Part 1 - Written AnswersDownload the GridWriter.zip file and exami.pdfPart 1 - Written AnswersDownload the GridWriter.zip file and exami.pdf
Part 1 - Written AnswersDownload the GridWriter.zip file and exami.pdf
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
 
Forgive me for i have allocated
Forgive me for i have allocatedForgive me for i have allocated
Forgive me for i have allocated
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
 
Thread
ThreadThread
Thread
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

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.