Navigation


Changes between Version 2 and Version 3 of Laboratory/GridComparisonPartI/GridGain-2.1.1

Show
Ignore:
Timestamp:
12.02.2010 15:18:23 (3 years ago)
Author:
jeremian
Comment:

Two test cases for GridGain

Legend:

Unmodified
Added
Removed
Modified
  • Laboratory/GridComparisonPartI/GridGain-2.1.1

    v2 v3  
    1616 
    1717 == Code == 
     18 
     19We prepared two versions of the !GridGain test: 
     20 * with !GridTasks 
     21 * with !ExecutorService 
     22 
     23The first version had some issues with large amount of tasks (known edge-case problem with "siblings" explosion). The second one performed much better with large amount of tasks, but was a little bit slower in other cases. 
     24 
     25 === Test case I - using !GridTasks === 
    1826 
    1927!GridGain operates on the !GridTasks. Executing such tasks is very simple: 
     
    8694 
    8795    return result; 
     96} 
     97 
     98}}} 
     99 
     100 === Test case II - using !ExecutorService === 
     101 
     102!GridGain's distributed executor service operates on the Callable/Runnable interfaces. The main work was done in the '''Agent''' class, which implements Callable interface: 
     103 
     104{{{ 
     105#!java 
     106 
     107public class Agent implements Callable<FastBigInt128>, Serializable { 
     108    private static final long serialVersionUID = 1L; 
     109    private String[] imageDesc; 
     110    private int z; 
     111 
     112    public Agent(String[] imageDesc, int z) { 
     113        this.imageDesc = imageDesc; 
     114        this.z = z; 
     115    } 
     116 
     117    public FastBigInt128 call() { 
     118        Worker cmbfWorker = new Worker(); 
     119        FastBigInt128 result = cmbfWorker.countInImage(imageDesc); 
     120        System.out.println("\tResult from task #" + z + ", " + "\tvalue: " + result); 
     121        return result; 
     122    } 
     123} 
     124 
     125}}} 
     126 
     127In order to perform computations, we had to divide problem into small tasks and submit them into executor service: 
     128 
     129{{{ 
     130#!java 
     131 
     132for (int i = 1; i <= n; i++) { 
     133    for (final String[] imageDesc : cmbfWorker.generateImages(i, level)) { 
     134        Future<FastBigInt128> future = executorService.submit(new Agent(imageDesc, ++count)); 
     135        tasks.add(future); 
     136    } 
     137} 
     138 
     139}}} 
     140 
     141After that we had to gather results: 
     142 
     143{{{ 
     144#!java 
     145 
     146for (Future<FastBigInt128> w : tasks) { 
     147    results.add(w.get()); 
    88148} 
    89149