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

Download our Introduction to API Performance Testing and learn why testing your API is just as important as testing your website, and how to start today.

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

Find scaling and performance issues before your customers do with our Introduction to High-Capacity Load Testing guide.

Topics:
infinispan ,nodes ,dependency ,example ,code

Published at DZone with permission of Mohammad Nadeem, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}