blob: cf9caddaa47ea0e47772cd3ec99a5b5cbb2482eb [file]
= Job Scheduling
:javaFile: {javaCodeDir}/JobScheduling.java
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 link:distributed-computing/load-balancing#job-stealing[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.
[tabs]
--
tab:XML[]
[source,xml]
----
include::code-snippets/xml/job-scheduling-fifo.xml[tags=ignite-config;!discovery, indent=0]
----
tab:Java[]
[source,java]
----
include::{javaFile}[tag=fifo,indent=0]
----
tab:C#/.NET[unsupported]
--
== 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.
[tabs]
--
tab:XML[]
[source,xml]
----
include::code-snippets/xml/job-scheduling-priority.xml[tags=ignite-config;!discovery, indent=0]
----
tab:Java[]
[source,java]
----
include::{javaFile}[tag=priority,indent=0]
----
tab:C#/.NET[unsupported]
tab:C++[unsupported]
--
Task priorities are set in the link:distributed-computing/map-reduce#distributed-task-session[task session] via the `grid.task.priority` attribute. If no priority is assigned to a task, then the default priority of 0 is used.
[source, java]
----
include::{javaFile}[tag=task-priority,indent=0]
----