Sorting based on watts value added. bin packing based on watts is almost complete.
This commit is contained in:
parent
cfbad349e1
commit
f349da4633
3 changed files with 287 additions and 25 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/mesos/mesos-go/mesosutil"
|
||||
sched "github.com/mesos/mesos-go/scheduler"
|
||||
"log"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
@ -51,6 +52,7 @@ type BinPackWatts struct {
|
|||
|
||||
// New electron scheduler
|
||||
func NewBinPackWatts(tasks []def.Task, ignoreWatts bool) *BinPackWatts {
|
||||
sort.Sort(def.WattsSorter(tasks))
|
||||
|
||||
s := &BinPackWatts{
|
||||
tasks: tasks,
|
||||
|
@ -142,9 +144,10 @@ func (s *BinPackWatts) ResourceOffers(driver sched.SchedulerDriver, offers []*me
|
|||
|
||||
tasks := []*mesos.TaskInfo{}
|
||||
|
||||
// First fit strategy
|
||||
_, _, offer_watts := OfferAgg(offer)
|
||||
|
||||
taken := false
|
||||
totalWatts := 0.0
|
||||
for i, task := range s.tasks {
|
||||
|
||||
// Check host if it exists
|
||||
|
@ -155,45 +158,46 @@ func (s *BinPackWatts) ResourceOffers(driver sched.SchedulerDriver, offers []*me
|
|||
}
|
||||
}
|
||||
|
||||
// Decision to take the offer or not
|
||||
if s.takeOffer(offer, task) {
|
||||
for *task.Instances > 0 {
|
||||
// Does the task fit
|
||||
if offer_watts >= (totalWatts + task.Watts) {
|
||||
|
||||
log.Println("Co-Located with: ")
|
||||
coLocated(s.running[offer.GetSlaveId().GoString()])
|
||||
taken = true
|
||||
totalWatts += task.Watts
|
||||
log.Println("Co-Located with: ")
|
||||
coLocated(s.running[offer.GetSlaveId().GoString()])
|
||||
tasks = append(tasks, s.newTask(offer, task))
|
||||
|
||||
tasks = append(tasks, s.newTask(offer, task))
|
||||
fmt.Println("Inst: ", *task.Instances)
|
||||
*task.Instances--
|
||||
|
||||
log.Printf("Starting %s on [%s]\n", task.Name, offer.GetHostname())
|
||||
driver.LaunchTasks([]*mesos.OfferID{offer.Id}, tasks, defaultFilter)
|
||||
if *task.Instances <= 0 {
|
||||
// All instances of task have been scheduled, remove it
|
||||
s.tasks = append(s.tasks[:i], s.tasks[i+1:]...)
|
||||
|
||||
taken = true
|
||||
|
||||
fmt.Println("Inst: ", *task.Instances)
|
||||
*task.Instances--
|
||||
|
||||
if *task.Instances <= 0 {
|
||||
// All instances of task have been scheduled, remove it
|
||||
s.tasks[i] = s.tasks[len(s.tasks)-1]
|
||||
s.tasks = s.tasks[:len(s.tasks)-1]
|
||||
|
||||
if len(s.tasks) <= 0 {
|
||||
log.Println("Done scheduling all tasks")
|
||||
close(s.Shutdown)
|
||||
if len(s.tasks) <= 0 {
|
||||
log.Println("Done scheduling all tasks")
|
||||
close(s.Shutdown)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break // Continue on to next offer
|
||||
}
|
||||
break // Offer taken, move on
|
||||
}
|
||||
}
|
||||
|
||||
// If there was no match for the task
|
||||
if !taken {
|
||||
if taken {
|
||||
log.Printf("Starting on [%s]\n", offer.GetHostname())
|
||||
driver.LaunchTasks([]*mesos.OfferID{offer.Id}, tasks, defaultFilter)
|
||||
} else {
|
||||
|
||||
// If there was no match for the task
|
||||
fmt.Println("There is not enough resources to launch a task:")
|
||||
cpus, mem, watts := OfferAgg(offer)
|
||||
|
||||
log.Printf("<CPU: %f, RAM: %f, Watts: %f>\n", cpus, mem, watts)
|
||||
driver.DeclineOffer(offer.Id, defaultFilter)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue