Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Multi Node Distributed Execution Using Infinispan and Dexecutor

DZone's Guide to

Multi Node Distributed Execution Using Infinispan and Dexecutor

In this article, we take a look at how to run Dexecutor in a distributed mode using Infinispan. Read on to find out more.

· Performance Zone ·
Free Resource

xMatters delivers integration-driven collaboration that relays data between systems, while engaging the right people to proactively resolve issues. Read the Monitoring in a Connected Enterprise whitepaper and learn about 3 tools for resolving incidents quickly.

We will try to execute Dexecutor in a distributed mode using Infinispan. For the demo, we would be setting up multiple infinispan nodes on a single machine. Refer to 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 Infinispan nodes in a single machine.

To do that one of nodes would act as master and submit the tasks to DistributedExecutorService to be executed by other infinispan worker nodes.

Step 1: Add dexecutor-infinispan Dependency

<dependency>
    <groupId>com.github.dexecutor</groupId>
    <artifactId>dexecutor-infinispan</artifactId>
    <version>0.0.2</version>
</dependency>

Step 2: Add the Default jgroups.xml

Step 3: Create the CacheManager

private DefaultCacheManager createCacheManagerProgrammatically(final String nodeName, final String cacheName) {
    DefaultCacheManager cacheManager = new DefaultCacheManager(globalConfiguration(nodeName), defaultConfiguration());
    cacheManager.defineConfiguration(cacheName, cacheConfiguration());
    return cacheManager;
}

private GlobalConfiguration globalConfiguration(String nodeName) {
    return GlobalConfigurationBuilder
    .defaultClusteredBuilder()
    .transport()
    .nodeName(nodeName)
    .addProperty("configurationFile", "jgroups.xml")
    .build();
}

private Configuration defaultConfiguration() {
    return new ConfigurationBuilder()
    .clustering()
    .cacheMode(CacheMode.REPL_SYNC)
    .build();
}

private Configuration cacheConfiguration() {
    return new ConfigurationBuilder()
    .clustering()
    .cacheMode(CacheMode.DIST_SYNC)
    .hash()
    .numOwners(2)
    .build();
}

Step 4 : Create Dexecutor Instance Using InfinispanExecutionEngine

EmbeddedCacheManager cacheManager = createCacheManagerProgrammatically(nodeName, cacheName);
final Cache<String, String> cache = cacheManager.getCache(cacheName);
DefaultExecutorService distributedExecutorService = new DefaultExecutorService(cache);
DefaultDependentTasksExecutor<Integer, Integer> dexecutor = newTaskExecutor(distributedExecutorService);

private DefaultDependentTasksExecutor<Integer, Integer> newTaskExecutor(final DistributedExecutorService executorService) {
    return new DefaultDependentTasksExecutor<Integer, Integer>(taskExecutorConfig(executorService));
}

private DependentTasksExecutorConfig<Integer, Integer> taskExecutorConfig(final DistributedExecutorService executorService) {
    return new DependentTasksExecutorConfig<Integer, Integer>(executionEngine(executorService), new SleepyTaskProvider());
}

private InfinispanExecutionEngine<Integer, Integer> executionEngine(final DistributedExecutorService executorService) {
    return new InfinispanExecutionEngine<Integer, Integer>(executorService);
}

Step 5: Only Master Should Create Tasks

if (isMaster) {
    DefaultExecutorService distributedExecutorService = new DefaultExecutorService(cache);
    DefaultDependentTasksExecutor<Integer, Integer> dexecutor = newTaskExecutor(distributedExecutorService);

    buildGraph(dexecutor);
    dexecutor.execute(ExecutionBehavior.TERMINATING);
}

Refer the full code here.

Step 4: Run the Application

Terminal #1 : Run as worker

mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.infinispan.Node" -Dexec.classpathScope="test" -Dexec.args="s node-A"

Terminal #2: Run as worker

mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.infinispan.Node" -Dexec.classpathScope="test" -Dexec.args="s node-B"

Terminal #3 : Run as Master

mvn test-compile exec:java  -Dexec.classpathScope="test" -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.infinispan.Node" -Dexec.args="m node-C"

Here is the output:

dexecutor-multi-node-infinispan-single-machine

References

Discovering, responding to, and resolving incidents is a complex endeavor. Read this narrative to learn how you can do it quickly and effectively by connecting AppDynamics, Moogsoft and xMatters to create a monitoring toolchain.

Topics:
infinispan ,nodes ,dependency ,example ,code

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}