Skip to main content

Bundle-Bee - transparent, grid-distributed OSGi computing

Posted by herkules on January 28, 2010 at 4:43 AM PST

In my famous company innoQ I currently have the opportunity to work on a real cool tool: Bundle-Bee. It claims to be able to take any OSGi bundle and distribute the computational load to an ad-hoc grid (e.g. all machines in an office) without special setup or configuration.

We just released version 0.5.3 which is still very restricted and far from feature complete - we don't even know what feature completeness might mean - but is already quite useful when it comes to doing computationally intensive things. Like fractals ... for example. Fractal computing is known to be computationally intensive and it may take long times to render the fascinating images. On the other hand, the nature of the problem gives a straight forward way to compute the 2D area in separated tiles and thus - in parallel. 

Bundle-Bee is about taking any OSGi bundle an distributing parts of that bundles computational code over a grid with (close-to) zero configuration. We did so e.g. on one of our company's meeting, where we ran the fractal computation on the attendees notebooks in parallel without any hassle. Just let them all start the Bundle-Bee equipped OSGi container (not a big deal) and they immediately make up an ad-hoc grid. Even one iPhone has been part of the game. The fractals jar is automagically flooded to the grid and execution load is split among all nodes.

Hence Bundle-Bee does the grid distribution transparently, there is no special notion of grid computing in the code at all. The brute-force Mandelbrot implementation is just like that:

public class MandelbrotAlgorithm {

   private static int iterate(Complex z0, int maxdepth) {
      Complex z = z0;
      for (int t = 0; t <= maxdepth; t++) {
         if (z.absSquared() >= 4.0)   return t;
         z = z.times(z).plus(z0);
      }
      return maxdepth;
   }

   public int[][] computeArea( Complex z0, Complex dz, int width, int height, int maxdepth ) {
      int[][] res = new int[width][height];
     
      for( int i=0; i         for( int j=0; j            Complex z = new Complex( z0.re()+i*dz.re(), z0.im()+j*dz.im() );
            res[i][j] = iterate(z, maxdepth);
         }
      }
      return res;
   }

Just the main loop needs to go multithreaded which is always a bit tricky when dealing with an UI, but the pseudocode looks easy like that:

MandelbrotAlgorithm algo = new MandelbrotAlgorithm();

onUpdateRequest(area) {
  Collection tiles = divideToTiles(area);
  foreach(tile : tiles) {
    runAsThread() {
      int[][] result = algo.computeArea(tile);
      tile.paint(result);
    }
  }
}

 

Letting Java2D fly a bit, a kind-of-nice UI is not far away:

screenshot

 

Now, by just packing that code into an OSGi bundle (which basically means to augment it with a handful of entries in the MANIFEST.MF), it is ready to be run on a Bundle-Bee grid with nearly unlimited computing power. 

 

Sounds too easy, eh? But it actually is....

 

 

 

AttachmentSize
fractalscreenshot.png153.09 KB