Job Scheduling | Ignite Documentation

Ignite Summit 2024 — Call For Speakers Now Open — Learn more

Edit

Job Scheduling

When jobs arrive at the destination node, they are submitted to a thread pool and scheduled for execution in random order. However, you can change job ordering by configuring CollisionSpi. The CollisionSpi interface provides a way to control how jobs are scheduled for processing on each node.

Ignite provides several implementations of the CollisionSpi interface:

  • FifoQueueCollisionSpi — simple FIFO ordering in multiple threads. This implementation is used by default;

  • PriorityQueueCollisionSpi — priority ordering;

  • JobStealingFailoverSpi — use this implementation to enable job stealing.

To enable a specific collision spi, change the IgniteConfiguration.collisionSpi property.

FIFO Ordering

FifoQueueCollisionSpi provides FIFO ordering of jobs as they arrive. The jobs are executed in multiple threads. The number of threads is controlled by the parallelJobsNumber parameter. The default value equals 2 times the number of processor cores.

<bean class="org.apache.ignite.configuration.IgniteConfiguration">

    <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 a node.
Ignite ignite = Ignition.start(cfg);
This API is not presently available for C#/.NET. You can use XML configuration.

Priority Ordering

Use PriorityQueueCollisionSpi to assign priorities to individual jobs, so that jobs with higher priority are executed ahead of lower priority jobs. You can also specify the number of threads to process jobs.

<bean class="org.apache.ignite.configuration.IgniteConfiguration">

    <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 a node.
Ignite ignite = Ignition.start(cfg);
This API is not presently available for C#/.NET. You can use XML configuration.
This API is not presently available for C++. You can use XML configuration.

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

public class MyUrgentTask extends ComputeTaskSplitAdapter<Object, Object> {
    // Auto-injected task session.
    @TaskSessionResource
    private ComputeTaskSession 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 ComputeJobAdapter() {

                @Override
                public Object execute() throws IgniteException {

                    //your implementation goes here

                    return null;
                }
            });
        }

        // These jobs will be executed with higher priority.
        return jobs;
    }

    @Override
    public Object reduce(List<ComputeJobResult> results) throws IgniteException {
        return null;
    }
}