From 0135ee69e4ffb4350b1a4747463090a9723045c8 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 15:39:12 -0800 Subject: [PATCH 1/9] Added TODO to make the newTask(...) variadic --- schedulers/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/schedulers/README.md b/schedulers/README.md index 7492e56..f09b695 100644 --- a/schedulers/README.md +++ b/schedulers/README.md @@ -6,6 +6,7 @@ To Do: * Design changes -- Possible to have one scheduler with different scheduling schemes? * Fix the race condition on 'tasksRunning' in proactiveclusterwidecappingfcfs.go and proactiveclusterwidecappingranked.go * Separate the capping strategies from the scheduling algorithms and make it possible to use any capping strategy with any scheduler. + * Make newTask(...) variadic where the newTaskClass argument can either be given or not. If not give, then pick task.Watts as the watts attribute, else pick task.ClassToWatts[newTaskClass]. Scheduling Algorithms: From 270b5a7ee17f03dc576b23fee048b77d1ac8c511 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 15:41:13 -0800 Subject: [PATCH 2/9] Fixed bug. Now watts is taken from task.ClassMapWatts[nodeClass] and not task.Watts. Changed the function signature of newTask(...) to take in another parameter called newTaskClass that corresponds to the nodeClass. --- schedulers/bpswClassMapWatts.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/schedulers/bpswClassMapWatts.go b/schedulers/bpswClassMapWatts.go index 5307807..13bbdc7 100644 --- a/schedulers/bpswClassMapWatts.go +++ b/schedulers/bpswClassMapWatts.go @@ -66,7 +66,7 @@ func NewBPSWClassMapWatts(tasks []def.Task, ignoreWatts bool) *BPSWClassMapWatts return s } -func (s *BPSWClassMapWatts) newTask(offer *mesos.Offer, task def.Task) *mesos.TaskInfo { +func (s *BPSWClassMapWatts) newTask(offer *mesos.Offer, task def.Task, newTaskClass string) *mesos.TaskInfo { taskName := fmt.Sprintf("%s-%d", task.Name, *task.Instances) s.tasksCreated++ @@ -90,7 +90,7 @@ func (s *BPSWClassMapWatts) newTask(offer *mesos.Offer, task def.Task) *mesos.Ta } if !s.ignoreWatts { - resources = append(resources, mesosutil.NewScalarResource("watts", task.Watts)) + resources = append(resources, mesosutil.NewScalarResource("watts", task.ClassToWatts[newTaskClass])) } return &mesos.TaskInfo{ @@ -181,7 +181,7 @@ func (s *BPSWClassMapWatts) ResourceOffers(driver sched.SchedulerDriver, offers totalRAM += task.RAM 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, nodeClass)) fmt.Println("Inst: ", *task.Instances) *task.Instances-- From 86d91b3b5bef6599dc180d3abf936a01bdc46097 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 15:56:49 -0800 Subject: [PATCH 3/9] changed the CapMargin to 70 and Window to 20 as they are the optimal ones. --- constants/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constants/constants.go b/constants/constants.go index 08ad28a..bcd051b 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -68,7 +68,7 @@ func UpdateCapMargin(newCapMargin float64) bool { var StarvationFactor = PowerThreshold / CapMargin // Window size for running average -var WindowSize = 160 +var WindowSize = 20 // Update the window size. func UpdateWindowSize(newWindowSize int) bool { From 58bc24cb72e6cff3d6869a1e41a71e5774c2cbb2 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 15:57:08 -0800 Subject: [PATCH 4/9] Changed the scheduler to run --- scheduler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scheduler.go b/scheduler.go index bd7c943..20ce644 100644 --- a/scheduler.go +++ b/scheduler.go @@ -56,7 +56,7 @@ func main() { fmt.Println(task) } - scheduler := schedulers.NewPistonCapper(tasks, *ignoreWatts) + scheduler := schedulers.NewBPSWClassMapWatts(tasks, *ignoreWatts) driver, err := sched.NewMesosSchedulerDriver(sched.DriverConfig{ Master: *master, Framework: &mesos.FrameworkInfo{ From 678c113f0ae149cce90fd08390c824af73359b4d Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 16:01:18 -0800 Subject: [PATCH 5/9] Proactive Clusterwide Capping with BinPackedSortedWattsClassToWatts --- schedulers/bpswClassMapWattsProacCC.go | 428 +++++++++++++++++++++++++ 1 file changed, 428 insertions(+) create mode 100644 schedulers/bpswClassMapWattsProacCC.go diff --git a/schedulers/bpswClassMapWattsProacCC.go b/schedulers/bpswClassMapWattsProacCC.go new file mode 100644 index 0000000..1b62a66 --- /dev/null +++ b/schedulers/bpswClassMapWattsProacCC.go @@ -0,0 +1,428 @@ +package schedulers + +import ( + "bitbucket.org/sunybingcloud/electron/constants" + "bitbucket.org/sunybingcloud/electron/def" + "bitbucket.org/sunybingcloud/electron/pcp" + "bitbucket.org/sunybingcloud/electron/rapl" + "fmt" + "github.com/golang/protobuf/proto" + mesos "github.com/mesos/mesos-go/mesosproto" + "github.com/mesos/mesos-go/mesosutil" + sched "github.com/mesos/mesos-go/scheduler" + "log" + "math" + "strings" + "sync" + "time" + "sort" +) + +// Decides if to take an offer or not +func (*BPSWClassMapWattsProacCC) takeOffer(offer *mesos.Offer, task def.Task) bool { + cpus, mem, watts := OfferAgg(offer) + + // TODO: Insert watts calculation here instead of taking them as parameter + + if cpus >= task.CPU && mem >= task.RAM && watts >= task.Watts { + return true + } + + return false +} + +type BPSWClassMapWattsProacCC struct { + tasksCreated int + tasksRunning int + tasks []def.Task + metrics map[string]def.Metric + running map[string]map[string]bool + taskMonitor map[string][]def.Task + availablePower map[string]float64 + totalPower map[string]float64 + ignoreWatts bool + capper *pcp.ClusterwideCapper + ticker *time.Ticker + recapTicker *time.Ticker + isCapping bool // indicate whether we are currently performing cluster-wide capping. + isRecapping bool // indicate whether we are currently performing cluster-wide recapping. + + // First set of PCP values are garbage values, signal to logger to start recording when we're + // about to schedule a new task + RecordPCP bool + + // This channel is closed when the program receives an interrupt, + // signalling that the program should shut down + Shutdown chan struct{} + // This channel is closed after shutdown is closed, and only when all + // outstanding tasks have been cleaned up + Done chan struct{} + + // Controls when to shutdown pcp logging + PCPLog chan struct{} +} + +// New electron scheduler +func NewBPSWClassMapWattsProacCC(tasks []def.Task, ignoreWatts bool) *BPSWClassMapWattsProacCC { + sort.Sort(def.WattsSorter(tasks)) + + s := &BPSWClassMapWattsProacCC{ + tasks: tasks, + ignoreWatts: ignoreWatts, + Shutdown: make(chan struct{}), + Done: make(chan struct{}), + PCPLog: make(chan struct{}), + running: make(map[string]map[string]bool), + taskMonitor: make(map[string][]def.Task), + availablePower: make(map[string]float64), + totalPower: make(map[string]float64), + RecordPCP: false, + capper: pcp.GetClusterwideCapperInstance(), + ticker: time.NewTicker(10 * time.Second), + recapTicker: time.NewTicker(20 * time.Second), + isCapping: false, + isRecapping: false, + } + return s +} + +// mutex +var bpswClassMapWattsProacCCMutex sync.Mutex + +func (s *BPSWClassMapWattsProacCC) newTask(offer *mesos.Offer, task def.Task, newTaskClass string) *mesos.TaskInfo { + taskName := fmt.Sprintf("%s-%d", task.Name, *task.Instances) + s.tasksCreated++ + + if !s.RecordPCP { + // Turn on logging. + s.RecordPCP = true + time.Sleep(1 * time.Second) // Make sure we're recording by the time the first task starts + } + + // If this is our first time running into this Agent + if _, ok := s.running[offer.GetSlaveId().GoString()]; !ok { + s.running[offer.GetSlaveId().GoString()] = make(map[string]bool) + } + + // Setting the task ID to the task. This is done so that we can consider each task to be different, + // even though they have the same parameters. + task.SetTaskID(*proto.String("electron-" + taskName)) + // Add task to the list of tasks running on the node. + s.running[offer.GetSlaveId().GoString()][taskName] = true + if len(s.taskMonitor[*offer.Hostname]) == 0 { + s.taskMonitor[*offer.Hostname] = []def.Task{task} + } else { + s.taskMonitor[*offer.Hostname] = append(s.taskMonitor[*offer.Hostname], task) + } + + resources := []*mesos.Resource{ + mesosutil.NewScalarResource("cpus", task.CPU), + mesosutil.NewScalarResource("mem", task.RAM), + } + + if !s.ignoreWatts { + resources = append(resources, mesosutil.NewScalarResource("watts", task.ClassToWatts[newTaskClass])) + } + + return &mesos.TaskInfo{ + Name: proto.String(taskName), + TaskId: &mesos.TaskID{ + Value: proto.String("electron-" + taskName), + }, + SlaveId: offer.SlaveId, + Resources: resources, + Command: &mesos.CommandInfo{ + Value: proto.String(task.CMD), + }, + Container: &mesos.ContainerInfo{ + Type: mesos.ContainerInfo_DOCKER.Enum(), + Docker: &mesos.ContainerInfo_DockerInfo{ + Image: proto.String(task.Image), + Network: mesos.ContainerInfo_DockerInfo_BRIDGE.Enum(), // Run everything isolated + }, + }, + } +} + +func (s *BPSWClassMapWattsProacCC) Registered( + _ sched.SchedulerDriver, + frameworkID *mesos.FrameworkID, + masterInfo *mesos.MasterInfo) { + log.Printf("Framework %s registered with master %s", frameworkID, masterInfo) +} + +func (s *BPSWClassMapWattsProacCC) Reregistered(_ sched.SchedulerDriver, masterInfo *mesos.MasterInfo) { + log.Printf("Framework re-registered with master %s", masterInfo) +} + +func (s *BPSWClassMapWattsProacCC) Disconnected(sched.SchedulerDriver) { + // Need to stop the capping process + s.ticker.Stop() + s.recapTicker.Stop() + bpswClassMapWattsProacCCMutex.Lock() + s.isCapping = false + bpswClassMapWattsProacCCMutex.Unlock() + log.Println("Framework disconnected with master") +} + +// go routine to cap the entire cluster in regular intervals of time. +var bpswClassMapWattsCapValue = 0.0 // initial value to indicate that we haven't capped the cluster yet. +func (s *BPSWClassMapWattsProacCC) startCapping() { + go func() { + for { + select { + case <-s.ticker.C: + // Need to cap the cluster to the bpswClassMapWattsCapValue. + bpswClassMapWattsProacCCMutex.Lock() + if bpswClassMapWattsCapValue > 0.0 { + for _, host := range constants.Hosts { + // Rounding capValue to nearest int. + if err := rapl.Cap(host, "rapl", int(math.Floor(bpswClassMapWattsCapValue+0.5))); err != nil { + log.Println(err) + } + } + log.Printf("Capped the cluster to %d", int(math.Floor(bpswClassMapWattsCapValue+0.5))) + } + bpswClassMapWattsProacCCMutex.Unlock() + } + } + }() +} + +// go routine to recap the entire cluster in regular intervals of time. +var bpswClassMapWattsRecapValue = 0.0 // The cluster-wide cap value when recapping +func (s *BPSWClassMapWattsProacCC) startRecapping() { + go func() { + for { + select { + case <-s.recapTicker.C: + bpswClassMapWattsProacCCMutex.Lock() + // If stopped performing cluster wide capping, then we need to recap + if s.isRecapping && bpswClassMapWattsRecapValue > 0.0 { + for _, host := range constants.Hosts { + // Rounding capValue to the nearest int + if err := rapl.Cap(host, "rapl", int(math.Floor(bpswClassMapWattsRecapValue+0.5))); err != nil { + log.Println(err) + } + } + log.Printf("Recapping the cluster to %d", int(math.Floor(bpswClassMapWattsRecapValue+0.5))) + } + // Setting recapping to false + s.isRecapping = false + bpswClassMapWattsProacCCMutex.Unlock() + } + } + }() +} + +// Stop cluster wide capping +func (s *BPSWClassMapWattsProacCC) stopCapping() { + if s.isCapping { + log.Println("Stopping the cluster-wide capping.") + s.ticker.Stop() + bpswClassMapWattsProacCCMutex.Lock() + s.isCapping = false + s.isRecapping = true + bpswClassMapWattsProacCCMutex.Unlock() + } +} + +// Stop the cluster wide recapping +func (s *BPSWClassMapWattsProacCC) stopRecapping() { + // If not capping, then definitely recapping. + if !s.isCapping && s.isRecapping { + log.Println("Stopping the cluster-wide re-capping.") + s.recapTicker.Stop() + bpswClassMapWattsProacCCMutex.Lock() + s.isRecapping = false + bpswClassMapWattsProacCCMutex.Unlock() + } +} + +func (s *BPSWClassMapWattsProacCC) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) { + log.Printf("Received %d resource offers", len(offers)) + + // retrieving the available power for all the hosts in the offers. + for _, offer := range offers { + _, _, offerWatts := OfferAgg(offer) + s.availablePower[*offer.Hostname] = offerWatts + // setting total power if the first time + if _, ok := s.totalPower[*offer.Hostname]; !ok { + s.totalPower[*offer.Hostname] = offerWatts + } + } + + for host, tpower := range s.totalPower { + log.Printf("TotalPower[%s] = %f", host, tpower) + } + + for _, offer := range offers { + select { + case <-s.Shutdown: + log.Println("Done scheduling tasks: declining offer on [", offer.GetHostname(), "]") + driver.DeclineOffer(offer.Id, longFilter) + + log.Println("Number of tasks still running: ", s.tasksRunning) + continue + default: + } + + tasks := []*mesos.TaskInfo{} + + offerCPU, offerRAM, offerWatts := OfferAgg(offer) + + taken := false + totalWatts := 0.0 + totalCPU := 0.0 + totalRAM := 0.0 + for i, task := range s.tasks { + // Check host if it exists + if task.Host != "" { + // Don't take offer it it doesn't match our task's host requirement. + if strings.HasPrefix(*offer.Hostname, task.Host) { + continue + } + } + + for *task.Instances > 0 { + var nodeClass string + for _, attr := range offer.GetAttributes() { + if attr.GetName() == "class" { + nodeClass = attr.GetText().GetValue() + } + } + // Does the task fit + // OR Lazy evaluation. If ignore watts is set to true, second statement won't + // be evaluated. + if (s.ignoreWatts || (offerWatts >= (totalWatts + task.ClassToWatts[nodeClass]))) && + (offerCPU >= (totalCPU + task.CPU)) && + (offerRAM >= (totalRAM + task.RAM)) { + + // Capping the cluster if haven't yet started + if !s.isCapping { + bpswClassMapWattsProacCCMutex.Lock() + s.isCapping = true + bpswClassMapWattsProacCCMutex.Unlock() + s.startCapping() + } + + fmt.Println("Watts being used: ", task.ClassToWatts[nodeClass]) + tempCap, err := s.capper.FCFSDeterminedCap(s.totalPower, &task) + if err == nil { + bpswClassMapWattsProacCCMutex.Lock() + bpswClassMapWattsCapValue = tempCap + bpswClassMapWattsProacCCMutex.Unlock() + } else { + log.Println("Failed to determine new cluster-wide cap:") + log.Println(err) + } + taken = true + totalWatts += task.ClassToWatts[nodeClass] + totalCPU += task.CPU + totalRAM += task.RAM + log.Println("Co-Located with: ") + coLocated(s.running[offer.GetSlaveId().GoString()]) + tasks = append(tasks, s.newTask(offer, task, nodeClass)) + + fmt.Println("Inst: ", *task.Instances) + *task.Instances-- + + if *task.Instances <= 0 { + // All instances of task have been scheduled, remove it + s.tasks = append(s.tasks[:i], s.tasks[i+1:]...) + + if len(s.tasks) == 0 { + log.Println("Done scheduling all tasks.") + // Need to stop the cluster wide capping as there aren't any more tasks to schedule. + s.stopCapping() + s.startRecapping() // Load changes after every task finishes and hence, we need to change the capping of the cluster. + close(s.Shutdown) + } + } + } else { + break // Continue on to the next task + } + } + } + + 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("\n", cpus, mem, watts) + driver.DeclineOffer(offer.Id, defaultFilter) + } + } +} + +func (s *BPSWClassMapWattsProacCC) StatusUpdate(driver sched.SchedulerDriver, status *mesos.TaskStatus) { + log.Printf("Received task status [%s] for task [%s]", NameFor(status.State), *status.TaskId.Value) + + if *status.State == mesos.TaskState_TASK_RUNNING { + s.tasksRunning++ + } else if IsTerminal(status.State) { + delete(s.running[status.GetSlaveId().GoString()], *status.TaskId.Value) + // Need to remove the task from the window + s.capper.TaskFinished(*status.TaskId.Value) + // Determining the new cluster wide recap value + tempCap, err := s.capper.Recap(s.totalPower, s.taskMonitor, *status.TaskId.Value) + //tempCap, err := s.capper.CleverRecap(s.totalPower, s.taskMonitor, *status.TaskId.Value) + if err == nil { + // If new determined cap value is different from the current recap value, then we need to recap + if int(math.Floor(tempCap+0.5)) != int(math.Floor(bpswClassMapWattsRecapValue+0.5)) { + bpswClassMapWattsRecapValue = tempCap + bpswClassMapWattsProacCCMutex.Lock() + s.isRecapping = true + bpswClassMapWattsProacCCMutex.Unlock() + log.Printf("Determined re-cap value: %f\n", bpswClassMapWattsRecapValue) + } else { + bpswClassMapWattsProacCCMutex.Lock() + s.isRecapping = false + bpswClassMapWattsProacCCMutex.Unlock() + } + } else { + log.Println(err) + } + + s.tasksRunning-- + if s.tasksRunning == 0 { + select { + case <-s.Shutdown: + // Need to stop the cluster-wide recapping + s.stopRecapping() + close(s.Done) + default: + } + } + } + log.Printf("DONE: Task status [%s] for task[%s]", NameFor(status.State), *status.TaskId.Value) +} + +func (s *BPSWClassMapWattsProacCC) FrameworkMessage( + driver sched.SchedulerDriver, + executorID *mesos.ExecutorID, + slaveID *mesos.SlaveID, + message string) { + log.Println("Getting a framework message: ", message) + log.Printf("Received framework message from some unknown source: %s", *executorID.Value) +} + +func (s *BPSWClassMapWattsProacCC) OfferRescinded(_ sched.SchedulerDriver, offerID *mesos.OfferID) { + log.Printf("Offer %s rescinded", offerID) +} + +func (s *BPSWClassMapWattsProacCC) SlaveLost(_ sched.SchedulerDriver, slaveID *mesos.SlaveID) { + log.Printf("Slave %s lost", slaveID) +} + +func (s *BPSWClassMapWattsProacCC) ExecutorLost(_ sched.SchedulerDriver, executorID *mesos.ExecutorID, slaveID *mesos.SlaveID, status int) { + log.Printf("Executor %s on slave %s was lost", executorID, slaveID) +} + +func (s *BPSWClassMapWattsProacCC) Error(_ sched.SchedulerDriver, err string) { + log.Printf("Receiving an error: %s", err) +} From 20efe9252517f732a0d1d5e7b0b6c15ef16c54a3 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 16:01:45 -0800 Subject: [PATCH 6/9] Piston Capping with BinPackedSortedWattsClassToWatts --- schedulers/bpswClassMapWattsPistonCapping.go | 403 +++++++++++++++++++ 1 file changed, 403 insertions(+) create mode 100644 schedulers/bpswClassMapWattsPistonCapping.go diff --git a/schedulers/bpswClassMapWattsPistonCapping.go b/schedulers/bpswClassMapWattsPistonCapping.go new file mode 100644 index 0000000..114b204 --- /dev/null +++ b/schedulers/bpswClassMapWattsPistonCapping.go @@ -0,0 +1,403 @@ +package schedulers + +import ( + "bitbucket.org/sunybingcloud/electron/constants" + "bitbucket.org/sunybingcloud/electron/def" + "bitbucket.org/sunybingcloud/electron/rapl" + "errors" + "fmt" + "github.com/golang/protobuf/proto" + mesos "github.com/mesos/mesos-go/mesosproto" + "github.com/mesos/mesos-go/mesosutil" + sched "github.com/mesos/mesos-go/scheduler" + "log" + "math" + "sort" + "strings" + "sync" + "time" +) + +// Decides if to take offer or not +func (s *BPSWClassMapWattsPistonCapping) takeOffer(offer *mesos.Offer, task def.Task) bool { + cpus, mem, watts := OfferAgg(offer) + + //TODO: Insert watts calculation here instead of taking them as a parameter + + if cpus >= task.CPU && mem >= task.RAM && watts >= task.Watts { + return true + } + + return false +} + +type BPSWClassMapWattsPistonCapping struct { + tasksCreated int + tasksRunning int + tasks []def.Task + metrics map[string]def.Metric + running map[string]map[string]bool + taskMonitor map[string][]def.Task + totalPower map[string]float64 + ignoreWatts bool + ticker *time.Ticker + isCapping bool + + // First set of PCP values are garbage values, signal to logger to start recording when we're + // about to schedule the new task + RecordPCP bool + + // This channel is closed when the program receives an interrupt, + // signalling that program should shutdown + Shutdown chan struct{} + + // This channel is closed after shutdown is closed, and only when all + // outstanding tasks have been cleaned up + Done chan struct{} + + // Controls when to shutdown pcp logging + PCPLog chan struct{} +} + +// New electron scheduler +func NewBPSWClassMapWattsPistonCapping(tasks []def.Task, ignoreWatts bool) *BPSWClassMapWattsPistonCapping { + sort.Sort(def.WattsSorter(tasks)) + + s := &BPSWClassMapWattsPistonCapping{ + tasks: tasks, + ignoreWatts: ignoreWatts, + Shutdown: make(chan struct{}), + Done: make(chan struct{}), + PCPLog: make(chan struct{}), + running: make(map[string]map[string]bool), + taskMonitor: make(map[string][]def.Task), + totalPower: make(map[string]float64), + RecordPCP: false, + ticker: time.NewTicker(5 * time.Second), + isCapping: false, + } + return s +} + +func (s *BPSWClassMapWattsPistonCapping) newTask(offer *mesos.Offer, task def.Task, newTaskClass string) *mesos.TaskInfo { + taskName := fmt.Sprintf("%s-%d", task.Name, *task.Instances) + s.tasksCreated++ + + if !s.RecordPCP { + // Turn on logging + s.RecordPCP = true + time.Sleep(1 * time.Second) // Make sure we're recording by the time the first task starts + } + + // If this is our first time running into this Agent + if _, ok := s.running[offer.GetSlaveId().GoString()]; !ok { + s.running[offer.GetSlaveId().GoString()] = make(map[string]bool) + } + + // Setting the task ID to the task. This is done so that we can consider each task to be different + // even though they have the same parameters. + task.SetTaskID(*proto.String("electron-" + taskName)) + // Add task to list of tasks running on node + if len(s.taskMonitor[*offer.Hostname]) == 0 { + s.taskMonitor[*offer.Hostname] = []def.Task{task} + } else { + s.taskMonitor[*offer.Hostname] = append(s.taskMonitor[*offer.Hostname], task) + } + + resources := []*mesos.Resource{ + mesosutil.NewScalarResource("cpus", task.CPU), + mesosutil.NewScalarResource("mem", task.RAM), + } + + if !s.ignoreWatts { + resources = append(resources, mesosutil.NewScalarResource("watts", task.ClassToWatts[newTaskClass])) + } + + return &mesos.TaskInfo{ + Name: proto.String(taskName), + TaskId: &mesos.TaskID{ + Value: proto.String("electron-" + taskName), + }, + SlaveId: offer.SlaveId, + Resources: resources, + Command: &mesos.CommandInfo{ + Value: proto.String(task.CMD), + }, + Container: &mesos.ContainerInfo{ + Type: mesos.ContainerInfo_DOCKER.Enum(), + Docker: &mesos.ContainerInfo_DockerInfo{ + Image: proto.String(task.Image), + Network: mesos.ContainerInfo_DockerInfo_BRIDGE.Enum(), // Run everything isolated + }, + }, + } +} + +func (s *BPSWClassMapWattsPistonCapping) Registered( + _ sched.SchedulerDriver, + frameworkID *mesos.FrameworkID, + masterInfo *mesos.MasterInfo) { + log.Printf("Framework %s registered with master %s", frameworkID, masterInfo) +} + +func (s *BPSWClassMapWattsPistonCapping) Reregistered(_ sched.SchedulerDriver, masterInfo *mesos.MasterInfo) { + log.Printf("Framework re-registered with master %s", masterInfo) +} + +func (s *BPSWClassMapWattsPistonCapping) Disconnected(sched.SchedulerDriver) { + log.Println("Framework disconnected with master") +} + +// mutex +var bpswClassMapWattsPistonMutex sync.Mutex + +// go routine to cap eahc node in the cluster at regular intervals of time +var bpswClassMapWattsPistonCapValues = make(map[string]float64) + +// Storing the previous cap value for each host so as to not repeatedly cap the nodes to the same value. (reduces overhead) +var bpswClassMapWattsPistonPreviousRoundedCapValues = make(map[string]int) + +func (s *BPSWClassMapWattsPistonCapping) startCapping() { + go func() { + for { + select { + case <-s.ticker.C: + // Need to cap each node + bpswClassMapWattsPistonMutex.Lock() + for host, capValue := range bpswClassMapWattsPistonCapValues { + roundedCapValue := int(math.Floor(capValue + 0.5)) + // has the cap value changed + if previousRoundedCap, ok := bpswClassMapWattsPistonPreviousRoundedCapValues[host]; ok { + if previousRoundedCap != roundedCapValue { + if err := rapl.Cap(host, "rapl", roundedCapValue); err != nil { + log.Println(err) + } else { + log.Printf("Capped [%s] at %d", host, int(math.Floor(capValue))) + } + bpswClassMapWattsPistonPreviousRoundedCapValues[host] = roundedCapValue + } + } else { + if err := rapl.Cap(host, "rapl", roundedCapValue); err != nil { + log.Println(err) + } else { + log.Printf("Capped [%s] at %d", host, int(math.Floor(capValue+0.5))) + } + bpswClassMapWattsPistonPreviousRoundedCapValues[host] = roundedCapValue + } + } + bpswClassMapWattsPistonMutex.Unlock() + } + } + }() +} + +// Stop the capping +func (s *BPSWClassMapWattsPistonCapping) stopCapping() { + if s.isCapping { + log.Println("Stopping the capping.") + s.ticker.Stop() + bpswClassMapWattsPistonMutex.Lock() + s.isCapping = false + bpswClassMapWattsPistonMutex.Unlock() + } +} + +func (s *BPSWClassMapWattsPistonCapping) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) { + log.Printf("Received %d resource offers", len(offers)) + + // retrieving the total power for each host in the offers. + for _, offer := range offers { + if _, ok := s.totalPower[*offer.Hostname]; !ok { + _, _, offerWatts := OfferAgg(offer) + s.totalPower[*offer.Hostname] = offerWatts + } + } + + // Displaying the totalPower + for host, tpower := range s.totalPower { + log.Printf("TotalPower[%s] = %f", host, tpower) + } + + for _, offer := range offers { + select { + case <-s.Shutdown: + log.Println("Done scheduling tasks: declining offer on [", offer.GetHostname(), "]") + driver.DeclineOffer(offer.Id, longFilter) + + log.Println("Number of tasks still running: ", s.tasksRunning) + continue + default: + } + + tasks := []*mesos.TaskInfo{} + + offerCPU, offerRAM, offerWatts := OfferAgg(offer) + + taken := false + totalWatts := 0.0 + totalCPU := 0.0 + totalRAM := 0.0 + // Store the partialLoad for host corresponding to this offer + // Once we can't fit any more tasks, we update the capValue for this host with partialLoad and then launch the fitted tasks. + partialLoad := 0.0 + for i, task := range s.tasks { + + // Check host if it exists + if task.Host != "" { + // Don't take offer if it doesn't match our task's host requirement + if !strings.HasPrefix(*offer.Hostname, task.Host) { + continue + } + } + + for *task.Instances > 0 { + var nodeClass string + for _, attr := range offer.GetAttributes() { + if attr.GetName() == "class" { + nodeClass = attr.GetText().GetValue() + } + } + // Does the task fit + // OR lazy evaluation. If ignoreWatts is set to true, second statement won't + // be evaluated + if (s.ignoreWatts || (offerWatts >= (totalWatts + task.ClassToWatts[nodeClass]))) && + (offerCPU >= (totalCPU + task.CPU)) && + (offerRAM >= (totalRAM + task.RAM)) { + + fmt.Println("Watts being used: ", task.ClassToWatts[nodeClass]) + taken = true + totalWatts += task.ClassToWatts[nodeClass] + totalCPU += task.CPU + totalRAM += task.RAM + log.Println("Co-Located with: ") + coLocated(s.running[offer.GetSlaveId().GoString()]) + tasks = append(tasks, s.newTask(offer, task, nodeClass)) + + fmt.Println("Inst: ", *task.Instances) + *task.Instances-- + partialLoad += ((task.Watts * constants.CapMargin) / s.totalPower[*offer.Hostname]) * 100 + + if *task.Instances <= 0 { + // All instances of task have been scheduled. Remove it + s.tasks = append(s.tasks[:i], s.tasks[i+1:]...) + if len(s.tasks) <= 0 { + log.Println("Done scheduling all tasks") + close(s.Shutdown) + } + } + } else { + break // Continue on to the next task + } + } + } + + if taken { + // Updating the cap value for offer.Hostname + bpswClassMapWattsPistonMutex.Lock() + bpswClassMapWattsPistonCapValues[*offer.Hostname] += partialLoad + bpswClassMapWattsPistonMutex.Unlock() + log.Printf("Starting on [%s]\n", offer.GetHostname()) + driver.LaunchTasks([]*mesos.OfferID{offer.Id}, tasks, defaultFilter) + } else { + // If there was no match for task + log.Println("There is not enough resources to launch task: ") + cpus, mem, watts := OfferAgg(offer) + + log.Printf("\n", cpus, mem, watts) + driver.DeclineOffer(offer.Id, defaultFilter) + } + } +} + +// Remove finished task from the taskMonitor +func (s *BPSWClassMapWattsPistonCapping) deleteFromTaskMonitor(finishedTaskID string) (def.Task, string, error) { + hostOfFinishedTask := "" + indexOfFinishedTask := -1 + found := false + var finishedTask def.Task + + for host, tasks := range s.taskMonitor { + for i, task := range tasks { + if task.TaskID == finishedTaskID { + hostOfFinishedTask = host + indexOfFinishedTask = i + found = true + } + } + if found { + break + } + } + + if hostOfFinishedTask != "" && indexOfFinishedTask != -1 { + finishedTask = s.taskMonitor[hostOfFinishedTask][indexOfFinishedTask] + log.Printf("Removing task with TaskID [%s] from the list of running tasks\n", + s.taskMonitor[hostOfFinishedTask][indexOfFinishedTask].TaskID) + s.taskMonitor[hostOfFinishedTask] = append(s.taskMonitor[hostOfFinishedTask][:indexOfFinishedTask], + s.taskMonitor[hostOfFinishedTask][indexOfFinishedTask+1:]...) + } else { + return finishedTask, hostOfFinishedTask, errors.New("Finished Task not present in TaskMonitor") + } + return finishedTask, hostOfFinishedTask, nil +} + +func (s *BPSWClassMapWattsPistonCapping) StatusUpdate(driver sched.SchedulerDriver, status *mesos.TaskStatus) { + log.Printf("Received task status [%s] for task [%s]\n", NameFor(status.State), *status.TaskId.Value) + + if *status.State == mesos.TaskState_TASK_RUNNING { + bpswClassMapWattsPistonMutex.Lock() + s.tasksRunning++ + bpswClassMapWattsPistonMutex.Unlock() + } else if IsTerminal(status.State) { + delete(s.running[status.GetSlaveId().GoString()], *status.TaskId.Value) + // Deleting the task from the taskMonitor + finishedTask, hostOfFinishedTask, err := s.deleteFromTaskMonitor(*status.TaskId.Value) + if err != nil { + log.Println(err) + } + + // Need to update the cap values for host of the finishedTask + bpswClassMapWattsPistonMutex.Lock() + bpswClassMapWattsPistonCapValues[hostOfFinishedTask] -= ((finishedTask.Watts * constants.CapMargin) / s.totalPower[hostOfFinishedTask]) * 100 + // Checking to see if the cap value has become 0, in which case we uncap the host. + if int(math.Floor(bpswClassMapWattsPistonCapValues[hostOfFinishedTask]+0.5)) == 0 { + bpswClassMapWattsPistonCapValues[hostOfFinishedTask] = 100 + } + s.tasksRunning-- + bpswClassMapWattsPistonMutex.Unlock() + + if s.tasksRunning == 0 { + select { + case <-s.Shutdown: + s.stopCapping() + close(s.Done) + default: + } + } + } + log.Printf("DONE: Task status [%s] for task [%s]", NameFor(status.State), *status.TaskId.Value) +} + +func (s *BPSWClassMapWattsPistonCapping) FrameworkMessage( + driver sched.SchedulerDriver, + executorID *mesos.ExecutorID, + slaveID *mesos.SlaveID, + message string) { + + log.Println("Getting a framework message: ", message) + log.Printf("Received a framework message from some unknown source: %s", *executorID.Value) +} + +func (s *BPSWClassMapWattsPistonCapping) OfferRescinded(_ sched.SchedulerDriver, offerID *mesos.OfferID) { + log.Printf("Offer %s rescinded", offerID) +} +func (s *BPSWClassMapWattsPistonCapping) SlaveLost(_ sched.SchedulerDriver, slaveID *mesos.SlaveID) { + log.Printf("Slave %s lost", slaveID) +} +func (s *BPSWClassMapWattsPistonCapping) ExecutorLost(_ sched.SchedulerDriver, executorID *mesos.ExecutorID, slaveID *mesos.SlaveID, status int) { + log.Printf("Executor %s on slave %s was lost", executorID, slaveID) +} + +func (s *BPSWClassMapWattsPistonCapping) Error(_ sched.SchedulerDriver, err string) { + log.Printf("Receiving an error: %s", err) +} From 118e0a571adc1a437372be5ce40c0938ba671318 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 16:46:31 -0800 Subject: [PATCH 7/9] changed scheduler to BPSWClassMapWatts. Also, capping is extrema. --- scheduler.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scheduler.go b/scheduler.go index 32f843a..4a45608 100644 --- a/scheduler.go +++ b/scheduler.go @@ -58,7 +58,7 @@ func main() { startTime := time.Now().Format("20060102150405") logPrefix := *pcplogPrefix + "_" + startTime - scheduler := schedulers.NewBPSWClassMapWatts(tasks, *ignoreWatts) + scheduler := schedulers.NewBPSWClassMapWatts(tasks, *ignoreWatts, logPrefix) driver, err := sched.NewMesosSchedulerDriver(sched.DriverConfig{ Master: *master, Framework: &mesos.FrameworkInfo{ @@ -72,8 +72,8 @@ func main() { return } - go pcp.Start(scheduler.PCPLog, &scheduler.RecordPCP, logPrefix) - //go pcp.StartLogAndDynamicCap(scheduler.PCPLog, &scheduler.RecordPCP, logPrefix, *hiThreshold, *loThreshold) + //go pcp.Start(scheduler.PCPLog, &scheduler.RecordPCP, logPrefix) + go pcp.StartLogAndDynamicCap(scheduler.PCPLog, &scheduler.RecordPCP, logPrefix, *hiThreshold, *loThreshold) time.Sleep(1 * time.Second) // Take a second between starting PCP log and continuing // Attempt to handle signint to not leave pmdumptext running From 722bd233e35598779d7d2cfc866a7a87f64cdd84 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 16:47:59 -0800 Subject: [PATCH 8/9] Used composition to use common functions from base.go. Also incorporated schedTrace and made the necessary changes to the constructor --- schedulers/bpswClassMapWatts.go | 55 +++++++++------------------------ 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/schedulers/bpswClassMapWatts.go b/schedulers/bpswClassMapWatts.go index 6a190f7..f3167ac 100644 --- a/schedulers/bpswClassMapWatts.go +++ b/schedulers/bpswClassMapWatts.go @@ -8,6 +8,7 @@ import ( "github.com/mesos/mesos-go/mesosutil" sched "github.com/mesos/mesos-go/scheduler" "log" + "os" "sort" "strings" "time" @@ -28,6 +29,7 @@ func (*BPSWClassMapWatts) takeOffer(offer *mesos.Offer, task def.Task) bool { } type BPSWClassMapWatts struct { + base // Type embedded to inherit common functions tasksCreated int tasksRunning int tasks []def.Task @@ -48,12 +50,19 @@ type BPSWClassMapWatts struct { // Controls when to shutdown pcp logging PCPLog chan struct{} + + schedTrace *log.Logger } // New electron scheduler -func NewBPSWClassMapWatts(tasks []def.Task, ignoreWatts bool) *BPSWClassMapWatts { +func NewBPSWClassMapWatts(tasks []def.Task, ignoreWatts bool, schedTracePrefix string) *BPSWClassMapWatts { sort.Sort(def.WattsSorter(tasks)) + logFile, err := os.Create("./" + schedTracePrefix + "_schedTrace.log") + if err != nil { + log.Fatal(err) + } + s := &BPSWClassMapWatts{ tasks: tasks, ignoreWatts: ignoreWatts, @@ -62,6 +71,7 @@ func NewBPSWClassMapWatts(tasks []def.Task, ignoreWatts bool) *BPSWClassMapWatts PCPLog: make(chan struct{}), running: make(map[string]map[string]bool), RecordPCP: false, + schedTrace: log.New(logFile, "", log.LstdFlags), } return s } @@ -113,21 +123,6 @@ func (s *BPSWClassMapWatts) newTask(offer *mesos.Offer, task def.Task, newTaskCl } } -func (s *BPSWClassMapWatts) Registered( - _ sched.SchedulerDriver, - frameworkID *mesos.FrameworkID, - masterInfo *mesos.MasterInfo) { - log.Printf("Framework %s registered with master %s", frameworkID, masterInfo) -} - -func (s *BPSWClassMapWatts) Reregistered(_ sched.SchedulerDriver, masterInfo *mesos.MasterInfo) { - log.Printf("Framework re-registered with master %s", masterInfo) -} - -func (s *BPSWClassMapWatts) Disconnected(sched.SchedulerDriver) { - log.Println("Framework disconnected with master") -} - func (s *BPSWClassMapWatts) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) { log.Printf("Received %d resource offers", len(offers)) @@ -181,9 +176,11 @@ func (s *BPSWClassMapWatts) ResourceOffers(driver sched.SchedulerDriver, offers totalRAM += task.RAM log.Println("Co-Located with: ") coLocated(s.running[offer.GetSlaveId().GoString()]) - tasks = append(tasks, s.newTask(offer, task, nodeClass)) + taskToSchedule := s.newTask(offer, task, nodeClass) + tasks = append(tasks, taskToSchedule) fmt.Println("Inst: ", *task.Instances) + s.schedTrace.Print(offer.GetHostname() + ":" + taskToSchedule.GetTaskId().GetValue()) *task.Instances-- if *task.Instances <= 0 { @@ -234,27 +231,3 @@ func (s *BPSWClassMapWatts) StatusUpdate(driver sched.SchedulerDriver, status *m } log.Printf("DONE: Task status [%s] for task [%s]", NameFor(status.State), *status.TaskId.Value) } - -func (s *BPSWClassMapWatts) FrameworkMessage( - driver sched.SchedulerDriver, - executorID *mesos.ExecutorID, - slaveID *mesos.SlaveID, - message string) { - - log.Println("Getting a framework message: ", message) - log.Printf("Received a framework message from some unknown source: %s", *executorID.Value) -} - -func (s *BPSWClassMapWatts) OfferRescinded(_ sched.SchedulerDriver, offerID *mesos.OfferID) { - log.Printf("Offer %s rescinded", offerID) -} -func (s *BPSWClassMapWatts) SlaveLost(_ sched.SchedulerDriver, slaveID *mesos.SlaveID) { - log.Printf("Slave %s lost", slaveID) -} -func (s *BPSWClassMapWatts) ExecutorLost(_ sched.SchedulerDriver, executorID *mesos.ExecutorID, slaveID *mesos.SlaveID, status int) { - log.Printf("Executor %s on slave %s was lost", executorID, slaveID) -} - -func (s *BPSWClassMapWatts) Error(_ sched.SchedulerDriver, err string) { - log.Printf("Receiving an error: %s", err) -} From a0f911e4e455e49218f25a14bba73e453f8449be Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Fri, 6 Jan 2017 16:49:00 -0800 Subject: [PATCH 9/9] Used composition to use common functions from base.go. Also incorporated schedTrace and made the necessary changes to the constructor --- schedulers/bpswClassMapWattsPistonCapping.go | 56 +++++++------------- schedulers/bpswClassMapWattsProacCC.go | 56 ++++++-------------- 2 files changed, 35 insertions(+), 77 deletions(-) diff --git a/schedulers/bpswClassMapWattsPistonCapping.go b/schedulers/bpswClassMapWattsPistonCapping.go index 114b204..9f725e4 100644 --- a/schedulers/bpswClassMapWattsPistonCapping.go +++ b/schedulers/bpswClassMapWattsPistonCapping.go @@ -12,6 +12,7 @@ import ( sched "github.com/mesos/mesos-go/scheduler" "log" "math" + "os" "sort" "strings" "sync" @@ -32,6 +33,7 @@ func (s *BPSWClassMapWattsPistonCapping) takeOffer(offer *mesos.Offer, task def. } type BPSWClassMapWattsPistonCapping struct { + base // Type embedded to inherit common functions tasksCreated int tasksRunning int tasks []def.Task @@ -57,12 +59,19 @@ type BPSWClassMapWattsPistonCapping struct { // Controls when to shutdown pcp logging PCPLog chan struct{} + + schedTrace *log.Logger } // New electron scheduler -func NewBPSWClassMapWattsPistonCapping(tasks []def.Task, ignoreWatts bool) *BPSWClassMapWattsPistonCapping { +func NewBPSWClassMapWattsPistonCapping(tasks []def.Task, ignoreWatts bool, schedTracePrefix string) *BPSWClassMapWattsPistonCapping { sort.Sort(def.WattsSorter(tasks)) + logFile, err := os.Create("./" + schedTracePrefix + "_schedTrace.log") + if err != nil { + log.Fatal(err) + } + s := &BPSWClassMapWattsPistonCapping{ tasks: tasks, ignoreWatts: ignoreWatts, @@ -75,6 +84,7 @@ func NewBPSWClassMapWattsPistonCapping(tasks []def.Task, ignoreWatts bool) *BPSW RecordPCP: false, ticker: time.NewTicker(5 * time.Second), isCapping: false, + schedTrace: log.New(logFile, "", log.LstdFlags), } return s } @@ -133,18 +143,12 @@ func (s *BPSWClassMapWattsPistonCapping) newTask(offer *mesos.Offer, task def.Ta } } -func (s *BPSWClassMapWattsPistonCapping) Registered( - _ sched.SchedulerDriver, - frameworkID *mesos.FrameworkID, - masterInfo *mesos.MasterInfo) { - log.Printf("Framework %s registered with master %s", frameworkID, masterInfo) -} - -func (s *BPSWClassMapWattsPistonCapping) Reregistered(_ sched.SchedulerDriver, masterInfo *mesos.MasterInfo) { - log.Printf("Framework re-registered with master %s", masterInfo) -} - func (s *BPSWClassMapWattsPistonCapping) Disconnected(sched.SchedulerDriver) { + // Need to stop the capping process + s.ticker.Stop() + bpswClassMapWattsPistonMutex.Lock() + s.isCapping = false + bpswClassMapWattsPistonMutex.Unlock() log.Println("Framework disconnected with master") } @@ -271,9 +275,11 @@ func (s *BPSWClassMapWattsPistonCapping) ResourceOffers(driver sched.SchedulerDr totalRAM += task.RAM log.Println("Co-Located with: ") coLocated(s.running[offer.GetSlaveId().GoString()]) - tasks = append(tasks, s.newTask(offer, task, nodeClass)) + taskToSchedule := s.newTask(offer, task, nodeClass) + tasks = append(tasks, taskToSchedule) fmt.Println("Inst: ", *task.Instances) + s.schedTrace.Print(offer.GetHostname() + ":" + taskToSchedule.GetTaskId().GetValue()) *task.Instances-- partialLoad += ((task.Watts * constants.CapMargin) / s.totalPower[*offer.Hostname]) * 100 @@ -377,27 +383,3 @@ func (s *BPSWClassMapWattsPistonCapping) StatusUpdate(driver sched.SchedulerDriv } log.Printf("DONE: Task status [%s] for task [%s]", NameFor(status.State), *status.TaskId.Value) } - -func (s *BPSWClassMapWattsPistonCapping) FrameworkMessage( - driver sched.SchedulerDriver, - executorID *mesos.ExecutorID, - slaveID *mesos.SlaveID, - message string) { - - log.Println("Getting a framework message: ", message) - log.Printf("Received a framework message from some unknown source: %s", *executorID.Value) -} - -func (s *BPSWClassMapWattsPistonCapping) OfferRescinded(_ sched.SchedulerDriver, offerID *mesos.OfferID) { - log.Printf("Offer %s rescinded", offerID) -} -func (s *BPSWClassMapWattsPistonCapping) SlaveLost(_ sched.SchedulerDriver, slaveID *mesos.SlaveID) { - log.Printf("Slave %s lost", slaveID) -} -func (s *BPSWClassMapWattsPistonCapping) ExecutorLost(_ sched.SchedulerDriver, executorID *mesos.ExecutorID, slaveID *mesos.SlaveID, status int) { - log.Printf("Executor %s on slave %s was lost", executorID, slaveID) -} - -func (s *BPSWClassMapWattsPistonCapping) Error(_ sched.SchedulerDriver, err string) { - log.Printf("Receiving an error: %s", err) -} diff --git a/schedulers/bpswClassMapWattsProacCC.go b/schedulers/bpswClassMapWattsProacCC.go index 1b62a66..cd21b03 100644 --- a/schedulers/bpswClassMapWattsProacCC.go +++ b/schedulers/bpswClassMapWattsProacCC.go @@ -12,10 +12,11 @@ import ( sched "github.com/mesos/mesos-go/scheduler" "log" "math" + "os" + "sort" "strings" "sync" "time" - "sort" ) // Decides if to take an offer or not @@ -32,6 +33,7 @@ func (*BPSWClassMapWattsProacCC) takeOffer(offer *mesos.Offer, task def.Task) bo } type BPSWClassMapWattsProacCC struct { + base // Type embedding to inherit common functions tasksCreated int tasksRunning int tasks []def.Task @@ -60,12 +62,19 @@ type BPSWClassMapWattsProacCC struct { // Controls when to shutdown pcp logging PCPLog chan struct{} + + schedTrace *log.Logger } // New electron scheduler -func NewBPSWClassMapWattsProacCC(tasks []def.Task, ignoreWatts bool) *BPSWClassMapWattsProacCC { +func NewBPSWClassMapWattsProacCC(tasks []def.Task, ignoreWatts bool, schedTracePrefix string) *BPSWClassMapWattsProacCC { sort.Sort(def.WattsSorter(tasks)) + logFile, err := os.Create("./" + schedTracePrefix + "_schedTrace.log") + if err != nil { + log.Fatal(err) + } + s := &BPSWClassMapWattsProacCC{ tasks: tasks, ignoreWatts: ignoreWatts, @@ -82,6 +91,7 @@ func NewBPSWClassMapWattsProacCC(tasks []def.Task, ignoreWatts bool) *BPSWClassM recapTicker: time.NewTicker(20 * time.Second), isCapping: false, isRecapping: false, + schedTrace: log.New(logFile, "", log.LstdFlags), } return s } @@ -144,17 +154,6 @@ func (s *BPSWClassMapWattsProacCC) newTask(offer *mesos.Offer, task def.Task, ne } } -func (s *BPSWClassMapWattsProacCC) Registered( - _ sched.SchedulerDriver, - frameworkID *mesos.FrameworkID, - masterInfo *mesos.MasterInfo) { - log.Printf("Framework %s registered with master %s", frameworkID, masterInfo) -} - -func (s *BPSWClassMapWattsProacCC) Reregistered(_ sched.SchedulerDriver, masterInfo *mesos.MasterInfo) { - log.Printf("Framework re-registered with master %s", masterInfo) -} - func (s *BPSWClassMapWattsProacCC) Disconnected(sched.SchedulerDriver) { // Need to stop the capping process s.ticker.Stop() @@ -322,9 +321,11 @@ func (s *BPSWClassMapWattsProacCC) ResourceOffers(driver sched.SchedulerDriver, totalRAM += task.RAM log.Println("Co-Located with: ") coLocated(s.running[offer.GetSlaveId().GoString()]) - tasks = append(tasks, s.newTask(offer, task, nodeClass)) + taskToSchedule := s.newTask(offer, task, nodeClass) + tasks = append(tasks, taskToSchedule) fmt.Println("Inst: ", *task.Instances) + s.schedTrace.Print(offer.GetHostname() + ":" + taskToSchedule.GetTaskId().GetValue()) *task.Instances-- if *task.Instances <= 0 { @@ -369,7 +370,7 @@ func (s *BPSWClassMapWattsProacCC) StatusUpdate(driver sched.SchedulerDriver, st // Need to remove the task from the window s.capper.TaskFinished(*status.TaskId.Value) // Determining the new cluster wide recap value - tempCap, err := s.capper.Recap(s.totalPower, s.taskMonitor, *status.TaskId.Value) + tempCap, err := s.capper.CleverRecap(s.totalPower, s.taskMonitor, *status.TaskId.Value) //tempCap, err := s.capper.CleverRecap(s.totalPower, s.taskMonitor, *status.TaskId.Value) if err == nil { // If new determined cap value is different from the current recap value, then we need to recap @@ -401,28 +402,3 @@ func (s *BPSWClassMapWattsProacCC) StatusUpdate(driver sched.SchedulerDriver, st } log.Printf("DONE: Task status [%s] for task[%s]", NameFor(status.State), *status.TaskId.Value) } - -func (s *BPSWClassMapWattsProacCC) FrameworkMessage( - driver sched.SchedulerDriver, - executorID *mesos.ExecutorID, - slaveID *mesos.SlaveID, - message string) { - log.Println("Getting a framework message: ", message) - log.Printf("Received framework message from some unknown source: %s", *executorID.Value) -} - -func (s *BPSWClassMapWattsProacCC) OfferRescinded(_ sched.SchedulerDriver, offerID *mesos.OfferID) { - log.Printf("Offer %s rescinded", offerID) -} - -func (s *BPSWClassMapWattsProacCC) SlaveLost(_ sched.SchedulerDriver, slaveID *mesos.SlaveID) { - log.Printf("Slave %s lost", slaveID) -} - -func (s *BPSWClassMapWattsProacCC) ExecutorLost(_ sched.SchedulerDriver, executorID *mesos.ExecutorID, slaveID *mesos.SlaveID, status int) { - log.Printf("Executor %s on slave %s was lost", executorID, slaveID) -} - -func (s *BPSWClassMapWattsProacCC) Error(_ sched.SchedulerDriver, err string) { - log.Printf("Receiving an error: %s", err) -}