Changed Window to ConsiderationWindow.
This commit is contained in:
parent
916581067b
commit
2cd77a7ba8
3 changed files with 19 additions and 19 deletions
|
@ -86,7 +86,7 @@ func UpdateCapMargin(newCapMargin float64) bool {
|
||||||
var StarvationFactor = PowerThreshold / CapMargin
|
var StarvationFactor = PowerThreshold / CapMargin
|
||||||
|
|
||||||
// Window size for running average
|
// Window size for running average
|
||||||
var WindowSize = 20
|
var ConsiderationWindowSize = 20
|
||||||
|
|
||||||
// Update the window size.
|
// Update the window size.
|
||||||
func UpdateWindowSize(newWindowSize int) bool {
|
func UpdateWindowSize(newWindowSize int) bool {
|
||||||
|
@ -94,7 +94,7 @@ func UpdateWindowSize(newWindowSize int) bool {
|
||||||
if newWindowSize == 0 {
|
if newWindowSize == 0 {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
WindowSize = newWindowSize
|
ConsiderationWindowSize = newWindowSize
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ func (capper ClusterwideCapper) FCFSDeterminedCap(totalPower map[string]float64,
|
||||||
return 100, errors.New("Invalid argument: totalPower")
|
return 100, errors.New("Invalid argument: totalPower")
|
||||||
} else {
|
} else {
|
||||||
// Need to calculate the running average
|
// 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.
|
// For each node, calculate the percentage of the running average to the total power.
|
||||||
ratios := make(map[string]float64)
|
ratios := make(map[string]float64)
|
||||||
for host, tpower := range totalPower {
|
for host, tpower := range totalPower {
|
||||||
|
|
|
@ -19,9 +19,9 @@ type Interface interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type runningAverageCalculator struct {
|
type runningAverageCalculator struct {
|
||||||
window list.List
|
considerationWindow list.List
|
||||||
windowSize int
|
considerationWindowSize int
|
||||||
currentSum float64
|
currentSum float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// singleton instance
|
// singleton instance
|
||||||
|
@ -31,14 +31,14 @@ var racSingleton *runningAverageCalculator
|
||||||
func getInstance(curSum float64, wSize int) *runningAverageCalculator {
|
func getInstance(curSum float64, wSize int) *runningAverageCalculator {
|
||||||
if racSingleton == nil {
|
if racSingleton == nil {
|
||||||
racSingleton = &runningAverageCalculator{
|
racSingleton = &runningAverageCalculator{
|
||||||
windowSize: wSize,
|
considerationWindowSize: wSize,
|
||||||
currentSum: curSum,
|
currentSum: curSum,
|
||||||
}
|
}
|
||||||
return racSingleton
|
return racSingleton
|
||||||
} else {
|
} else {
|
||||||
// Updating window size if a new window size is given.
|
// Updating window size if a new window size is given.
|
||||||
if wSize != racSingleton.windowSize {
|
if wSize != racSingleton.considerationWindowSize {
|
||||||
racSingleton.windowSize = wSize
|
racSingleton.considerationWindowSize = wSize
|
||||||
}
|
}
|
||||||
return racSingleton
|
return racSingleton
|
||||||
}
|
}
|
||||||
|
@ -47,20 +47,20 @@ func getInstance(curSum float64, wSize int) *runningAverageCalculator {
|
||||||
// Compute the running average by adding 'data' to the window.
|
// Compute the running average by adding 'data' to the window.
|
||||||
// Updating currentSum to get constant time complexity for every running average computation.
|
// Updating currentSum to get constant time complexity for every running average computation.
|
||||||
func (rac *runningAverageCalculator) calculate(data Interface) float64 {
|
func (rac *runningAverageCalculator) calculate(data Interface) float64 {
|
||||||
if rac.window.Len() < rac.windowSize {
|
if rac.considerationWindow.Len() < rac.considerationWindowSize {
|
||||||
rac.window.PushBack(data)
|
rac.considerationWindow.PushBack(data)
|
||||||
rac.currentSum += data.Val()
|
rac.currentSum += data.Val()
|
||||||
} else {
|
} else {
|
||||||
// removing the element at the front of the window.
|
// removing the element at the front of the window.
|
||||||
elementToRemove := rac.window.Front()
|
elementToRemove := rac.considerationWindow.Front()
|
||||||
rac.currentSum -= elementToRemove.Value.(Interface).Val()
|
rac.currentSum -= elementToRemove.Value.(Interface).Val()
|
||||||
rac.window.Remove(elementToRemove)
|
rac.considerationWindow.Remove(elementToRemove)
|
||||||
|
|
||||||
// adding new element to the window
|
// adding new element to the window
|
||||||
rac.window.PushBack(data)
|
rac.considerationWindow.PushBack(data)
|
||||||
rac.currentSum += data.Val()
|
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)
|
Else, return (nil, error)
|
||||||
*/
|
*/
|
||||||
func (rac *runningAverageCalculator) removeFromWindow(id string) (interface{}, 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 {
|
if elementToRemove := element.Value.(Interface); elementToRemove.ID() == id {
|
||||||
rac.window.Remove(element)
|
rac.considerationWindow.Remove(element)
|
||||||
rac.currentSum -= elementToRemove.Val()
|
rac.currentSum -= elementToRemove.Val()
|
||||||
return elementToRemove, nil
|
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
|
// 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.
|
// another instance when Calc is called.
|
||||||
racSingleton.window.Init()
|
racSingleton.considerationWindow.Init()
|
||||||
racSingleton.windowSize = 0
|
racSingleton.considerationWindowSize = 0
|
||||||
racSingleton.currentSum = 0.0
|
racSingleton.currentSum = 0.0
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue