Commit 8b526d22 by Tomasz Ciesielczyk

bug fixes and minor improvements

parent 243bc267
......@@ -2,6 +2,7 @@ package psnc.m2dc.rtm
import org.jsoup.Connection
import org.jsoup.Jsoup
import psnc.m2dc.rtm.dao.DAO
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rpm.RPMApi
import psnc.m2dc.rtm.utils.logError
......@@ -28,18 +29,33 @@ abstract class RTMWorker : Runnable {
}
protected fun notify(actions: PowerSettings) {
if (Keys.RTM.notification_endpoint.getNullable() != null) {
try {
Keys.RTM.notification_endpoint.getNullable()?.let { endpoint ->
logInfo("Action notify: $endpoint")
Jsoup.connect(endpoint).method(Connection.Method.POST).requestBody(actions.getSettings().toJson()).execute()
try {
Keys.RTM.notification_endpoint.getNullable()?.let { endpoint ->
logInfo("Action notify: $endpoint")
var currentSettings = DAO.Resource.getNodes().keys.map {
it to ActionCache.getPerformanceSetting(it)
}.toMap()
var newSettings = DAO.Resource.getNodes().keys.map {
if (actions.getSettings().containsKey(it)) {
it to actions.getSettings()[it]
} else
it to ActionCache.getPerformanceSetting(it)
}.toMap()
val data = mapOf("current_settings" to currentSettings,"new_settings" to newSettings)
if (endpoint.startsWith("file:")) {
data.toJson(endpoint.substring(5),true)
} else {
Jsoup.connect(endpoint).method(Connection.Method.POST).requestBody(data.toJson()).execute()
}
} catch (e: Exception) {
logError(e, "Power Action notification error")
//endpoint.
}
} catch (e: Exception) {
logError(e, "Power Action notification error")
}
}
abstract fun stop()
......
......@@ -49,6 +49,7 @@ class ESMApi {
val powerUsage = RPMApi.instance().getPowerUsageList().sum()
val state = CurrentState(powerUsage)// * (1 + Keys.PCM.power_buffer.get()))//, DAO.Chassis.getRCUUtil())
printConsole("testx $state")
ESMWorker.start(state)
return true
} catch (e: Exception) {
......
package psnc.m2dc.rtm.esm
import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.pcm.algorithm.Evaluation
import psnc.m2dc.rtm.pcm.algorithm.Solver
import psnc.m2dc.rtm.properties.keys.Keys
......@@ -11,4 +10,4 @@ import psnc.m2dc.rtm.properties.keys.Keys
*/
class ESMSolver(e: Evaluation,algorithm: Algorithm) : Solver(e, SolverMode.esm,
Keys.ESM.power_buffer.get() *
(PCMApi.instance().getPowerLimit() ?: 0.0),algorithm)
(e.totalCurrentPowerUsage()+Keys.ESM.absolute_power_buffer.get()),algorithm)
......@@ -80,7 +80,7 @@ class PCMApi() {
}
fun getPowerLimit(): Double? = StorageKeys.POWER_LIMIT
fun getPowerLimit(): Double? = StorageKeys.POWER_LIMIT?:Keys.PCM.default_power_limit.get()
fun getNodePerformance(resources: Map<String, Resource>? = DAO.Resource.getResources()): HashMap<String,
ActionCache.Setting> {
......
......@@ -9,6 +9,6 @@ import psnc.m2dc.rtm.properties.keys.Keys
* Created by Tomek on 2018-06-25.
*/
class PCMSolver(e: Evaluation,algorithm: Algorithm) : Solver(e, SolverMode.pcm,Keys.PCM.power_buffer.get() *
(PCMApi.instance().getPowerLimit() ?: 0.0),algorithm) {
(e.totalCurrentPowerUsage()+Keys.PCM.absolute_power_buffer.get() ),algorithm) {
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ import psnc.m2dc.rtm.utils.logInfo
import psnc.m2dc.rtm.utils.printConsole
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
import kotlin.collections.ArrayList
//todo: dump power settings
//dump parametrw wejsiowych
......@@ -292,7 +293,7 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
val group = r.second
val usePriorities = false
/**set minimum performance*/
var powerBudget = currentBudget // powerBudget should be greater than 0
var powerBudget = currentBudget // powerBudget should be greater than 0
val nodeSet = HashMap<String, Pair<Double, Double>>()
nodes.forEach { priority, nodeList ->
if (priority.priorityValue <= group.priorityValue || !usePriorities) {
......@@ -315,17 +316,21 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
nodes.forEach { node ->
this.settings.forEach { setting ->
val slot = Slot(setting, node)
slots.add(slot)
result[slot.node.id] = slot.settingValue
if(slot.settingValue>=0.0) {
slots.add(slot)
}
}
this.eval.getState(node.id)?.perfLevel?.let {
result[node.id] = it
}
}
}
slots.shuffle()
var idx = 0
while (idx < slots.size && powerBudget < 0) {
while (idx < slots.size) {
var slot = slots[idx]
val budgetChange = nodeSet[slot.node.id]!!.first - slot.powerReduction
if (-budgetChange >= 0) {//power budget increases
if (-budgetChange >= 0 || powerBudget - budgetChange>0 ) {//power budget increases
nodeSet[slot.node.id] = Pair(slot.powerReduction, slot.gain)
result[slot.node.id] = slot.settingValue
powerSavings -= budgetChange
......@@ -341,7 +346,7 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
this.powerSavings = eval.totalPowerSavings(result)
this.currentGain = eval.totalGain(result)
return result
return null
// return null
}
private fun simpleAlgo(): HashMap<String, Double>? {
......@@ -355,7 +360,7 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
val group = r.second
/**set minimum performance*/
var powerBudget = currentBudget // powerBudget should be greater than 0
var powerBudget = currentBudget // powerBudget should be greater than 0
val nodeList = ArrayList<Node>()
nodes.forEach { priority, it ->
if (priority.priorityValue <= group.priorityValue) {
......@@ -363,14 +368,22 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
}
}
val sorted = nodeList.sortedByDescending { it.state.priority }
val slots = HashMap<String, Slot>()
val slots = HashMap<String, ArrayList<Slot>>()
nodes.forEach { priority, nodes ->
if (priority.priorityValue <= group.priorityValue)
nodes.forEach { node ->
val nodeSlots = ArrayList<Slot>()
//ascending list of settings
this.settings.forEach { setting ->
val slot = Slot(setting, node)
slots[node.id] = slot
result[slot.node.id] = slot.settingValue
if (slot.settingValue >= 0.0) {
nodeSlots.add(slot)
}
}
slots[node.id] = nodeSlots
this.eval.getState(node.id)?.perfLevel?.let {
result[node.id] = it
}
}
}
......@@ -378,17 +391,27 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
var idx = 0
while (idx < size && powerBudget < 0) {
val node = nodeList[idx]
val currentSlot = slots[node.id]!!
var settingIndex = currentSlot.performanceSetting.settingIndex - 1
var budgetChange = 0.0
while (settingIndex > 0 && powerBudget - budgetChange < 0) {
budgetChange = currentSlot.powerReduction - node.state.getSavings(settingIndex)
settingIndex--
this.eval.getState(node.id)?.let {state->
val currentSettingIdx = state.model.getPerfIdx(state.perfLevel)
val setting = this.settings[currentSettingIdx]
val currentPowerReduction = Slot(setting, node).powerReduction
val nodeSlots = slots[node.id]!!
var settingIndex = nodeSlots.size - 1
var budgetChange = currentPowerReduction - node.state.getSavings(settingIndex)
while (settingIndex > 0 && powerBudget - budgetChange < 0) {
settingIndex--
budgetChange = currentPowerReduction - node.state.getSavings(settingIndex)
}
result[node.id] = Slot(this.settings[settingIndex], node).settingValue
powerSavings -= budgetChange
powerBudget -= budgetChange
}
result[node.id] = Slot(this.settings[settingIndex], node).settingValue
powerSavings -= budgetChange
powerBudget -= budgetChange
idx++
}
/**
......@@ -451,7 +474,7 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
val budgetChange = slot.node.state.savingsVector[0] - slot.powerReduction
if (powerBudget - budgetChange >= 0) {
nodeSet[slot.node.id] = Pair(slot.powerReduction, slot.gain)
result.put(slot.node.id, slot.settingValue)
result[slot.node.id] = slot.settingValue
powerSavings -= budgetChange
powerBudget -= budgetChange
}
......@@ -459,7 +482,7 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
val budgetChange = nodeSet[slot.node.id]!!.first - slot.powerReduction
if (powerBudget - budgetChange >= 0) {
nodeSet[slot.node.id] = Pair(slot.powerReduction, slot.gain)
result.put(slot.node.id, slot.settingValue)
result[slot.node.id] = slot.settingValue
powerSavings -= budgetChange
powerBudget -= budgetChange
}
......
......@@ -64,7 +64,7 @@ object RTMScannerWorker {
iter = 0
} else if (iter > esmRatio) {
ActionPredictor.predict(PCMApi.instance().getPowerLimit()).generateScripts()
if (Keys.ESM.status.get()) {
if (Keys.ESM.scan_status.get()) {
ESMApi.instance().optimize()
} else {
printConsole("ESM is stopped")
......
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.551_50237"
\ No newline at end of file
val APP_VERSION = "1.0.554_53306"
\ No newline at end of file
package psnc.m2dc.rtm.client
const val APP_VERSION = "1.1.551_50237"
\ No newline at end of file
const val APP_VERSION = "1.1.554_53306"
\ No newline at end of file
......@@ -3,6 +3,7 @@ package psnc.m2dc.rtm.model.rpm
import psnc.m2dc.rtm.dao.SettingsDAO
import psnc.m2dc.rtm.model.rest.ResourceAction
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.utils.logError
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.toJson
import java.io.File
......@@ -350,10 +351,10 @@ class ComponentPowerModel(val name: String, private val perfList: List<Double>,
?: return ComponentPowerModel.HIGH_VALUE //Double.MAX_VALUE
val j_lower = (utilization / this.utilStep).toInt()
val x = (utilization % this.utilStep) / this.utilStep.toDouble()
val j_upper = Math.min(j_lower+1, this.powerUsage[i].size - 1)
val j_upper = Math.min(j_lower + 1, this.powerUsage[i].size - 1)
val p_lower = this.powerUsage[i][j_lower]
val p_upper = this.powerUsage[i][j_upper]
val p = p_lower + (p_upper-p_lower)*x
val p = p_lower + (p_upper - p_lower) * x
// return this.powerUsage[i][j]
return p
}
......@@ -702,11 +703,14 @@ object ModelMap {
}
fun get(resourceType: String, profileName: String? = defaultProfile): ComponentPowerModel {
val resourceModels = this.map[resourceType] ?: this.map[defaultType]!!
val resourceModels = this.map[resourceType]
?: { logError("default model for $resourceType");this.map[defaultType]!! }()
if (profileName == null) {
return resourceModels.values.first()
}
return resourceModels[profileName] ?: resourceModels[defaultProfile]!!
return resourceModels[profileName] ?: {
logError("default profile for model $resourceType for profile $profileName");resourceModels[defaultProfile]!!
}()
}
fun checkModel(resourceType: String, profileName: String? = defaultProfile): Boolean {
......
......@@ -13,7 +13,9 @@ class ESM {
//val auto_perform_actions = ESM + "auto_perform_actions"
val scan_timeout_ms = RTMProperty(ESM + "scan_timeout_ms", 300000L)
val status = RTMProperty(ESM + "status", false)
val power_buffer = RTMProperty(ESM + "power_buffer", 0.05, description = "power limit with safety buffer: power_limit = power_limit*(1.0-power_buffer)")
val scan_status = RTMProperty(ESM + "status", false)
val power_buffer = RTMProperty(ESM + "power_buffer", 0.025, description = "power limit with safety buffer: power_limit = power_limit*(1.0-power_buffer)")
val absolute_power_buffer = RTMProperty(ESM + "absolute_power_buffer", 10.0, description = "Absolute power (in Watts) buffer limit with safety buffer: final_power_limit = power_limit*(1.0-power_buffer) - absolute_power_buffer")
// }
}
\ No newline at end of file
......@@ -13,13 +13,14 @@ class PCM {
return description
}
val algorithm = RTMProperty(PCM + "algorithm", "greedy",description= "available values: greedy, simple, random, milp, proportional")
val algorithm = RTMProperty(PCM + "algorithm", "greedy", description = "available values: greedy, simple, random, milp, proportional")
//val auto_perform_actions = RTMProperty(PCM + "auto_perform_actions", true)
val fire_null_limit_restore = RTMProperty(PCM + "fire_null_limit_restore ",
true)
// val power_buffer = PCM + "power_buffer"
val power_buffer = RTMProperty(PCM + "power_buffer", 0.15, description = " power limit with relative safety buffer: final_power_limit = power_limit*(1.0-power_buffer)-absolute_power_buffer")
val absolute_power_buffer = RTMProperty(PCM + "absolute_power_buffer", 5.0, description = "Absolute power (in Watts) buffer limit with safety buffer: final_power_limit = power_limit*(1.0-power_buffer) - absolute_power_buffer")
val power_buffer = RTMProperty(PCM + "power_buffer", 0.03, description = " power limit with relative safety buffer: final_power_limit = power_limit*(1.0-power_buffer)-absolute_power_buffer")
val default_power_limit = RTMProperty(PCM + "default_power_limit", 50000.0, description = " default power limit in Watts ")
val absolute_power_buffer = RTMProperty(PCM + "absolute_power_buffer", 15.0, description = "Absolute power (in Watts) buffer limit with safety buffer: final_power_limit = power_limit*(1.0-power_buffer) - absolute_power_buffer")
// val scan_timeout_ms = RTMProperty(PCM + "scan_timeout_ms", 60000L)
// val scan_thread = RTMProperty(PCM + "scan_thread", true)
......
......@@ -31,7 +31,7 @@ class RTM {
val default_ssh_user = RTMProperty(RTM + "default_ssh_user", null, String::class.java)
val model_map_directory = RTMProperty(RTM + "model_map_directory", "\$[basePath]/models",
String::class.java)
val notification_endpoint = RTMProperty(RTM + "notification_endpoint", null, description = "Notify about actions")
val notification_endpoint = RTMProperty(RTM + "notification_endpoint", null, String::class.java, description = "Notify about actions")
val model_map_file = RTMProperty(RTM + "model_map_file", " \$[basePath]/models/model_map.txt ", String::class.java)
......
......@@ -5,7 +5,7 @@ import psnc.m2dc.rtm.model.rpm.Resource
interface SSHApi {
companion object {
val SSH_COMMAND_TIMEOUT = 10000L
val SSH_COMMAND_TIMEOUT = 20000L
}
fun suspend()
......
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