Simulation

We will now show how the same implementation of a distributed system, which is designed for production deployment, is also executable in simulation mode for stepped debugging, protocol correctness testing, or for repeatable studies of the dynamic behaviour of large-scale peer-to-peer systems.

In order to allow the debugging of code, we require deterministic execution during simulation. We achieve this by executing all events and messages in a deterministic fashion and, additionally, removing other sources of nondeterminism.

Possible sources of nondeterminism include:

  1. system time
  2. random generators
  3. thread creation/execution
  4. network, e.g. latency, packet loss
  5. input/output sources

At a high level, a simulation experiment is specified as a SimulationScenario class, that describes the occurence of events such as starting/stopping a node, changing the parameters of the network, or terminating the simulation. Such a SimulationScenario is then executed by the P2pSimulator in a single-threaded, deterministic fashion.

Dependencies

The examples in this tutorial require a new dependency, which is different depending whether you are using Java or Scala.

Kompics Simulator

The kompics-simulator module contains the core definitions and the runtime for the Kompics Simulator framework. It is the required dependency in Kompics Java.

sbt
libraryDependencies += "se.sics.kompics.simulator" % "kompics-simulator" % "1.2.1"
Maven
<dependency>
  <groupId>se.sics.kompics.simulator</groupId>
  <artifactId>kompics-simulator</artifactId>
  <version>1.2.1</version>
</dependency>
Gradle
dependencies {
  compile group: 'se.sics.kompics.simulator', name: 'kompics-simulator', version: '1.2.1'
}

Kompics Scala Simulator

The kompics-scala-simulator module provides the Scala DSL for Kompics Simulator. Like with Kompics Core, projects including it as a dependency should elide the kompics-simulator dependency above, as it is automatically pulled in as a transitive dependency in the correct version.

sbt
libraryDependencies += "se.sics.kompics.sl" %% "kompics-scala-simulator" % "2.0.0"
Maven
<dependency>
  <groupId>se.sics.kompics.sl</groupId>
  <artifactId>kompics-scala-simulator_2.13</artifactId>
  <version>2.0.0</version>
</dependency>
Gradle
dependencies {
  compile group: 'se.sics.kompics.sl', name: 'kompics-scala-simulator_2.13', version: '2.0.0'
}

Contents

The source code for this page can be found here.