scheduler

package
v0.0.0-...-f52f6c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 22 Imported by: 9

Documentation

Overview

Package scheduler orders tasks in distro queues.

Index

Constants

View Source
const RunnerName = "scheduler"

Variables

This section is empty.

Functions

func AlternateTaskFinder

func AlternateTaskFinder(ctx context.Context, d distro.Distro) ([]task.Task, error)

func FilterTasksWithVersionCache

func FilterTasksWithVersionCache(tasks []task.Task) ([]task.Task, map[string]model.Version, error)

FilterTasksWithVersionCache finds tasks whose versions have already been created, and returns those tasks, as well as a map of version IDs to versions.

func GetDistroQueueInfo

func GetDistroQueueInfo(distroID string, tasks []task.Task, maxDurationThreshold time.Duration, opts TaskPlannerOptions) model.DistroQueueInfo

Returns the distroQueueInfo for the given set of tasks having set the task.ExpectedDuration for each task.

func LegacyFindRunnableTasks

func LegacyFindRunnableTasks(ctx context.Context, d distro.Distro) ([]task.Task, error)

The old Task finderDBTaskFinder, with the dependency check implemented in Go, instead of using $graphLookup

func ParallelTaskFinder

func ParallelTaskFinder(ctx context.Context, d distro.Distro) ([]task.Task, error)

func PersistTaskQueue

func PersistTaskQueue(distro string, tasks []task.Task, distroQueueInfo model.DistroQueueInfo) error

PersistTaskQueue saves the task queue to the database. Returns an error if the db call returns an error.

func PlanDistro

func PlanDistro(ctx context.Context, conf Configuration, s *evergreen.Settings) error

func PopulateCaches

func PopulateCaches(id string, tasks []task.Task) ([]task.Task, error)

PopulateCaches runs setup functions and is used by the new/tunable scheduler to reprocess tasks before running the new planner.

func PrioritizeTasks

func PrioritizeTasks(d *distro.Distro, tasks []task.Task, opts TaskPlannerOptions) ([]task.Task, error)

func RunnableTasksPipeline

func RunnableTasksPipeline(ctx context.Context, d distro.Distro) ([]task.Task, error)

func SpawnHosts

func SpawnHosts(ctx context.Context, d distro.Distro, newHostsNeeded int, pool *evergreen.ContainerPool) ([]host.Host, error)

Call out to the embedded Manager to spawn hosts. Takes in a map of distro -> number of hosts to spawn for the distro. Returns a map of distro -> hosts spawned, and an error if one occurs. The pool parameter is assumed to be the one from the distro passed in

func UpdateStaticDistro

func UpdateStaticDistro(ctx context.Context, d distro.Distro) error

func UtilizationBasedHostAllocator

func UtilizationBasedHostAllocator(ctx context.Context, hostAllocatorData *HostAllocatorData) (int, int, error)

Types

type CmpBasedTaskComparator

type CmpBasedTaskComparator struct {
	// contains filtered or unexported fields
}

CmpBasedTaskComparator runs the tasks through a slice of comparator functions determining which is more important.

func NewCmpBasedTaskComparator

func NewCmpBasedTaskComparator(id string) *CmpBasedTaskComparator

NewCmpBasedTaskComparator returns a new task prioritizer, using the default set of comparators as well as the setup functions necessary for those comparators.

func (*CmpBasedTaskComparator) Len

func (cbtc *CmpBasedTaskComparator) Len() int

func (*CmpBasedTaskComparator) Less

func (cbtc *CmpBasedTaskComparator) Less(i, j int) bool

func (*CmpBasedTaskComparator) Swap

func (cbtc *CmpBasedTaskComparator) Swap(i, j int)

type CmpBasedTaskPrioritizer

type CmpBasedTaskPrioritizer struct {
	// contains filtered or unexported fields
}

func (*CmpBasedTaskPrioritizer) PrioritizeTasks

func (prioritizer *CmpBasedTaskPrioritizer) PrioritizeTasks(distroId string, tasks []task.Task, versions map[string]model.Version) ([]task.Task, map[string]map[string]string, error)

PrioritizeTask prioritizes the tasks to run. First splits the tasks into slices based on whether they are part of patch versions or automatically created versions. Then prioritizes each slice, and merges them. Returns a full slice of the prioritized tasks, and an error if one occurs.

type CmpBasedTaskQueues

type CmpBasedTaskQueues struct {
	HighPriorityTasks []task.Task
	PatchTasks        []task.Task
	RepotrackerTasks  []task.Task
}

CmpBasedTaskQueues represents the three types of queues that are created for merging together into one queue. The HighPriorityTasks list represent the tasks that are always placed at the front of the queue PatchTasks and RepotrackerTasks are interleaved after the high priority tasks.

type Configuration

type Configuration struct {
	DistroID   string
	TaskFinder string
}

type HostAllocator

type HostAllocator func(context.Context, *HostAllocatorData) (newHostsNeeded int, estimatedFreeHosts int, err error)

HostAllocator is responsible for determining how many new hosts should be spun up. The first returned int is this number, and the second returned int is the rough number of free hosts.

func GetHostAllocator

func GetHostAllocator(name string) HostAllocator

type HostAllocatorData

type HostAllocatorData struct {
	Distro          distro.Distro
	ExistingHosts   []host.Host
	UsesContainers  bool
	ContainerPool   *evergreen.ContainerPool
	DistroQueueInfo model.DistroQueueInfo
}

type Scheduler

type Scheduler struct {
	*evergreen.Settings
	TaskPrioritizer
	HostAllocator

	FindRunnableTasks TaskFinder
}

Responsible for prioritizing and scheduling tasks to be run, on a per-distro basis.

type StringSet

