fixed bugs. Made sure that we don't cap a victim below the threshold. Made sure the victims the can be capped and uncapped are maintained in both cappedVictims and orderCappedVictims.

This commit is contained in:
Pradyumna Kaushik 2017-02-21 21:05:47 -05:00
parent 531c1a120b
commit 373ba63933

View file

@ -26,12 +26,6 @@ func getNextCapValue(curCapValue float64, precision int) float64 {
return float64(round(curCapValue*output)) / output return float64(round(curCapValue*output)) / output
} }
func getNextUncapValue(curCapValue float64, precision int) float64 {
curCapValue *= 2.0
output := math.Pow(10, float64(precision))
return float64(round(curCapValue*output)) / output
}
func StartPCPLogAndProgressiveExtremaCap(quit chan struct{}, logging *bool, prefix string, hiThreshold, loThreshold float64) { func StartPCPLogAndProgressiveExtremaCap(quit chan struct{}, logging *bool, prefix string, hiThreshold, loThreshold float64) {
log.Println("Inside Log and Progressive Extrema") log.Println("Inside Log and Progressive Extrema")
const pcpCommand string = "pmdumptext -m -l -f '' -t 1.0 -d , -c config" const pcpCommand string = "pmdumptext -m -l -f '' -t 1.0 -d , -c config"
@ -128,6 +122,8 @@ func StartPCPLogAndProgressiveExtremaCap(quit chan struct{}, logging *bool, pref
if clusterMean >= hiThreshold { if clusterMean >= hiThreshold {
log.Println("Need to cap a node") log.Println("Need to cap a node")
log.Println(cappedVictims)
log.Println(orderCappedVictims)
// Create statics for all victims and choose one to cap // Create statics for all victims and choose one to cap
victims := make([]Victim, 0, 8) victims := make([]Victim, 0, 8)
@ -148,10 +144,8 @@ func StartPCPLogAndProgressiveExtremaCap(quit chan struct{}, logging *bool, pref
for i := 0; i < len(victims); i++ { for i := 0; i < len(victims); i++ {
// Try to pick a victim that hasn't been capped yet. // Try to pick a victim that hasn't been capped yet.
if _, ok := cappedVictims[victims[i].Host]; !ok { if _, ok := cappedVictims[victims[i].Host]; !ok {
// If this victim is present in orderCapped, then we move on to find another victim that we can cap. // If this victim can't be capped further, then we move on to find another victim that we can cap.
if _, ok := orderCappedVictims[victims[i].Host]; ok { if _, ok := orderCappedVictims[victims[i].Host]; ok {
// Adding the host to the alreadyCappedHosts
alreadyCappedHosts = append(alreadyCappedHosts, victims[i].Host)
continue continue
} }
// Need to cap this victim and add it to the cappedVictims // Need to cap this victim and add it to the cappedVictims
@ -173,90 +167,65 @@ func StartPCPLogAndProgressiveExtremaCap(quit chan struct{}, logging *bool, pref
// If no new victim found, then we need to cap the best victim among the already capped victims // If no new victim found, then we need to cap the best victim among the already capped victims
if !newVictimFound { if !newVictimFound {
for i := 0; i < len(alreadyCappedHosts); i++ { for i := 0; i < len(alreadyCappedHosts); i++ {
// Checking if this node can be uncapped too // If already capped then the host must be present in orderCappedVictims
if capValue, ok := orderCappedVictims[alreadyCappedHosts[i]]; ok { capValue := orderCappedVictims[alreadyCappedHosts[i]]
// if capValue is greater than the threshold then cap, else continue // if capValue is greater than the threshold then cap, else continue
if capValue > constants.CapThreshold { if capValue > constants.CapThreshold {
newCapValue := getNextCapValue(capValue, 2) newCapValue := getNextCapValue(capValue, 2)
if err := rapl.Cap(alreadyCappedHosts[i], "rapl", newCapValue); err != nil { log.Printf("CurrentCapValue for host[%s] is %f", alreadyCappedHosts[i], capValue)
log.Printf("Error capping host %s", alreadyCappedHosts[i]) log.Printf("NewCapValue for host[%s] is %f", alreadyCappedHosts[i], newCapValue)
} else {
// successful cap
log.Printf("Capped host[%s] at %f", alreadyCappedHosts[i], newCapValue)
// Checking whether this victim can be capped further
if newCapValue <= constants.CapThreshold {
// deleting victim from cappedVictims
delete(cappedVictims, alreadyCappedHosts[i])
// updating the cap value in orderCappedVictims
orderCappedVictims[alreadyCappedHosts[i]] = newCapValue
} else {
// updating the cap value
cappedVictims[alreadyCappedHosts[i]] = newCapValue
orderCappedVictims[alreadyCappedHosts[i]] = newCapValue
}
break // exiting only on a successful cap.
}
} else {
// Do nothing
}
} else {
// This host can definitely be capped.
// Cap this host to half it's current cap value and update the new cap value in cappedVictims and orderCappedVictims
// If we have hit the threshold then we add this host to orderCapped to indicate that it needs to be uncapped.
newCapValue := getNextCapValue(cappedVictims[alreadyCappedHosts[i]], 2)
if err := rapl.Cap(alreadyCappedHosts[i], "rapl", newCapValue); err != nil { if err := rapl.Cap(alreadyCappedHosts[i], "rapl", newCapValue); err != nil {
log.Printf("Error capping host %s", alreadyCappedHosts[i]) log.Printf("Error capping host %s", alreadyCappedHosts[i])
} else { } else {
// successful cap
log.Printf("Capped host[%s] at %f", alreadyCappedHosts[i], newCapValue) log.Printf("Capped host[%s] at %f", alreadyCappedHosts[i], newCapValue)
// Checking whether this victim can be capped further // Checking whether this victim can be capped further
if newCapValue <= constants.CapThreshold { if newCapValue <= constants.CapThreshold {
// deleting victim from cappedVictims // deleting victim from cappedVictims
delete(cappedVictims, alreadyCappedHosts[i]) delete(cappedVictims, alreadyCappedHosts[i])
// staging victim for uncapping // updating the cap value in orderCappedVictims
orderCapped = append(orderCapped, alreadyCappedHosts[i]) orderCappedVictims[alreadyCappedHosts[i]] = newCapValue
orderCappedVictims[alreadyCappedHosts[i]] = constants.CapThreshold
} else { } else {
// Updating the cap value of the victim // updating the cap value
cappedVictims[alreadyCappedHosts[i]] = newCapValue cappedVictims[alreadyCappedHosts[i]] = newCapValue
orderCappedVictims[alreadyCappedHosts[i]] = newCapValue
} }
break // exiting only on a successful uncap break // exiting only on a successful cap.
} }
} else {
// Do nothing
// Continue to find another victim to cap.
// If cannot find any victim, then all nodes have been capped to the maximum and we stop capping at that point.
} }
} }
} }
} else if clusterMean < loThreshold { } else if clusterMean < loThreshold {
log.Println("Need to uncap a node") log.Println("Need to uncap a node")
log.Println(cappedVictims)
log.Println(orderCappedVictims)
if len(orderCapped) > 0 { if len(orderCapped) > 0 {
host := orderCapped[len(orderCapped)-1] host := orderCapped[len(orderCapped)-1]
// Removing victim from orderCapped only if it has been completely uncapped to 100% // Uncapping the host and removing it from orderCapped if we cannot uncap it further
if cappedVictims[host] == 100.0 { newUncapValue := orderCappedVictims[host] * 2.0
orderCapped = orderCapped[:len(orderCapped)-1] if err := rapl.Cap(host, "rapl", newUncapValue); err != nil {
delete(orderCappedVictims, host) log.Printf("Error uncapping host %s", host)
} else { } else {
newCapValue := getNextUncapValue(cappedVictims[host], 2) // Successful uncap
// Uncapping the victim log.Printf("Uncapped host[%s] to %f", host, newUncapValue)
if err := rapl.Cap(host, "rapl", newCapValue); err != nil { if newUncapValue >= 100.0 { // can compare using ==
log.Printf("Error uncapping host %s", host) orderCapped = orderCapped[:len(orderCapped)-1]
} else { delete(orderCappedVictims, host)
// Successful uncap // removing entry from cappedVictims as this host is no longer capped
log.Printf("Uncapped host[%s] to %f", host, newCapValue) delete(cappedVictims, host)
// If the new cap value is 100, then this node cannot be uncapped } else if newUncapValue > constants.CapThreshold { // this check is unnecessary and can be converted to 'else'
if newCapValue == 100.0 { // Updating the cap value in orderCappedVictims and cappedVictims
orderCapped = orderCapped[:len(orderCapped)-1] orderCappedVictims[host] = newUncapValue
delete(orderCappedVictims, host) cappedVictims[host] = newUncapValue
// Updating cappedVictims
cappedVictims[host] = newCapValue
} else if newCapValue > constants.CapThreshold {
// This host can be capped
cappedVictims[host] = newCapValue
// Updating orderCappedVictims
orderCappedVictims[host] = newCapValue
}
} }
} }
} else { } else {
// No node has been capped until now. log.Println("No host staged for Uncapping")
} }
} }
} }