Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Distributed Computing API

GridGain's distributed computing API distributes tasks across cluster nodes, with support for runnables, callables, closures, broadcasting, and asynchronous execution.

GridGain provides an API for distributing computations across cluster nodes in a balanced and fault-tolerant manner. You can submit individual tasks for execution as well as implement the MapReduce pattern with automatic task splitting. The API provides fine-grained control over the job distribution strategy.

Getting the Compute Interface

The main entry point for running distributed computations is the compute interface, which can be obtained from an instance of Ignite.

Ignite ignite = Ignition.start();

IgniteCompute compute = ignite.compute();
var ignite = Ignition.Start();
var compute = ignite.GetCompute();
Ignite ignite = Ignition::Start(cfg);

Compute compute = ignite.GetCompute();

The compute interface provides methods for distributing different types of tasks over cluster nodes and running collocated computations.

Specifying the Set of Nodes for Computations

Each instance of the compute interface is associated with a set of nodes on which the tasks are executed. When called without arguments, ignite.compute() returns the compute interface that is associated with all server nodes. To obtain an instance for a specific subset of nodes, use Ignite.compute(ClusterGroup group). In the following example, the compute interface is bound to the remote nodes only, i.e. all nodes except for the one that runs this code.

Ignite ignite = Ignition.start();

IgniteCompute compute = ignite.compute(ignite.cluster().forRemotes());
var ignite = Ignition.Start();
var compute = ignite.GetCluster().ForRemotes().GetCompute();

unsupported

Executing Tasks

GridGain provides three interfaces that can be implemented to represent a task and executed via the compute interface:

  • IgniteRunnable — an extension of java.lang.Runnable that can be used to implement calculations that do not have input parameters and return no result.

  • IgniteCallable — an extension of java.util.concurrent.Callable that returns a specific value.

  • IgniteClosure — a functional interface that accepts a parameter and returns a value.

You can execute a task once (on one of the nodes) or broadcast it to all nodes.

Executing a Runnable Task

To execute a runnable task, use the run(...) method of the compute interface. The task is sent to one of the nodes associated with the compute instance.

Executing a Callable Task

To execute a callable task, use the call(...) method of the compute interface.

Executing an IgniteClosure

To execute an IgniteClosure, use the apply(...) method of the compute interface. The method accepts a task and an input parameter for the task. The parameter is passed to the given IgniteClosure at the execution time.

unsupported

Broadcasting a Task

The broadcast() method executes a task on all nodes associated with the compute instance.

Asynchronous Execution

All methods described in the previous sections have asynchronous counterparts:

  • callAsync(...)

  • runAsync(...)

  • applyAsync(...)

  • broadcastAsync(...)

The asynchronous methods return an IgniteFuture that represents the result of the operation. In the following example, a collection of callable tasks is executed asynchronously.

Task Execution Timeout

You can set a timeout for task execution. If the task does not finish within the given time frame, it be stopped and all jobs produced by this task are cancelled.

To execute a task with a timeout, use the withTimeout(...) method of the compute interface. The method returns a compute interface that executes the first task given to it in a time-limited manner. Consequent tasks do not have a timeout: you need to call withTimeout(...) for every task that should have a timeout.

Sharing State Between Jobs on Local Node

It is often useful to share a state between different compute jobs executed on one node. For this purpose, there is a shared concurrent local map available on each node.

unsupported

unsupported

Node-local values are similar to thread local variables in that these values are not distributed and kept only on the local node. Node-local data can be used to share the state between compute jobs. It can also be used by deployed services.

In the following example, a job increments a node-local counter every time it executes on some node. As a result, the node-local counter on each node tells us how many times the job has executed on that node.

unsupported

unsupported

Accessing Data from Computational Tasks

If your computational task needs to access the data stored in caches, you can do it via the instance of Ignite:

Note that the example shown above may not be the most effective way. The reason is that the person object that corresponds to key 1 may be located on a node that is different from the node where the task is executed. In this case, the object is fetched via network. This can be avoided by colocating the task with the data.

Enabling Extended Support

By default, a number of internal properties and parameters are not exposed to the user and run at default settings. Use the @ComputeTaskSessionFullSupport annotation to access all ComputeTaskSession attributes. With it, you can work with task attributes, for example, change tasks priorities or set up a listener for events.

Other Distributed Computing Interfaces

GridGain also provides a number of interfaces that can be used to provide additional control over how your distributed computing tasks are executed:

  • The scope of the nodes used in the execution can be adjusted by using the ClusterGroup interface;

  • Tasks can be submitted to the server node to be automatically distributed across the cluster by using the ExecutorService interface;

  • The ComputeTask interface can be used to implement custom map and reduce logic as described in the MapReduce API topic;

  • GridGain handles load balancing automatically, but you can adjust the type of load balancing used and the balancing configuration by using the loadBalancingSpi;

  • GridGain reroutes failed jobs to other nodes by default. You can change the failoverSpi property to handle failed jobs in a different way;

  • Job priority can be configured by using the CollisionSpi.

This page is: Copyright © 2026 MariaDB. All rights reserved.

Last updated

Was this helpful?