From 2cd77a7ba87413fea49e08fb12d9b1e3742e1ae3 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Sat, 28 Jan 2017 18:29:00 -0500 Subject: [PATCH] Changed Window to ConsiderationWindow. --- constants/constants.go | 4 ++-- pcp/proactiveclusterwidecappers.go | 2 +- utilities/runAvg/runAvg.go | 32 +++++++++++++++--------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/constants/constants.go b/constants/constants.go index efb8ed0..045c1a2 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -86,7 +86,7 @@ func UpdateCapMargin(newCapMargin float64) bool { var StarvationFactor = PowerThreshold / CapMargin // Window size for running average -var WindowSize = 20 +var ConsiderationWindowSize = 20 // Update the window size. func UpdateWindowSize(newWindowSize int) bool { @@ -94,7 +94,7 @@ func UpdateWindowSize(newWindowSize int) bool { if newWindowSize == 0 { return false } else { - WindowSize = newWindowSize + ConsiderationWindowSize = newWindowSize return true } } diff --git a/pcp/proactiveclusterwidecappers.go b/pcp/proactiveclusterwidecappers.go index ae90b61..acbe766 100644 --- a/pcp/proactiveclusterwidecappers.go +++ b/pcp/proactiveclusterwidecappers.go @@ -251,7 +251,7 @@ func (capper ClusterwideCapper) FCFSDeterminedCap(totalPower map[string]float64, return 100, errors.New("Invalid argument: totalPower") } else { // Need to calculate the running average - runningAverage := runAvg.Calc(taskWrapper{task: *newTask}, constants.WindowSize) + runningAverage := runAvg.Calc(taskWrapper{task: *newTask}, constants.ConsiderationWindowSize) // For each node, calculate the percentage of the running average to the total power. ratios := make(map[string]float64) for host, tpower := range totalPower { diff --git a/utilities/runAvg/runAvg.go b/utilities/runAvg/runAvg.go index 592929f..6c0d3b0 100644 --- a/utilities/runAvg/runAvg.go +++ b/utilities/runAvg/runAvg.go @@ -19,9 +19,9 @@ type Interface interface { } type runningAverageCalculator struct { - window list.List - windowSize int - currentSum float64 + considerationWindow list.List + considerationWindowSize int + currentSum float64 } // singleton instance @@ -31,14 +31,14 @@ var racSingleton *runningAverageCalculator func getInstance(curSum float64, wSize int) *runningAverageCalculator { if racSingleton == nil { racSingleton = &runningAverageCalculator{ - windowSize: wSize, + considerationWindowSize: wSize, currentSum: curSum, } return racSingleton } else { // Updating window size if a new window size is given. - if wSize != racSingleton.windowSize { - racSingleton.windowSize = wSize + if wSize != racSingleton.considerationWindowSize { + racSingleton.considerationWindowSize = wSize } return racSingleton } @@ -47,20 +47,20 @@ func getInstance(curSum float64, wSize int) *runningAverageCalculator { // Compute the running average by adding 'data' to the window. // Updating currentSum to get constant time complexity for every running average computation. func (rac *runningAverageCalculator) calculate(data Interface) float64 { - if rac.window.Len() < rac.windowSize { - rac.window.PushBack(data) + if rac.considerationWindow.Len() < rac.considerationWindowSize { + rac.considerationWindow.PushBack(data) rac.currentSum += data.Val() } else { // removing the element at the front of the window. - elementToRemove := rac.window.Front() + elementToRemove := rac.considerationWindow.Front() rac.currentSum -= elementToRemove.Value.(Interface).Val() - rac.window.Remove(elementToRemove) + rac.considerationWindow.Remove(elementToRemove) // adding new element to the window - rac.window.PushBack(data) + rac.considerationWindow.PushBack(data) rac.currentSum += data.Val() } - return rac.currentSum / float64(rac.window.Len()) + return rac.currentSum / float64(rac.considerationWindow.Len()) } /* @@ -68,9 +68,9 @@ If element with given ID present in the window, then remove it and return (remov Else, return (nil, error) */ func (rac *runningAverageCalculator) removeFromWindow(id string) (interface{}, error) { - for element := rac.window.Front(); element != nil; element = element.Next() { + for element := rac.considerationWindow.Front(); element != nil; element = element.Next() { if elementToRemove := element.Value.(Interface); elementToRemove.ID() == id { - rac.window.Remove(element) + rac.considerationWindow.Remove(element) rac.currentSum -= elementToRemove.Val() return elementToRemove, nil } @@ -102,7 +102,7 @@ func Init() { } // Setting parameters to default values. Could also set racSingleton to nil but this leads to unnecessary overhead of creating // another instance when Calc is called. - racSingleton.window.Init() - racSingleton.windowSize = 0 + racSingleton.considerationWindow.Init() + racSingleton.considerationWindowSize = 0 racSingleton.currentSum = 0.0 }