1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
/*
* 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
* 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.experiments.base
import org.opendc.common.ResourceType
import org.opendc.compute.simulator.provisioner.Provisioner
import org.opendc.compute.simulator.provisioner.registerComputeMonitor
import org.opendc.compute.simulator.provisioner.setupComputeService
import org.opendc.compute.simulator.provisioner.setupHosts
import org.opendc.compute.simulator.scheduler.ComputeScheduler
import org.opendc.compute.simulator.scheduler.FilterScheduler
import org.opendc.compute.simulator.scheduler.filters.ComputeFilter
import org.opendc.compute.simulator.scheduler.filters.RamFilter
import org.opendc.compute.simulator.scheduler.filters.VCpuFilter
import org.opendc.compute.simulator.scheduler.weights.CoreRamWeigher
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.simulator.service.ServiceTask
import org.opendc.compute.simulator.telemetry.ComputeMonitor
import org.opendc.compute.simulator.telemetry.table.host.HostTableReader
import org.opendc.compute.simulator.telemetry.table.powerSource.PowerSourceTableReader
import org.opendc.compute.simulator.telemetry.table.service.ServiceTableReader
import org.opendc.compute.simulator.telemetry.table.task.TaskTableReader
import org.opendc.compute.topology.clusterTopology
import org.opendc.compute.topology.specs.ClusterSpec
import org.opendc.experiments.base.experiment.specs.FailureModelSpec
import org.opendc.experiments.base.runner.replay
import org.opendc.simulator.compute.workload.trace.TraceFragment
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
import org.opendc.simulator.kotlin.runSimulation
import java.time.Duration
import java.time.LocalDateTime
import java.time.ZoneOffset
import kotlin.collections.ArrayList
/**
* Obtain the topology factory for the test.
*/
fun createTopology(name: String): List<ClusterSpec> {
val stream = checkNotNull(object {}.javaClass.getResourceAsStream("/topologies/$name"))
return stream.use { clusterTopology(stream) }
}
fun createTestTask(
id: Int,
name: String = "",
memCapacity: Long = 0L,
submissionTime: String = "1970-01-01T00:00",
duration: Long = 0L,
cpuCoreCount: Int = 1,
gpuCoreCount: Int = 0,
fragments: ArrayList<TraceFragment>,
checkpointInterval: Long = 0L,
checkpointDuration: Long = 0L,
checkpointIntervalScaling: Double = 1.0,
scalingPolicy: ScalingPolicy = NoDelayScaling(),
parents: ArrayList<Int> = ArrayList<Int>(),
children: Set<Int> = emptySet(),
): ServiceTask {
var usedResources = arrayOf<ResourceType>()
if (fragments.any { it.cpuUsage > 0.0 }) {
usedResources += ResourceType.CPU
}
if (fragments.any { it.gpuUsage > 0.0 }) {
usedResources += ResourceType.GPU
}
return ServiceTask(
id,
name,
LocalDateTime.parse(submissionTime).toInstant(ZoneOffset.UTC).toEpochMilli(),
duration,
cpuCoreCount,
fragments.maxOf { it.cpuUsage },
1800000.0,
memCapacity,
gpuCoreCount,
fragments.maxOfOrNull { it.gpuUsage } ?: 0.0,
0L,
TraceWorkload(
fragments,
checkpointInterval,
checkpointDuration,
checkpointIntervalScaling,
scalingPolicy,
id,
usedResources,
),
false,
-1,
parents,
children,
)
}
fun runTest(
topology: List<ClusterSpec>,
workload: ArrayList<ServiceTask>,
failureModelSpec: FailureModelSpec? = null,
computeScheduler: ComputeScheduler =
FilterScheduler(
filters = listOf(ComputeFilter(), VCpuFilter(1.0), RamFilter(1.0)),
weighers = listOf(CoreRamWeigher(multiplier = 1.0)),
),
): TestComputeMonitor {
val monitor = TestComputeMonitor()
runSimulation {
val seed = 0L
Provisioner(dispatcher, seed).use { provisioner ->
val startTimeLong = workload.minOf { it.submittedAt }
val startTime = Duration.ofMillis(startTimeLong)
provisioner.runSteps(
setupComputeService(serviceDomain = "compute.opendc.org", { computeScheduler }),
registerComputeMonitor(serviceDomain = "compute.opendc.org", monitor, exportInterval = Duration.ofMinutes(1), startTime),
setupHosts(serviceDomain = "compute.opendc.org", topology, startTimeLong),
)
val service = provisioner.registry.resolve("compute.opendc.org", ComputeService::class.java)!!
service.setTasksExpected(workload.size)
service.setMetricReader(provisioner.getMonitor())
val workloadCopy = ArrayList<ServiceTask>()
for (task in workload) {
workloadCopy.add(task.copy())
}
service.replay(timeSource, ArrayDeque(workloadCopy), failureModelSpec = failureModelSpec)
}
}
return monitor
}
class TestComputeMonitor : ComputeMonitor {
var taskCpuDemands = mutableMapOf<Int, ArrayList<Double>>()
var taskCpuSupplied = mutableMapOf<Int, ArrayList<Double>>()
var taskGpuDemands = mutableMapOf<Int, ArrayList<Double?>?>()
var taskGpuSupplied = mutableMapOf<Int, ArrayList<Double?>?>()
override fun record(reader: TaskTableReader) {
val taskName: Int = reader.taskInfo.id
if (taskName in taskCpuDemands) {
taskCpuDemands[taskName]?.add(reader.cpuDemand)
taskCpuSupplied[taskName]?.add(reader.cpuUsage)
} else {
taskCpuDemands[taskName] = arrayListOf(reader.cpuDemand)
taskCpuSupplied[taskName] = arrayListOf(reader.cpuUsage)
}
if (taskName in taskGpuDemands) {
taskGpuDemands[taskName]?.add(reader.gpuDemand)
taskGpuSupplied[taskName]?.add(reader.gpuUsage)
} else {
taskGpuDemands[taskName] = arrayListOf(reader.gpuDemand)
taskGpuSupplied[taskName] = arrayListOf(reader.gpuUsage)
}
}
var attemptsSuccess = 0
var attemptsFailure = 0
var attemptsError = 0
var tasksPending = 0
var tasksActive = 0
var tasksTerminated = 0
var tasksCompleted = 0
var timestamps = ArrayList<Long>()
var absoluteTimestamps = ArrayList<Long>()
var maxTimestamp = 0L
override fun record(reader: ServiceTableReader) {
attemptsSuccess = reader.attemptsSuccess
attemptsFailure = reader.attemptsFailure
attemptsError = 0
tasksPending = reader.tasksPending
tasksActive = reader.tasksActive
tasksTerminated = reader.tasksTerminated
tasksCompleted = reader.tasksCompleted
timestamps.add(reader.timestamp.toEpochMilli())
absoluteTimestamps.add(reader.timestampAbsolute.toEpochMilli())
maxTimestamp = reader.timestamp.toEpochMilli()
}
var hostCpuDemands = mutableMapOf<String, ArrayList<Double>>()
var hostCpuSupplied = mutableMapOf<String, ArrayList<Double>>()
var hostCpuIdleTimes = mutableMapOf<String, ArrayList<Long>>()
var hostCpuActiveTimes = mutableMapOf<String, ArrayList<Long>>()
var hostCpuStealTimes = mutableMapOf<String, ArrayList<Long>>()
var hostCpuLostTimes = mutableMapOf<String, ArrayList<Long>>()
var hostGpuDemands = mutableMapOf<String, ArrayList<ArrayList<Double>>>()
var hostGpuSupplied = mutableMapOf<String, ArrayList<ArrayList<Double>>>()
var hostGpuIdleTimes = mutableMapOf<String, ArrayList<ArrayList<Long>>>()
var hostGpuActiveTimes = mutableMapOf<String, ArrayList<ArrayList<Long>>>()
var hostGpuStealTimes = mutableMapOf<String, ArrayList<ArrayList<Long>>>()
var hostGpuLostTimes = mutableMapOf<String, ArrayList<ArrayList<Long>>>()
var hostPowerDraws = mutableMapOf<String, ArrayList<Double>>()
var hostEnergyUsages = mutableMapOf<String, ArrayList<Double>>()
override fun record(reader: HostTableReader) {
val hostName: String = reader.hostInfo.name
if (!(hostName in hostCpuDemands)) {
hostCpuIdleTimes[hostName] = ArrayList()
hostCpuActiveTimes[hostName] = ArrayList()
hostCpuStealTimes[hostName] = ArrayList()
hostCpuLostTimes[hostName] = ArrayList()
hostCpuDemands[hostName] = ArrayList()
hostCpuSupplied[hostName] = ArrayList()
hostPowerDraws[hostName] = ArrayList()
hostEnergyUsages[hostName] = ArrayList()
}
if (hostName !in hostGpuDemands) {
hostGpuDemands[hostName] = ArrayList()
hostGpuSupplied[hostName] = ArrayList()
hostGpuIdleTimes[hostName] = ArrayList()
hostGpuActiveTimes[hostName] = ArrayList()
hostGpuStealTimes[hostName] = ArrayList()
hostGpuLostTimes[hostName] = ArrayList()
}
hostCpuDemands[hostName]?.add(reader.cpuDemand)
hostCpuSupplied[hostName]?.add(reader.cpuUsage)
hostCpuIdleTimes[hostName]?.add(reader.cpuIdleTime)
hostCpuActiveTimes[hostName]?.add(reader.cpuActiveTime)
hostCpuStealTimes[hostName]?.add(reader.cpuStealTime)
hostCpuLostTimes[hostName]?.add(reader.cpuLostTime)
hostGpuDemands[hostName]?.add(reader.gpuDemands)
hostGpuSupplied[hostName]?.add(reader.gpuUsages)
hostGpuIdleTimes[hostName]?.add(reader.gpuIdleTimes)
hostGpuActiveTimes[hostName]?.add(reader.gpuActiveTimes)
hostGpuStealTimes[hostName]?.add(reader.gpuStealTimes)
hostGpuLostTimes[hostName]?.add(reader.gpuLostTimes)
hostPowerDraws[hostName]?.add(reader.powerDraw)
hostEnergyUsages[hostName]?.add(reader.energyUsage)
}
var powerDraws = ArrayList<Double>()
var energyUsages = ArrayList<Double>()
var carbonIntensities = ArrayList<Double>()
var carbonEmissions = ArrayList<Double>()
override fun record(reader: PowerSourceTableReader) {
powerDraws.add(reader.powerDraw)
energyUsages.add(reader.energyUsage)
carbonIntensities.add(reader.carbonIntensity)
carbonEmissions.add(reader.carbonEmission)
}
}
|