Task Affinity
Task Affinity provides the ability to run a set of Tasks on the same Engine or set of Engines. It is primarily used for data awareness and locality. For example, you might have a large dataset, and have Tasks that work on subsets of that dataset, so you would prefer that an Engine works on Tasks from the same subset.
Create Task Affinity Conditions with the SchedulingConditionFactory
, using the createTaskAffinity
method.
When set on a Task, it specifies that this Task must run only on an Engine that has already worked on a Task with the same TaskAffinity
as specified by a tag.
The wait
value indicates how long it must wait for an Engine with affinity before being allowed on any Engine. This wait countdown starts the first time that the task becomes available for scheduling, and only if it is the next task to be assigned to this set.
The first TaskAffinity
for a given tag must be assigned a wait value of 0 so that it is immediately assigned to an Engine. Typically the remaining in the set would use the same value, for example, 10000 for a wait of 10s. An Engine retains the affinity for the duration of the Service Session but not beyond.
The tag is not guaranteed to be unique among all Services, so you would typically append a unique value to the tag, such as the Service ID. This is left to the caller, since there might be a unique string shorter than the Service ID which results in quicker string comparisons.
TaskAffinity
can be used in a ConditionSet
. For example, you can use this along with a PropertyDiscriminator
and a Descriptor
using an AND
ConditionSet
.