Skip to content

Commit

Permalink
updated logging and added logging for batteries (#301)
Browse files Browse the repository at this point in the history
* Updated logging

* removed DoubleThresholdBatteryPolicy.java
  • Loading branch information
DanteNiewenhuis authored Feb 6, 2025
1 parent df1028c commit 8a3f26b
Show file tree
Hide file tree
Showing 43 changed files with 775 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.opendc.compute.simulator.telemetry.ComputeMetricReader;
import org.opendc.compute.simulator.telemetry.SchedulerStats;
import org.opendc.simulator.compute.power.SimPowerSource;
import org.opendc.simulator.compute.power.batteries.SimBattery;
import org.opendc.simulator.compute.workload.Workload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -108,6 +109,11 @@ public final class ComputeService implements AutoCloseable {
*/
private final Set<SimPowerSource> powerSources = new HashSet<>();

/**
* The available powerSources
*/
private final Set<SimBattery> batteries = new HashSet<>();

/**
* The tasks that should be launched by the service.
*/
Expand Down Expand Up @@ -307,6 +313,15 @@ public void addPowerSource(SimPowerSource simPowerSource) {
powerSources.add(simPowerSource);
}

public void addBattery(SimBattery simBattery) {
// Check if host is already known
if (batteries.contains(simBattery)) {
return;
}

batteries.add(simBattery);
}

/**
* Remove a {@link SimHost} from the scheduling pool of the compute service.
*/
Expand Down Expand Up @@ -341,6 +356,10 @@ public Set<SimPowerSource> getPowerSources() {
return Collections.unmodifiableSet(this.powerSources);
}

public Set<SimBattery> getBatteries() {
return Collections.unmodifiableSet(this.batteries);
}

public void setMetricReader(ComputeMetricReader metricReader) {
this.metricReader = metricReader;
}
Expand Down Expand Up @@ -445,6 +464,7 @@ private void doSchedule() {
final HostView hv = result.getHost();
final SchedulingRequest req = result.getReq();
final ServiceTask task = req.getTask();

final ServiceFlavor flavor = task.getFlavor();

if (task.getNumFailures() >= maxNumFailures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,21 @@ import org.opendc.simulator.engine.graph.FlowGraph
import java.time.Duration
import java.time.Instant
import java.time.InstantSource
import java.util.UUID

/**
* A [Host] implementation that simulates virtual machines on a physical machine.
* A [SimHost] implementation that simulates virtual machines on a physical machine.
*
* @param uid The unique identifier of the host.
* @param name The name of the host.
* @param meta The metadata of the host.
* @param clock The (virtual) clock used to track time.
* @param graph The Flow Graph that the Host is part of
* @param machineModel The static model of the host
* @param powerModel The static powerModel of the CPU TODO: can this be combined with machinemodel?
* @param cpuPowerModel The power model of the host
* @param powerDistributor The power distributor to which the host is connected
* @constructor Create empty Sim host
*/
public class SimHost(
private val uid: UUID,
private val name: String,
private val meta: Map<String, Any>,
private val clusterName: String,
private val clock: InstantSource,
private val graph: FlowGraph,
private val machineModel: MachineModel,
Expand Down Expand Up @@ -170,20 +167,16 @@ public class SimHost(
hostState = state
}

public fun getUid(): UUID {
return uid
}

public fun getName(): String {
return name
}

public fun getModel(): HostModel {
return model
public fun getClusterName(): String {
return clusterName
}

public fun getMeta(): Map<String, *> {
return meta
public fun getModel(): HostModel {
return model
}

public fun getState(): HostState {
Expand Down Expand Up @@ -236,12 +229,12 @@ public class SimHost(
}

public fun start(task: ServiceTask) {
val guest = requireNotNull(taskToGuestMap[task]) { "Unknown task ${task.uid} at host $uid" }
val guest = requireNotNull(taskToGuestMap[task]) { "Unknown task ${task.name} at host $name" }
guest.start()
}

public fun stop(task: ServiceTask) {
val guest = requireNotNull(taskToGuestMap[task]) { "Unknown task ${task.uid} at host $uid" }
val guest = requireNotNull(taskToGuestMap[task]) { "Unknown task ${task.name} at host $name" }
guest.stop()
}

Expand Down Expand Up @@ -308,7 +301,7 @@ public class SimHost(
}

public fun getSystemStats(task: ServiceTask): GuestSystemStats {
val guest = requireNotNull(taskToGuestMap[task]) { "Unknown task ${task.uid} at host $uid" }
val guest = requireNotNull(taskToGuestMap[task]) { "Unknown task ${task.name} at host $name" }
return guest.getSystemStats()
}

Expand All @@ -330,17 +323,17 @@ public class SimHost(
}

public fun getCpuStats(task: ServiceTask): GuestCpuStats {
val guest = requireNotNull(taskToGuestMap[task]) { "Unknown task ${task.uid} at host $uid" }
val guest = requireNotNull(taskToGuestMap[task]) { "Unknown task ${task.name} at host $name" }
return guest.getCpuStats()
}

override fun hashCode(): Int = uid.hashCode()
override fun hashCode(): Int = name.hashCode()

override fun equals(other: Any?): Boolean {
return other is SimHost && uid == other.uid
return other is SimHost && name == other.name
}

override fun toString(): String = "SimHost[uid=$uid,name=$name,model=$model]"
override fun toString(): String = "SimHost[uid=$name,name=$name,model=$model]"

/**
* Convert flavor to machine model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import org.opendc.simulator.engine.graph.FlowDistributor
* A [ProvisioningStep] that provisions a list of hosts for a [ComputeService].
*
* @param serviceDomain The domain name under which the compute service is registered.
* @param specs A list of [HostSpec] objects describing the simulated hosts to provision.
* @param optimize A flag to indicate that the CPU resources of the host should be merged into a single CPU resource.
* @param clusterSpecs A list of [HostSpec] objects describing the simulated hosts to provision.
* @param startTime The absolute start time of the simulation. Used to determine the carbon trace offset.
*/
public class HostsProvisioningStep internal constructor(
private val serviceDomain: String,
Expand All @@ -62,7 +62,7 @@ public class HostsProvisioningStep internal constructor(
// Create the Power Source to which hosts are connected

// Create Power Source
val simPowerSource = SimPowerSource(graph, cluster.powerSource.totalPower.toDouble())
val simPowerSource = SimPowerSource(graph, cluster.powerSource.totalPower.toDouble(), cluster.powerSource.name, cluster.name)
simPowerSources.add(simPowerSource)
service.addPowerSource(simPowerSource)

Expand All @@ -84,7 +84,14 @@ public class HostsProvisioningStep internal constructor(

// Create Battery
val battery =
SimBattery(graph, cluster.battery!!.capacity, cluster.battery!!.chargingSpeed, cluster.battery!!.initialCharge)
SimBattery(
graph,
cluster.battery!!.capacity,
cluster.battery!!.chargingSpeed,
cluster.battery!!.initialCharge,
cluster.battery!!.name,
cluster.name,
)
graph.addEdge(battery, batteryDistributor)

// Create Aggregator
Expand All @@ -102,6 +109,8 @@ public class HostsProvisioningStep internal constructor(
carbonModel?.addReceiver(batteryPolicy)

graph.addEdge(hostDistributor, batteryAggregator)

service.addBattery(battery)
} else {
graph.addEdge(hostDistributor, simPowerSource)
}
Expand All @@ -110,17 +119,16 @@ public class HostsProvisioningStep internal constructor(
for (hostSpec in cluster.hostSpecs) {
val simHost =
SimHost(
hostSpec.uid,
hostSpec.name,
hostSpec.meta,
cluster.name,
ctx.dispatcher.timeSource,
graph,
hostSpec.model,
hostSpec.cpuPowerModel,
hostDistributor,
)

require(simHosts.add(simHost)) { "Host with uid ${hostSpec.uid} already exists" }
require(simHosts.add(simHost)) { "Host with name ${hostSpec.name} already exists" }
service.addHost(simHost)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ import org.opendc.common.asCoroutineDispatcher
import org.opendc.compute.simulator.host.SimHost
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.simulator.service.ServiceTask
import org.opendc.compute.simulator.telemetry.table.HostTableReaderImpl
import org.opendc.compute.simulator.telemetry.table.PowerSourceTableReaderImpl
import org.opendc.compute.simulator.telemetry.table.ServiceTableReaderImpl
import org.opendc.compute.simulator.telemetry.table.TaskTableReaderImpl
import org.opendc.compute.simulator.telemetry.table.battery.BatteryTableReaderImpl
import org.opendc.compute.simulator.telemetry.table.host.HostTableReaderImpl
import org.opendc.compute.simulator.telemetry.table.powerSource.PowerSourceTableReaderImpl
import org.opendc.compute.simulator.telemetry.table.service.ServiceTableReaderImpl
import org.opendc.compute.simulator.telemetry.table.task.TaskTableReaderImpl
import org.opendc.simulator.compute.power.SimPowerSource
import org.opendc.simulator.compute.power.batteries.SimBattery
import java.time.Duration

/**
Expand Down Expand Up @@ -85,6 +87,11 @@ public class ComputeMetricReader(
*/
private val powerSourceTableReaders = mutableMapOf<SimPowerSource, PowerSourceTableReaderImpl>()

/**
* Mapping from [SimPowerSource] instances to [PowerSourceTableReaderImpl]
*/
private val batteryTableReaders = mutableMapOf<SimBattery, BatteryTableReaderImpl>()

/**
* The background job that is responsible for collecting the metrics every cycle.
*/
Expand Down Expand Up @@ -155,6 +162,20 @@ public class ComputeMetricReader(
reader.reset()
}

for (simBattery in this.service.batteries) {
val reader =
this.batteryTableReaders.computeIfAbsent(simBattery) {
BatteryTableReaderImpl(
it,
startTime,
)
}

reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
}

this.serviceTableReader.record(now)
monitor.record(this.serviceTableReader.copy())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

package org.opendc.compute.simulator.telemetry

import org.opendc.compute.simulator.telemetry.table.HostTableReader
import org.opendc.compute.simulator.telemetry.table.PowerSourceTableReader
import org.opendc.compute.simulator.telemetry.table.ServiceTableReader
import org.opendc.compute.simulator.telemetry.table.TaskTableReader
import org.opendc.compute.simulator.telemetry.table.battery.BatteryTableReader
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

/**
* A monitor that tracks the metrics and events of the OpenDC Compute service.
Expand All @@ -46,6 +47,11 @@ public interface ComputeMonitor {
*/
public fun record(reader: PowerSourceTableReader) {}

/**
* Record an entry with the specified [reader].
*/
public fun record(reader: BatteryTableReader) {}

/**
* Record an entry with the specified [reader].
*/
Expand Down
Loading

0 comments on commit 8a3f26b

Please sign in to comment.