Developing lightweight computation at the DSG edge

Commit f43a74c1 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-assign] Add global load calculations


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 10952275
......@@ -225,7 +225,7 @@ func initializeFlags() {
}
//Policy
if *policyPtr >= 1 && *policyPtr <= 2 {
if *policyPtr >= 1 && *policyPtr <= 3 {
policy = *policyPtr
}
......@@ -539,6 +539,7 @@ func reassignDevs() {
} else {
fmt.Println("Not assigning any new device.")
}
fmt.Println("Global average load:", calculateGlobalAverageLoad())
}
// Update the new assigned devices to the global shared list
......@@ -547,6 +548,7 @@ func reassignDevs() {
for _, v := range localAssign {
goclidote.AntidoteAddItemToSetInBucket(fmt.Sprintf("device-%d", v.Device.ID), "monitors", ID, dbHost, dbPort)
}
// localLoad := math.min(1, float64(len(localAssign))/float64(maxDevs))
}
}
......@@ -701,6 +703,8 @@ func startLocalAssignTimer() {
updateGlobalAssignationList()
sanitizeAssignationsInDatabase()
reassignDevs()
updateGlobalAssignationList()
updateLocalAssignationList()
}
}()
}
......@@ -717,7 +721,7 @@ func updateMonitorTimestampInAntidote() {
}
func updateMonitorMaxDevsInAntidote() {
goclidote.AntidoteSetRegisterInBucket("guifi", fmt.Sprintf("%s_maxdevs", maxDevs), fmt.Sprintf("%d", maxDevs), dbHost, dbPort)
goclidote.AntidoteSetRegisterInBucket("guifi", fmt.Sprintf("%d_maxdevs", maxDevs), fmt.Sprintf("%d", maxDevs), dbHost, dbPort)
fmt.Println("Setting capacity to", maxDevs)
}
......@@ -737,6 +741,69 @@ func deregisterMonitorInAntidote(monitorID string) {
goclidote.AntidoteRemoveRegisterInBucket("guifi", fmt.Sprintf("%s_ts", monitorID), dbHost, dbPort)
}
func calculateGlobalAverageLoad() float64 {
var monitors = getCurrentMonitorsList()
var monitorsMaxDevs []int
var monitorAssignedDevs []int
for _, v := range monitors {
capacity, err := strconv.ParseInt(goclidote.AntidoteReadRegisterInBucket("guifi", fmt.Sprintf("%d_maxdevs", maxDevs), dbHost, dbPort), 10, 64)
errCheck(err, WARNING, fmt.Sprintf("Monitor %s has an invalid maxDev", v))
if err == nil && capacity > 0 {
monitorsMaxDevs = append(monitorsMaxDevs, int(capacity))
} else {
monitorsMaxDevs = append(monitorsMaxDevs, 0)
}
monitorAssignedDevs = append(monitorAssignedDevs, 0)
}
fmt.Println("len(globalAssign):", len(globalAssign))
for _, v := range globalAssign {
fmt.Println(v)
for _, w := range v.MonitorID {
fmt.Println("len(monitors):", len(monitors))
for m, x := range monitors {
if w == x {
monitorAssignedDevs[m] = monitorAssignedDevs[m] + 1
}
}
}
}
var globalMaxDevs uint64
var globalAssignedDevs uint64
for _, v := range monitorsMaxDevs {
globalMaxDevs = globalMaxDevs + uint64(v)
}
for _, v := range monitorAssignedDevs {
globalAssignedDevs = globalAssignedDevs + uint64(v)
}
fmt.Println(monitors)
fmt.Println(monitorsMaxDevs)
fmt.Println(monitorAssignedDevs)
if globalMaxDevs > 0 {
if globalAssignedDevs >= 0 {
if globalAssignedDevs <= globalMaxDevs {
// Standard case
return float64(globalAssignedDevs) / float64(globalMaxDevs)
}
// Overload case, or monitors not reporting properly maxDevs
return 1
}
// Weird case with negative assigned devices
return 0
}
// Corner case when no monitors are registered, or not reporting properly;
// return a compromise 50% load
return 0.5
}
func errCheck(e error, level int, message string) {
if message == "" {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment