diff options
Diffstat (limited to 'opendc-core')
| -rw-r--r-- | opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.kt | 2 | ||||
| -rw-r--r-- | opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt (renamed from opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/DefaultSimulator.kt) | 31 | ||||
| -rw-r--r-- | opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt | 6 |
3 files changed, 23 insertions, 16 deletions
diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.kt index 23bf6818..72494793 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.kt @@ -27,7 +27,7 @@ package nl.atlarge.opendc.simulator import nl.atlarge.opendc.topology.Topology /** - * A [Simulator] implementation runs a simulation over the specified topology. + * A [Simulator] runs a simulation over the specified topology. * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/DefaultSimulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt index 6f025ed1..6b7407e5 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/DefaultSimulator.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt @@ -22,9 +22,10 @@ * SOFTWARE. */ -package nl.atlarge.opendc.simulator +package nl.atlarge.opendc.simulator.omega import mu.KotlinLogging +import nl.atlarge.opendc.simulator.* import nl.atlarge.opendc.simulator.clock.Clock import nl.atlarge.opendc.simulator.clock.Tick import nl.atlarge.opendc.simulator.messaging.Envelope @@ -33,12 +34,18 @@ import java.util.* import kotlin.coroutines.experimental.* /** - * A [DefaultSimulator] runs the simulation over the specified topology. + * The Omega simulator is the default [Simulator] implementation for the OpenDC core. + * + * <p>This simulator implementation is a single-threaded implementation running simulation kernels synchronously and + * provides a single priority queue for all events (messages, ticks, etc) that occur in the components. + * + * <p>By default, [Kernel]s are resolved as part of the [Topology], meaning each [Component] in the topology also + * implements its simulation logic by deriving from the [Kernel] interface. * * @param topology The topology to run the simulation over. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -class DefaultSimulator(override val topology: Topology): Simulator, Iterator<Unit> { +class OmegaSimulator(override val topology: Topology): Simulator, Iterator<Unit> { /** * The logger instance to use for the simulator. */ @@ -57,7 +64,7 @@ class DefaultSimulator(override val topology: Topology): Simulator, Iterator<Uni /** * The clock of the simulator. */ - private val clock: DefaultClock = DefaultClock() + private val clock: OmegaClock = OmegaClock() /** * Initialize the simulator. @@ -92,8 +99,8 @@ class DefaultSimulator(override val topology: Topology): Simulator, Iterator<Uni if (component.label !is Kernel<*>) null else when (component) { - is Node<*> -> DefaultEntityContext(component as Node<*>) - is Edge<*> -> DefaultChannelContext(component as Edge<*>) + is Node<*> -> OmegaEntityContext(component as Node<*>) + is Edge<*> -> OmegaChannelContext(component as Edge<*>) else -> null } }) as Context<T>? @@ -142,11 +149,11 @@ class DefaultSimulator(override val topology: Topology): Simulator, Iterator<Uni /** * The [Context] for an entity within the simulation. */ - private inner class DefaultEntityContext<out T: Entity<*>>(override val component: Node<T>): EntityContext<T> { + private inner class OmegaEntityContext<out T: Entity<*>>(override val component: Node<T>): EntityContext<T> { /** * The [Topology] over which the simulation is run. */ - override val topology: Topology = this@DefaultSimulator.topology + override val topology: Topology = this@OmegaSimulator.topology /** * Retrieves and removes a single message from this channel suspending the caller while the channel is empty. @@ -186,11 +193,11 @@ class DefaultSimulator(override val topology: Topology): Simulator, Iterator<Uni /** * The [Context] for an edge within the simulation. */ - private inner class DefaultChannelContext<out T>(override val component: Edge<T>): ChannelContext<T> { + private inner class OmegaChannelContext<out T>(override val component: Edge<T>): ChannelContext<T> { /** * The [Topology] over which the simulation is run. */ - override val topology: Topology = this@DefaultSimulator.topology + override val topology: Topology = this@OmegaSimulator.topology /** * Retrieves and removes a single message from this channel suspending the caller while the channel is empty. @@ -224,9 +231,9 @@ class DefaultSimulator(override val topology: Topology): Simulator, Iterator<Uni } /** - * The [Clock] for this [DefaultSimulator] that keeps track of the simulation time in ticks. + * The [Clock] for this [OmegaSimulator] that keeps track of the simulation time in ticks. */ - private inner class DefaultClock: Clock { + private inner class OmegaClock : Clock { override var tick: Tick = 0 internal val queue: PriorityQueue<Pair<Tick, () -> Unit>> = PriorityQueue(Comparator.comparingLong { it.first }) diff --git a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt index f56a13e6..7d3c317e 100644 --- a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt +++ b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt @@ -24,7 +24,7 @@ package nl.atlarge.opendc -import nl.atlarge.opendc.simulator.DefaultSimulator +import nl.atlarge.opendc.simulator.omega.OmegaSimulator import nl.atlarge.opendc.topology.AdjacencyListTopologyBuilder import nl.atlarge.opendc.topology.container.Rack import nl.atlarge.opendc.topology.machine.Cpu @@ -37,7 +37,7 @@ internal class SmokeTest { val builder = AdjacencyListTopologyBuilder() val topology = builder.build().apply { val rack = node(Rack()) - val n = 10 + val n = 1000000 // Create n machines in the rack repeat(n) { val machine = node(Machine()) @@ -51,7 +51,7 @@ internal class SmokeTest { } } - val simulator = DefaultSimulator(topology) + val simulator = OmegaSimulator(topology) while (simulator.hasNext()) { simulator.next() } |
