summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-workload
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2025-11-04 21:09:38 +0100
committerGitHub <noreply@github.com>2025-11-04 21:09:38 +0100
commit71f63618fb83c8e19ae48d5dc4a6e3927031cc10 (patch)
tree6bf4048b1e683bbcac53e162be787e80828e48e2 /opendc-compute/opendc-compute-workload
parent59898b873eabc72719376854770c55e8d8efaa0f (diff)
Memory update (#379)
* Updated the memory usage of Tasks. Still in Progress. * Merged Task and ServiceTask -> Currently not fully working!!! * Fixed bugs that made the merger between Task and ServiceTask not work well. * Updated jdk version for Dockerfile * Removed ServiceFlavor.java and Task.kt
Diffstat (limited to 'opendc-compute/opendc-compute-workload')
-rw-r--r--opendc-compute/opendc-compute-workload/build.gradle.kts3
-rw-r--r--opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt52
-rw-r--r--opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/Task.kt55
-rw-r--r--opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/WorkloadLoader.kt19
4 files changed, 41 insertions, 88 deletions
diff --git a/opendc-compute/opendc-compute-workload/build.gradle.kts b/opendc-compute/opendc-compute-workload/build.gradle.kts
index 58b7bc86..2b5ec510 100644
--- a/opendc-compute/opendc-compute-workload/build.gradle.kts
+++ b/opendc-compute/opendc-compute-workload/build.gradle.kts
@@ -1,4 +1,4 @@
-/*
+/*opendcSimulatorCore
* Copyright (c) 2021 AtLarge Research
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -32,6 +32,7 @@ dependencies {
implementation(projects.opendcCommon)
implementation(project(mapOf("path" to ":opendc-trace:opendc-trace-api")))
implementation(project(mapOf("path" to ":opendc-simulator:opendc-simulator-compute")))
+ implementation(project(mapOf("path" to ":opendc-compute:opendc-compute-simulator")))
implementation(libs.kotlin.logging)
}
diff --git a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt
index 57f2efc0..e4bdaac5 100644
--- a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt
+++ b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt
@@ -23,6 +23,7 @@
package org.opendc.compute.workload
import mu.KotlinLogging
+import org.opendc.compute.simulator.service.ServiceTask
import org.opendc.simulator.compute.workload.trace.TraceWorkload
import org.opendc.simulator.compute.workload.trace.scaling.NoDelayScaling
import org.opendc.simulator.compute.workload.trace.scaling.ScalingPolicy
@@ -72,7 +73,7 @@ public class ComputeWorkloadLoader(
/**
* The cache of workloads.
*/
- private val cache = ConcurrentHashMap<File, SoftReference<List<Task>>>()
+ private val cache = ConcurrentHashMap<File, SoftReference<List<ServiceTask>>>()
/**
* Read the fragments into memory.
@@ -119,10 +120,10 @@ public class ComputeWorkloadLoader(
/**
* Read the metadata into a workload.
*/
- private fun parseMeta(
+ private fun parseTasks(
trace: Trace,
fragments: Map<Int, Builder>,
- ): List<Task> {
+ ): List<ServiceTask> {
val reader = checkNotNull(trace.getTable(TABLE_TASKS)).newReader()
val idCol = reader.resolve(TASK_ID)
@@ -139,27 +140,23 @@ public class ComputeWorkloadLoader(
val deferrableCol = reader.resolve(TASK_DEFERRABLE)
val deadlineCol = reader.resolve(TASK_DEADLINE)
- val entries = mutableListOf<Task>()
+ val entries = mutableListOf<ServiceTask>()
return try {
while (reader.nextRow()) {
val id = reader.getInt(idCol)
var name = reader.getString(idName)
- if (name == null) {
- name = id.toString()
- }
-
if (!fragments.containsKey(id)) {
continue
}
val submissionTime = reader.getInstant(submissionTimeCol)!!.toEpochMilli()
val duration = reader.getLong(durationCol)
- val cpuCount = reader.getInt(cpuCountCol)
+ val cpuCoreCount = reader.getInt(cpuCountCol)
val cpuCapacity = reader.getDouble(cpuCapacityCol)
- val memCapacity = reader.getDouble(memCol) / 1000.0 // Convert from KB to MB
- val gpuUsage =
+ val memUsage = reader.getDouble(memCol) / 1000.0 // Convert from KB to MB
+ val gpuCapacity =
if (reader.getDouble(
gpuCapacityCol,
).isNaN()
@@ -171,8 +168,17 @@ public class ComputeWorkloadLoader(
val gpuCoreCount = reader.getInt(gpuCoreCountCol) // Default to 0 if not present
val gpuMemory = 0L // currently not implemented
- val parents = reader.getSet(parentsCol, Int::class.java) // No dependencies in the trace
- val children = reader.getSet(childrenCol, Int::class.java) // No dependencies in the trace
+ var parents = reader.getSet(parentsCol, Int::class.java) // No dependencies in the trace
+ var children = reader.getSet(childrenCol, Int::class.java) // No dependencies in the trace
+
+ var parentsOutput: ArrayList<Int>? = null
+
+ if (parents?.isEmpty() == true) {
+ parentsOutput = null
+ children = null
+ } else {
+ parentsOutput = ArrayList(parents!!)
+ }
var deferrable = reader.getBoolean(deferrableCol)
var deadline = reader.getLong(deadlineCol)
@@ -185,29 +191,29 @@ public class ComputeWorkloadLoader(
val totalLoad = builder.totalLoad
entries.add(
- Task(
+ ServiceTask(
id,
name,
submissionTime,
duration,
- parents!!,
- children!!,
- cpuCount,
+ cpuCoreCount,
cpuCapacity,
totalLoad,
- memCapacity.roundToLong(),
+ memUsage.roundToLong(),
gpuCoreCount,
- gpuUsage,
+ gpuCapacity,
gpuMemory,
+ builder.build(),
deferrable,
deadline,
- builder.build(),
+ parentsOutput,
+ children,
),
)
}
// Make sure the virtual machines are ordered by start time
- entries.sortBy { it.submissionTime }
+ entries.sortBy { it.submittedAt }
entries
} catch (e: Exception) {
@@ -221,10 +227,10 @@ public class ComputeWorkloadLoader(
/**
* Load the trace at the specified [pathToFile].
*/
- override fun load(): List<Task> {
+ override fun load(): List<ServiceTask> {
val trace = Trace.open(pathToFile, "workload")
val fragments = parseFragments(trace)
- val vms = parseMeta(trace, fragments)
+ val vms = parseTasks(trace, fragments)
return vms
}
diff --git a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/Task.kt b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/Task.kt
deleted file mode 100644
index 705730a0..00000000
--- a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/Task.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.compute.workload
-
-import org.opendc.simulator.compute.workload.trace.TraceWorkload
-
-/**
- * A virtual machine workload.
- *
- * @param id The unique identifier of the virtual machine.
- * @param name The name of the virtual machine.
- * @param cpuCapacity The required CPU capacity for the VM in MHz.
- * @param cpuCount The number of vCPUs in the VM.
- * @param memCapacity The provisioned memory for the VM in MB.
- * @param submissionTime The start time of the VM.
- * @param trace The trace that belong to this VM.
- */
-public data class Task(
- val id: Int,
- val name: String,
- var submissionTime: Long,
- val duration: Long,
- val parents: Set<Int> = mutableSetOf(),
- val children: Set<Int> = emptySet(),
- val cpuCount: Int,
- val cpuCapacity: Double,
- val totalCpuLoad: Double,
- val memCapacity: Long,
- val gpuCount: Int = 0,
- val gpuCapacity: Double = 0.0,
- val gpuMemCapacity: Long = 0L,
- val deferrable: Boolean,
- var deadline: Long,
- val trace: TraceWorkload,
-)
diff --git a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/WorkloadLoader.kt b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/WorkloadLoader.kt
index c8b7ecc7..dc7c46a7 100644
--- a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/WorkloadLoader.kt
+++ b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/WorkloadLoader.kt
@@ -22,34 +22,35 @@
package org.opendc.compute.workload
import mu.KotlinLogging
+import org.opendc.compute.simulator.service.ServiceTask
import java.time.LocalDateTime
import java.time.ZoneOffset
public abstract class WorkloadLoader(private val submissionTime: String? = null) {
private val logger = KotlinLogging.logger {}
- public fun reScheduleTasks(workload: List<Task>) {
+ public fun reScheduleTasks(workload: List<ServiceTask>) {
if (submissionTime == null) {
return
}
- val workloadSubmissionTime = workload.minOf({ it.submissionTime })
+ val workloadSubmissionTime = workload.minOf({ it.submittedAt })
val submissionTimeLong = LocalDateTime.parse(submissionTime).toInstant(ZoneOffset.UTC).toEpochMilli()
val timeShift = submissionTimeLong - workloadSubmissionTime
for (task in workload) {
- task.submissionTime += timeShift
+ task.submittedAt += timeShift
task.deadline = if (task.deadline == -1L) -1L else task.deadline + timeShift
}
}
- public abstract fun load(): List<Task>
+ public abstract fun load(): List<ServiceTask>
/**
* Load the workload at sample tasks until a fraction of the workload is loaded
*/
- public fun sampleByLoad(fraction: Double): List<Task> {
+ public fun sampleByLoad(fraction: Double): List<ServiceTask> {
val workload = this.load()
reScheduleTasks(workload)
@@ -62,9 +63,9 @@ public abstract class WorkloadLoader(private val submissionTime: String? = null)
throw Error("The fraction of tasks to load cannot be 0.0 or lower")
}
- val res = mutableListOf<Task>()
+ val res = mutableListOf<ServiceTask>()
- val totalLoad = workload.sumOf { it.totalCpuLoad }
+ val totalLoad = workload.sumOf { it.totalCPULoad }
val desiredLoad = totalLoad * fraction
var currentLoad = 0.0
@@ -72,11 +73,11 @@ public abstract class WorkloadLoader(private val submissionTime: String? = null)
val entry = workload.random()
res += entry
- currentLoad += entry.totalCpuLoad
+ currentLoad += entry.totalCPULoad
}
logger.info { "Sampled ${workload.size} VMs (fraction $fraction) into subset of ${res.size} VMs" }
- return res.sortedBy { it.submissionTime }
+ return res.sortedBy { it.submittedAt }
}
}