Skip to content

Commit 5965492

Browse files
Made some changes to improve RAM of OpenDC (#318)
1 parent 46ba81a commit 5965492

File tree

13 files changed

+34
-43
lines changed

13 files changed

+34
-43
lines changed

opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.Iterator;
3535
import java.util.List;
3636
import java.util.Map;
37-
import java.util.Objects;
3837
import java.util.Set;
3938
import java.util.SplittableRandom;
4039
import java.util.UUID;
@@ -594,15 +593,16 @@ public Flavor findFlavor(@NotNull UUID id) {
594593
}
595594

596595
@NotNull
597-
public Flavor newFlavor(@NotNull String name, int cpuCount, long memorySize, @NotNull Map<String, ?> meta) {
596+
public ServiceFlavor newFlavor(
597+
@NotNull String name, int cpuCount, long memorySize, @NotNull Map<String, ?> meta) {
598598
checkOpen();
599599

600600
final ComputeService service = this.service;
601601
UUID uid = new UUID(service.clock.millis(), service.random.nextLong());
602602
ServiceFlavor flavor = new ServiceFlavor(service, uid, name, cpuCount, memorySize, meta);
603603

604-
service.flavorById.put(uid, flavor);
605-
service.flavors.add(flavor);
604+
// service.flavorById.put(uid, flavor);
605+
// service.flavors.add(flavor);
606606

607607
return flavor;
608608
}
@@ -642,18 +642,19 @@ public Image newImage(@NotNull String name, @NotNull Map<String, String> labels,
642642
@NotNull
643643
public ServiceTask newTask(
644644
@NotNull String name,
645-
@NotNull Flavor flavor,
645+
@NotNull ServiceFlavor flavor,
646646
@NotNull Workload workload,
647647
@NotNull Map<String, ?> meta) {
648648
checkOpen();
649649

650650
final ComputeService service = this.service;
651651
UUID uid = new UUID(service.clock.millis(), service.random.nextLong());
652652

653-
final ServiceFlavor internalFlavor =
654-
Objects.requireNonNull(service.flavorById.get(flavor.getUid()), "Unknown flavor");
653+
// final ServiceFlavor internalFlavor =
654+
// Objects.requireNonNull(service.flavorById.get(flavor.getUid()), "Unknown flavor");
655655

656-
ServiceTask task = new ServiceTask(service, uid, name, internalFlavor, workload, meta);
656+
// ServiceTask task = new ServiceTask(service, uid, name, internalFlavor, workload, meta);
657+
ServiceTask task = new ServiceTask(service, uid, name, flavor, workload, meta);
657658

658659
service.taskById.put(uid, task);
659660

opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ServiceTask.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ServiceTask {
4949
private final UUID uid;
5050

5151
private final String name;
52-
private final ServiceFlavor flavor;
52+
private ServiceFlavor flavor;
5353
public Workload workload;
5454

5555
private Map<String, ?> meta; // TODO: remove this
@@ -181,6 +181,9 @@ public void delete() {
181181
}
182182
service.delete(this);
183183

184+
this.workload = null;
185+
this.flavor = null;
186+
184187
this.setState(TaskState.DELETED);
185188
}
186189

opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class ComputeMonitorProvisioningStep(
4545
OutputFiles.POWER_SOURCE to true,
4646
OutputFiles.BATTERY to true,
4747
),
48+
private val printFrequency: Int? = null,
4849
) : ProvisioningStep {
4950
override fun apply(ctx: ProvisioningContext): AutoCloseable {
5051
val service =
@@ -59,6 +60,7 @@ public class ComputeMonitorProvisioningStep(
5960
exportInterval,
6061
startTime,
6162
filesToExport,
63+
printFrequency,
6264
)
6365
return metricReader
6466
}

opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public fun registerComputeMonitor(
6868
OutputFiles.POWER_SOURCE to true,
6969
OutputFiles.BATTERY to true,
7070
),
71+
printFrequency: Int? = null,
7172
): ProvisioningStep {
72-
return ComputeMonitorProvisioningStep(serviceDomain, monitor, exportInterval, startTime, filesToExport)
73+
return ComputeMonitorProvisioningStep(serviceDomain, monitor, exportInterval, startTime, filesToExport, printFrequency)
7374
}
7475

7576
/**

opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class ComputeMetricReader(
6464
OutputFiles.BATTERY to true,
6565
OutputFiles.SERVICE to true,
6666
),
67+
private val printFrequency: Int? = null,
6768
) : AutoCloseable {
6869
private val logger = KotlinLogging.logger {}
6970
private val scope = CoroutineScope(dispatcher.asCoroutineDispatcher())
@@ -156,6 +157,7 @@ public class ComputeMetricReader(
156157
}
157158

158159
for (task in this.service.tasksToRemove) {
160+
this.taskTableReaders.remove(task)
159161
task.delete()
160162
}
161163
this.service.clearTasksToRemove()
@@ -197,7 +199,7 @@ public class ComputeMetricReader(
197199
monitor.record(this.serviceTableReader.copy())
198200
}
199201

200-
if (loggCounter >= 24) {
202+
if (printFrequency != null && loggCounter % printFrequency == 0) {
201203
var loggString = "\n\t\t\t\t\tMetrics after ${now.toEpochMilli() / 1000 / 60 / 60} hours:\n"
202204
loggString += "\t\t\t\t\t\tTasks Total: ${this.serviceTableReader.tasksTotal}\n"
203205
loggString += "\t\t\t\t\t\tTasks Active: ${this.serviceTableReader.tasksActive}\n"
@@ -206,7 +208,6 @@ public class ComputeMetricReader(
206208
loggString += "\t\t\t\t\t\tTasks Terminated: ${this.serviceTableReader.tasksTerminated}\n"
207209

208210
this.logger.warn { loggString }
209-
loggCounter = 0
210211
}
211212
} catch (cause: Throwable) {
212213
this.logger.warn(cause) { "Exporter threw an Exception" }

opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public class ComputeWorkloadLoader(
126126
continue
127127
}
128128

129-
val submissionTime = reader.getInstant(submissionTimeCol)!!
129+
val submissionTime = reader.getInstant(submissionTimeCol)!!.toEpochMilli()
130130
val duration = reader.getLong(durationCol)
131131
val cpuCount = reader.getInt(cpuCountCol)
132132
val cpuCapacity = reader.getDouble(cpuCapacityCol)

opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/Task.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package org.opendc.compute.workload
2424

2525
import org.opendc.simulator.compute.workload.trace.TraceWorkload
26-
import java.time.Instant
2726
import java.util.UUID
2827

2928
/**
@@ -45,7 +44,7 @@ public data class Task(
4544
val cpuCapacity: Double,
4645
val memCapacity: Long,
4746
val totalLoad: Double,
48-
var submissionTime: Instant,
47+
var submissionTime: Long,
4948
val duration: Long,
50-
val trace: TraceWorkload,
49+
var trace: TraceWorkload,
5150
)

opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/WorkloadLoader.kt

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
package org.opendc.compute.workload
2424
import mu.KotlinLogging
25-
import java.time.Instant
2625
import java.time.LocalDateTime
2726
import java.time.ZoneOffset
2827

@@ -34,13 +33,13 @@ public abstract class WorkloadLoader(private val submissionTime: String? = null)
3433
return
3534
}
3635

37-
val workloadSubmissionTime = workload.minOf({ it.submissionTime }).toEpochMilli()
36+
val workloadSubmissionTime = workload.minOf({ it.submissionTime })
3837
val submissionTimeLong = LocalDateTime.parse(submissionTime).toInstant(ZoneOffset.UTC).toEpochMilli()
3938

4039
val timeShift = submissionTimeLong - workloadSubmissionTime
4140

4241
for (task in workload) {
43-
task.submissionTime = Instant.ofEpochMilli(task.submissionTime.toEpochMilli() + timeShift)
42+
task.submissionTime += timeShift
4443
}
4544
}
4645

@@ -54,10 +53,6 @@ public abstract class WorkloadLoader(private val submissionTime: String? = null)
5453

5554
reScheduleTasks(workload)
5655

57-
// if (fraction >= 1.0) {
58-
// return workload
59-
// }
60-
6156
if (fraction <= 0.0) {
6257
throw Error("The fraction of tasks to load cannot be 0.0 or lower")
6358
}
@@ -75,19 +70,6 @@ public abstract class WorkloadLoader(private val submissionTime: String? = null)
7570
currentLoad += entry.totalLoad
7671
}
7772

78-
// val shuffledWorkload = workload.shuffled()
79-
// for (entry in shuffledWorkload) {
80-
// val entryLoad = entry.totalLoad
81-
//
82-
// // TODO: ask Sacheen
83-
// if ((currentLoad + entryLoad) / totalLoad > fraction) {
84-
// break
85-
// }
86-
//
87-
// currentLoad += entryLoad
88-
// res += entry
89-
// }
90-
9173
logger.info { "Sampled ${workload.size} VMs (fraction $fraction) into subset of ${res.size} VMs" }
9274

9375
return res

opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/experiment/specs/ExportModelSpec.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public data class ExportModelSpec(
3737
val computeExportConfig: ComputeExportConfig = ComputeExportConfig.ALL_COLUMNS,
3838
val filesToExport: List<OutputFiles> = OutputFiles.entries.toList(),
3939
var filesToExportDict: MutableMap<OutputFiles, Boolean> = OutputFiles.entries.associateWith { false }.toMutableMap(),
40+
var printFrequency: Int? = 24,
4041
) {
4142
init {
4243
require(exportInterval > 0) { "The Export interval has to be higher than 0" }

opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ScenarioReplayer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public suspend fun ComputeService.replay(
104104

105105
for (entry in trace.sortedBy { it.submissionTime }) {
106106
val now = clock.millis()
107-
val start = entry.submissionTime.toEpochMilli()
107+
val start = entry.submissionTime
108108

109109
// Set the simulationOffset based on the starting time of the first task
110110
if (simulationOffset == Long.MIN_VALUE) {

0 commit comments

Comments
 (0)