type StringSet map[string]struct{}

StringSet provides simple tools for managing sets of strings.

func (StringSet) Add

func (s StringSet) Add(id string)

Add places the string in the set.

func (StringSet) Check

func (s StringSet) Check(id string) bool

Check returns true if the string is a member of the set.

func (StringSet) Visit

func (s StringSet) Visit(id string) bool

Visit returns true if the string is already a member of the set. Otherwise it adds it to the set and returns false.

type TaskFinder

type TaskFinder func(context.Context, distro.Distro) ([]task.Task, error)

func GetTaskFinder

func GetTaskFinder(version string) TaskFinder

type TaskGroupData

type TaskGroupData struct {
	Hosts []host.Host
	Info  model.TaskGroupInfo
}

type TaskList

type TaskList []task.Task

TaskList implements sort.Interface on top of a slice of tasks. The provided sorting, orders members of task groups, and then prioritizes tasks by the number of dependencies, priority, and expected duration. This sorting is used for ordering tasks within a unit.

func (TaskList) Len

func (tl TaskList) Len() int

func (TaskList) Less

func (tl TaskList) Less(i, j int) bool

func (TaskList) Swap

func (tl TaskList) Swap(i, j int)

type TaskPlan

type TaskPlan []*Unit

TaskPlan provides a sortable interface on top of a slice of schedulable units, with ordering of units provided by the implementation of RankValue.

func PrepareTasksForPlanning

func PrepareTasksForPlanning(distro *distro.Distro, tasks []task.Task) TaskPlan

PrepareTasksForPlanning takes a list of tasks for a distro and returns a TaskPlan, grouping tasks into the appropriate units.

func (TaskPlan) Export

func (tpl TaskPlan) Export() []task.Task

Export sorts the TaskPlan returning a unique list of tasks.

func (TaskPlan) Keys

func (tpl TaskPlan) Keys() []string

func (TaskPlan) Len

func (tpl TaskPlan) Len() int

func (TaskPlan) Less

func (tpl TaskPlan) Less(i, j int) bool

func (TaskPlan) Swap

func (tpl TaskPlan) Swap(i, j int)

type TaskPlanner

type TaskPlanner func(*distro.Distro, []task.Task, TaskPlannerOptions) ([]task.Task, error)

type TaskPlannerOptions

type TaskPlannerOptions struct {
	ID                   string
	IsSecondaryQueue     bool
	IncludesDependencies bool
	StartedAt            time.Time
}

type TaskPrioritizer

type TaskPrioritizer interface {
	// Takes in a slice of tasks and the current MCI settings.
	// Returns the slice of tasks, sorted in the order in which they should
	// be run, as well as an error if appropriate.
	PrioritizeTasks(distroId string, tasks []task.Task, versions map[string]model.Version) ([]task.Task, map[string]map[string]string, error)
}

TaskPrioritizer is responsible for taking in a slice of tasks, and ordering them according to which should be run first.

type Unit

type Unit struct {
	// contains filtered or unexported fields
}

Unit is a holder of a group of related tasks which should be scheculded together. Typically these represent task groups, tasks, and their dependencies, or even all tasks of a version. All tasks in a Unit must be unique with regards to their ID.

func MakeUnit

func MakeUnit(d *distro.Distro) *Unit

MakeuUnit constructs a new unit, caching a reference to the distro in the unit. It's valid to pass a nil here.

func NewUnit

func NewUnit(t task.Task) *Unit

NewUnit constructs a new Unit container for a task.

func (*Unit) Add

func (unit *Unit) Add(t task.Task)

Add caches a task in the unit.

func (*Unit) Export

func (unit *Unit) Export() TaskList

Export returns an unordered sequence of tasks from unit. All tasks are unique.

func (*Unit) ID

func (unit *Unit) ID() string

ID constructs a unique and hashed ID of all the tasks in the unit.

func (*Unit) Keys

func (unit *Unit) Keys() []string

Keys returns all of the ids of tasks in the unit.

func (*Unit) RankValue

func (unit *Unit) RankValue() int64

RankValue returns a point value for the tasks in the unit that can be used to compare units with each other.

Generally, higher point values are given to larger units and for units that have been in the queue for longer, with longer expected runtimes. The tasks' priority acts as a multiplying factor.

func (*Unit) SetDistro

func (unit *Unit) SetDistro(d *distro.Distro)

SetDistro makes it possible to change/set the cached distro reference in the unit; however, it is not possible to set a nil distro.

type UnitCache

type UnitCache map[string]*Unit

UnitCache stores an unordered collection of schedulable units. The Unit type holds one or more tasks, but is handled by the scheduler as a single object. While the constituent tasks in a unit have an order, the unit themselves are an intermediate abstraction for the planner which represent task groups, tasks with their dependencies, or the tasks from a single version

func (UnitCache) AddNew

func (cache UnitCache) AddNew(id string, unit *Unit)

AddNew adds an entire unit to a cache with the specified ID. If the cached item exists, AddNew extends the existing unit with the tasks from the passed unit.

func (UnitCache) AddWhen

func (cache UnitCache) AddWhen(cond bool, id string, t task.Task)

AddWhen wraps AddNew, and is a noop if the conditional is false.

func (UnitCache) Create

func (cache UnitCache) Create(id string, t task.Task) *Unit

Create makes a new unit around the existing task, caching it with the specified key, and returning the resulting unit. If there is an existing cache item with the specified ID, then Create extends that unit with this task. In both cases, the resulting unit is returned to the caller.

func (UnitCache) Exists

func (cache UnitCache) Exists(key string) bool

func (UnitCache) Export

func (cache UnitCache) Export() TaskPlan

Export returns an unordered sequence of unique Units.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL