Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Currently we don't have much more than a infinite loop that entertains the garbage collector. So let's introduce a naive partitioning trick to let the slaves do work and consume our sent messages:

No Format
    @Override
    public void bsp(
	    BSPPeer<NullWritable, NullWritable, NullWritable, NullWritable, IntWritable> peer)
	    throws IOException, SyncException, InterruptedException {

	if (isMaster) {
	    Random random = new Random();
	    // produces new random integers every second
	    while (true) {
		int newInt = random.nextInt();
		peer.send(peer.getAllPeerNames()[Math.abs(newInt % peer.getNumPeers())],
			new IntWritable(newInt));
		System.out.println("Sending " + newInt);
		peer.sync();
		Thread.sleep(1000);
	    }
	} else {
	    // if I'm not the master, then I am one of the slaves!
	    while (true) {
		peer.sync();
		IntWritable msg = null;
		while ((msg = peer.getCurrentMessage()) != null) {
		    System.out.println(msg.get() + " received!");
		}
	    }
	}
    }

...

This example would then not have overhead in using a global sync, because it does not use it.

Also when a single master task is used, the throughput and scalability is limited by a single task. You could add more task to serve as a master and we want to definitely want to add convenience functions to make it much more easier to implement these real-time systems in a scalable manner.