Skip to content

Commit

Permalink
Simplified the WorkloadLoader into a single class that can be extende…
Browse files Browse the repository at this point in the history
…d when new workload types are added (#294)
  • Loading branch information
DanteNiewenhuis authored Jan 22, 2025
1 parent 5c193e7 commit 9403af1
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 419 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ import kotlin.math.roundToLong
* @param baseDir The directory containing the traces.
*/
public class ComputeWorkloadLoader(
private val baseDir: File,
private val pathToFile: File,
private val checkpointInterval: Long,
private val checkpointDuration: Long,
private val checkpointIntervalScaling: Double,
) {
) : WorkloadLoader() {
/**
* The logger for this instance.
*/
Expand All @@ -61,7 +61,7 @@ public class ComputeWorkloadLoader(
/**
* The cache of workloads.
*/
private val cache = ConcurrentHashMap<String, SoftReference<List<Task>>>()
private val cache = ConcurrentHashMap<File, SoftReference<List<Task>>>()

/**
* Read the fragments into memory.
Expand Down Expand Up @@ -157,21 +157,18 @@ public class ComputeWorkloadLoader(
}

/**
* Load the trace with the specified [name] and [format].
* Load the trace at the specified [pathToFile].
*/
public fun get(
name: String,
format: String,
): List<Task> {
override fun load(): List<Task> {
val ref =
cache.compute(name) { key, oldVal ->
cache.compute(pathToFile) { key, oldVal ->
val inst = oldVal?.get()
if (inst == null) {
val path = baseDir.resolve(key)
// val path = baseDir.resolve(key)

logger.info { "Loading trace $key at $path" }
logger.info { "Loading trace $key at $pathToFile" }

val trace = Trace.open(path, format)
val trace = Trace.open(pathToFile, "opendc-vm")
val fragments = parseFragments(trace)
val vms = parseMeta(trace, fragments)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 AtLarge Research
* Copyright (c) 2025 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
Expand All @@ -20,28 +20,19 @@
* SOFTWARE.
*/

package org.opendc.compute.workload.internal

package org.opendc.compute.workload
import mu.KotlinLogging
import org.opendc.compute.workload.ComputeWorkload
import org.opendc.compute.workload.ComputeWorkloadLoader
import org.opendc.compute.workload.Task
import java.util.random.RandomGenerator

/**
* A [ComputeWorkload] that is sampled based on total load.
*/
internal class LoadSampledComputeWorkload(val source: ComputeWorkload, val fraction: Double) : ComputeWorkload {
/**
* The logging instance of this class.
*/
public abstract class WorkloadLoader {
private val logger = KotlinLogging.logger {}

override fun resolve(
loader: ComputeWorkloadLoader,
random: RandomGenerator,
): List<Task> {
val vms = source.resolve(loader, random) // fixme: Should be shuffled, otherwise the first fraction is always chosen
public abstract fun load(): List<Task>

/**
* Load the workload at sample tasks until a fraction of the workload is loaded
*/
public fun sampleByLoad(fraction: Double): List<Task> {
val vms = this.load()
val res = mutableListOf<Task>()

val totalLoad = vms.sumOf { it.totalLoad }
Expand Down

This file was deleted.

Loading

0 comments on commit 9403af1

Please sign in to comment.