Apache Ignite

GridGain Developer Hub - Apache Ignitetm

Welcome to the Apache Ignite developer hub run by GridGain. Here you'll find comprehensive guides and documentation to help you start working with Apache Ignite as quickly as possible, as well as support if you get stuck.

 

GridGain also provides Community Edition which is a distribution of Apache Ignite made available by GridGain. It is the fastest and easiest way to get started with Apache Ignite. The Community Edition is generally more stable than the Apache Ignite release available from the Apache Ignite website and may contain extra bug fixes and features that have not made it yet into the release on the Apache website.

 

Let's jump right in!

 

Documentation     Ask a Question     Download

 

Javadoc     Scaladoc     Examples

Job Scheduling

Properly order your jobs for execution.

Overview

In Ignite, jobs are mapped to cluster nodes during initial task split or closure execution on the client side. However, once jobs arrive to the designated nodes, they need to be ordered for execution. By default, jobs are submitted to a thread pool and are executed in random order. However, if you want to have a fine-grained control over job ordering, you can enable CollisionSpi.

FIFO Ordering

FifoQueueCollisionSpi allows a certain number of jobs in first-in first-out order to proceed without interruptions. All other jobs will be put on a waiting list until their turn.

Number of parallel jobs is controlled by parallelJobsNumber configuration parameter. Default is number of cores times 2.

One at a Time

Note that by setting parallelJobsNumber to 1, you can guarantee that all jobs will be executed one-at-a-time, and no two jobs will be executed concurrently.

<bean class="org.apache.ignite.IgniteConfiguration" singleton="true">
  ...
  <property name="collisionSpi">
    <bean class="org.apache.ignite.spi.collision.fifoqueue.FifoQueueCollisionSpi">
      <!-- Execute one job at a time. -->
      <property name="parallelJobsNumber" value="1"/>
    </bean>
  </property>
  ...
</bean>
FifoQueueCollisionSpi colSpi = new FifoQueueCollisionSpi();
 
// Execute jobs sequentially, one at a time, 
// by setting parallel job number to 1.
colSpi.setParallelJobsNumber(1);
 
IgniteConfiguration cfg = new IgniteConfiguration();
 
// Override default collision SPI.
cfg.setCollisionSpi(colSpi);
 
// Start Ignite node.
Ignition.start(cfg);

Priority Ordering

PriorityQueueCollisionSpi allows to assign priorities to individual jobs, so jobs with higher priority will be executed ahead of lower priority jobs.

Task Priorities

Task priorities are set in the task session via grid.task.priority attribute. If no priority has been assigned to a task, then the default priority of 0 is used.

Below is an example showing how task priority can be set:

public class MyUrgentTask extends ComputeTaskSplitAdapter<Object, Object> {
  // Auto-injected task session.
  @TaskSessionResource
  private GridTaskSession taskSes = null;
 
  @Override
  protected Collection<ComputeJob> split(int gridSize, Object arg) {
    ...
    // Set high task priority.
    taskSes.setAttribute("grid.task.priority", 10);
 
    List<ComputeJob> jobs = new ArrayList<>(gridSize);
    
    for (int i = 1; i <= gridSize; i++) {
      jobs.add(new GridJobAdapter() {
        ...
      });
    }
    ...
      
    // These jobs will be executed with higher priority.
    return jobs;
  }
}

Configuration

Just like with FIFO Ordering, the number of parallel jobs is controlled by parallelJobsNumber configuration parameter.

<bean class="org.apache.ignite.IgniteConfiguration" singleton="true">
	...
	<property name="collisionSpi">
		<bean class="org.apache.ignite.spi.collision.priorityqueue.PriorityQueueCollisionSpi">
      <!-- 
        Change the parallel job number if needed.
        Default is number of cores times 2.
      -->
			<property name="parallelJobsNumber" value="5"/>
		</bean>
	</property>
	...
</bean>
PriorityQueueCollisionSpi colSpi = new PriorityQueueCollisionSpi();

// Change the parallel job number if needed.
// Default is number of cores times 2.
colSpi.setParallelJobsNumber(5);
 
IgniteConfiguration cfg = new IgniteConfiguration();
 
// Override default collision SPI.
cfg.setCollisionSpi(colSpi);
 
// Start Ignite node.
Ignition.start(cfg);

Job Scheduling

Properly order your jobs for execution.