diff --git a/README.md b/README.md index d93a97c..2e0ee06 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ To Do: * Have a centralised logFile that can be filtered by identifier. All electron logs should go into this file. * Make def.Task an interface for further modularization and flexibility. * Convert def#WattsToConsider(...) to be a receiver of def.Task and change the name of it to Watts(...). - * Have a generic sorter for task resources instead of having one for each kind of resource. * **Critical** -- Add software requirements to the README.md (Mesos version, RAPL version, PCP version, Go version...) * **Critical** -- Retrofit to use Go 1.8 sorting techniques. Use def/taskUtils.go for reference. * Handle powerclass not configured on a node condition. As of now, an assumption is made that the powerclass is configured * Refine the sorting algorithm that sorts the clusters of tasks retrieved using the kmeans algorithm. This also involves the reduction in time complexity of the same. + * Use the generic task sorter in def/taskUtils.go to sort the tasks based on CPU or RAM etc. Remove the existing sorters present in def/task.go. for all the nodes. **Requires [Performance Co-Pilot](http://pcp.io/) tool pmdumptext to be installed on the diff --git a/def/sortingCriteria.go b/def/sortingCriteria.go new file mode 100644 index 0000000..e595266 --- /dev/null +++ b/def/sortingCriteria.go @@ -0,0 +1,13 @@ +package def + +// the sortBy function that takes a task reference and returns the resource to consider when sorting. +type sortBy func(task *Task) float64 + +// Possible Sorting Criteria +// Each holds a closure that fetches the required resource from the +// given task reference. +var ( + SortByCPU = func(task *Task) float64 { return task.CPU } + SortByRAM = func(task *Task) float64 { return task.RAM } + SortByWatts = func(task *Task) float64 { return task.Watts } +) diff --git a/def/taskUtils.go b/def/taskUtils.go index 2b56be3..733754e 100644 --- a/def/taskUtils.go +++ b/def/taskUtils.go @@ -2,8 +2,8 @@ package def import ( "github.com/mdesenfants/gokmeans" - "sort" "log" + "sort" ) // Information about a cluster of tasks @@ -114,3 +114,11 @@ func labelAndOrder(clusters map[int][]Task, numberOfClusters int, taskObservatio }) return sizedClusters } + +// Generic Task Sorter. +// Be able to sort an array of tasks based on any of the tasks' resources. +func SortTasks(ts []Task, sb sortBy) { + sort.SliceStable(ts, func(i, j int) bool { + return sb(&ts[i]) <= sb(&ts[j]) + }) +}