Commit 224554a0 by Tomasz Ciesielczyk

new algorithms

parent 4a32af8d
......@@ -52,15 +52,6 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../../lib/lightstorage_2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.30" level="project" />
<orderEntry type="module" module-name="m2dc-rtm-utils_main" />
<orderEntry type="library" name="Gradle: org.ojalgo:ojalgo:45.1.0" level="project" />
......
......@@ -3,12 +3,14 @@ package psnc.m2dc.rtm
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.dao.DAO
import psnc.m2dc.rtm.model.rest.NodeUtil
import psnc.m2dc.rtm.model.rpm.ManagementMethodType
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.rpm.RPMApi
import psnc.m2dc.rtm.utils.logError
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.toJson
import java.nio.file.Paths
import java.util.*
/**
*
......@@ -20,6 +22,28 @@ abstract class RTMAlgorithm(currentState: CurrentState) {
companion object {
val log = LoggerFactory.getLogger(RTMAlgorithm::class.java.name)!!
private val cache = Array<PowerSettingsCacheRow>(10, { PowerSettingsCacheRow("") })
private var idx = 0
private data class PowerSettingsCacheRow(val name: String, val powerSettings: PowerSettings? = null, val timestamp: Date = Date())
private fun saveCache() {
cache.toJson(Paths.get("${RTMProperties.basePath}/rtm_algo.out").toString())
}
private fun appendCache(row: PowerSettingsCacheRow) {
synchronized(cache) {
cache[(idx++) % cache.size] = row
saveCache()
}
}
}
fun appendCache(powerSettingsMap: HashMap<Resource, CurrentState.NodeState>): PowerSettings {
val powerSettings = PowerSettings(powerSettingsMap)
appendCache(PowerSettingsCacheRow(this::class.java.name, powerSettings))
return powerSettings
}
fun updateState(currentState: CurrentState) {
......@@ -37,7 +61,8 @@ abstract class RTMAlgorithm(currentState: CurrentState) {
// val node = value.first
val typeId = DAO.Resource.getType(resourceId)!!
val model = DAO.Resource.getComponentPowerModel(typeId, null)!!
val savings = ManagementMethodType.suspend.getPowerSavings(model, power)
val savings = power - (model.suspendPowerUsage ?: power)
// val savings = ManagementMethodType.suspend.getPowerSavings(model, power)
sum += savings
}
return sum
......@@ -70,7 +95,7 @@ abstract class RTMAlgorithm(currentState: CurrentState) {
"resource: ${node.id}, default power: 0.0!!!"); 0.0
}.invoke()
val model = DAO.Resource.getComponentPowerModel(node.typeId, null)!!
val savings = ManagementMethodType.suspend.getPowerSavings(model, power)
val savings = power - (model.suspendPowerUsage ?: power)
return Pair(node, savings)
}
......@@ -84,9 +109,9 @@ abstract class RTMAlgorithm(currentState: CurrentState) {
val node = state.node
if (this.state.canSuspend(it.nodeId)) {
// node to PowerSettings.SUSPEND
node to state.setPerformance(PowerSettings.SUSPEND)
node to state.setPerformance(PowerSettings.SUSPEND)
} else if (this.state.canSetPerformance(it.nodeId)) {
node to state.setPerformance(0.0)
node to state.setPerformance(0.0)
} else
null
......@@ -94,17 +119,14 @@ abstract class RTMAlgorithm(currentState: CurrentState) {
}
fun getShutdownSavings(): Double {
val powerUsage = RPMApi.instance().getPowerUsageList()
var sum = 0.0
powerUsage.filter {
this.state.canShutdown(it.key)
}.forEach { resourceId, power ->
val typeId = DAO.Resource.getType(resourceId)!!
val model = DAO.Resource.getComponentPowerModel(typeId, null)!!
val savings = ManagementMethodType.turn_off.getPowerSavings(model, power)
sum += savings
}
return sum
}
// fun getShutdownSavings(): Double {
// val powerUsage = RPMApi.instance().getPowerUsageList()
// var sum = 0.0
// powerUsage.filter {
// this.state.canShutdown(it.key)
// }.forEach { _, power ->
// sum += power //savings = power
// }
// return sum
// }
}
\ No newline at end of file
......@@ -42,7 +42,7 @@ class ESMAlgorithm(state: CurrentState) : RTMAlgorithm(state) {
result[state.node] = state
}
}
return PowerSettings(result)
return appendCache(result)
}
......
......@@ -46,7 +46,7 @@ class PCMAlgorithm(state: CurrentState) : RTMAlgorithm(state) {
var suspendSavings = unusedResourcesSuspendSavings()
this.state.eval.resetPowerBudget(state.currentPowerOverLimit)
printConsole("pcm poweroverlimit: ${this.state.eval.powerOverLimit} $suspendSavings")
printConsole("PCM poweroverlimit: ${this.state.eval.powerOverLimit} $suspendSavings")
if (suspendSavings > this.state.currentPowerOverLimit) {
logInfo("Suspend unused: Stop")
......@@ -101,8 +101,7 @@ class PCMAlgorithm(state: CurrentState) : RTMAlgorithm(state) {
}
logInfo("Suspend active, unused, and reduce performance: Stop")
result.putAll(unusedNodesSuspendActions())
return PowerSettings(result)
// return runActions(this.algoState!!.getActions()).let { it.addAll(this.suspendUnusedNodes());it }
return appendCache(result)
}
......
......@@ -18,7 +18,7 @@ object ServerConfInitializer {
try {
logInfo("version: $APP_VERSION")
loadConfig()
prepareResourceFile().toJson()
prepareResourceFile().toJson("_resource.conf",true)
loadResources()
// setDefaultPriorities()
......
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.490_43783"
\ No newline at end of file
val APP_VERSION = "1.0.500_53131"
\ No newline at end of file
package psnc.m2dc.rtm.client
const val APP_VERSION = "1.1.490_43783"
\ No newline at end of file
const val APP_VERSION = "1.1.500_53133"
\ No newline at end of file
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 sign in to comment