Multi-Node Distributed Execution Using Hazelcast and Dexecutor

We will try to execute Dexecutor in a distributed mode using Hazelcast. For the demo we would be setting up multiple Hazelast nodes on single machine.

Refer Introducing Dexecutor, to get an introduction on Dexecutor  and to understand the problem we would solve in a distribute fashion. In short:

We would be distributing the execution of dexecutor tasks on Hazelcast compute nodes in a single machine.

To do that one of the nodes would act as master and submit the tasks to Hazelcast compute nodes to be executed by other Hazelcast compute nodes using Dexecutor.

Here are the steps to do that :

Step 1: Add dexecutor-hazelcast dependency


Step 2: Get an Instance of Hazelcast IExecutorService from Hazelcast

 Config cfg = new Config();
 HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
 IExecutorService executorService = instance.getExecutorService("test");

Step 3 : Create Dexecutor using IExecutorService

if (isMaster) {
  DefaultDependentTasksExecutor<Integer, Integer> dexecutor = newTaskExecutor(executorService);

private DefaultDependentTasksExecutor<Integer, Integer> newTaskExecutor(IExecutorService executorService) {
  DependentTasksExecutorConfig<Integer, Integer> config = new DependentTasksExecutorConfig<Integer, Integer>(
  new HazelcastExecutionEngine<Integer, Integer>(executorService), new SleepyTaskProvider());
  return new DefaultDependentTasksExecutor<Integer, Integer>(config);

  private static class SleepyTaskProvider implements TaskProvider<Integer, Integer> {

  public Task<Integer, Integer> provideTask(final Integer id) {
     return new HazelcastTask(id);

Step 4: Execution

Open three terminals and execute the following :

Terminal #1

 mvn test-compile exec:java -Dexec.mainClass="com.github.dexecutor.hazelcast.Node" -Dexec.classpathScope="test" -Dexec.args="s node-A"

Terminal #2

 mvn test-compile exec:java -Dexec.mainClass="com.github.dexecutor.hazelcast.Node" -Dexec.classpathScope="test" -Dexec.args="s node-B"
Terminal #3
 mvn test-compile exec:java -Dexec.mainClass="com.github.dexecutor.hazelcast.Node"  -Dexec.classpathScope="test" -Dexec.args="m node-C"

Here is the Execution

Here is the Complete Node Implementation



One thought on “Multi-Node Distributed Execution Using Hazelcast and Dexecutor

  1. Pingback: Lightweight Workflow Like Execution Using Dexecutor | Craftsman Nadeem

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s