Skip to content

Commit

Permalink
Move ConvoyRebroadcast performance test to extra executable class
Browse files Browse the repository at this point in the history
  • Loading branch information
vladamatena committed May 20, 2015
1 parent ca6048d commit bfabce5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cz.cuni.mff.d3s.jdeeco.network.demo.convoy;

import java.util.Random;

import cz.cuni.mff.d3s.deeco.runners.DEECoSimulation;
import cz.cuni.mff.d3s.deeco.runtime.DEECoNode;
import cz.cuni.mff.d3s.deeco.timer.DiscreteEventTimer;
import cz.cuni.mff.d3s.deeco.timer.SimulationTimer;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.ConvoyEnsemble;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.Follower;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.Leader;
import cz.cuni.mff.d3s.jdeeco.network.Network;
import cz.cuni.mff.d3s.jdeeco.network.device.SimpleBroadcastDevice;
import cz.cuni.mff.d3s.jdeeco.network.l2.strategy.KnowledgeInsertingStrategy;
import cz.cuni.mff.d3s.jdeeco.network.l2.strategy.RebroadcastStrategy;
import cz.cuni.mff.d3s.jdeeco.position.PositionPlugin;
import cz.cuni.mff.d3s.jdeeco.publishing.DefaultKnowledgePublisher;

public class ConvoyReboradcastPerformanceTest {
/**
* Tests the performance of the rebroadcast system
*
* ### This is not to be run automatically. ###
*
* Instantiates a lot of nodes and tries rebroadcast.
*
* @throws Exception
*
*/
public static void main(String[] args) throws Exception {
final long SIMULATION_DURATION_MS = 120000;

// Create main application container
SimulationTimer simulationTimer = new DiscreteEventTimer(); // also "new WallTimeSchedulerNotifier()"
DEECoSimulation realm = new DEECoSimulation(simulationTimer);
realm.addPlugin(new SimpleBroadcastDevice(25, 5, 250, 128));
realm.addPlugin(Network.class);
realm.addPlugin(KnowledgeInsertingStrategy.class);
realm.addPlugin(RebroadcastStrategy.class);
realm.addPlugin(DefaultKnowledgePublisher.class);

final int PLAYGROUND_WIDTH = 1000;
final int PLAYGROUND_HEIGHT = 1000;
final int NODES = 50;
final Random rand = new Random(42);

for (int i = 0; i < NODES; ++i) {
// Create DEECo node 1 - leader
DEECoNode deeco = realm.createNode(new PositionPlugin(rand.nextInt(PLAYGROUND_WIDTH), rand
.nextInt(PLAYGROUND_HEIGHT)));

if (rand.nextBoolean()) {
// Deploy components and ensembles
deeco.deployComponent(new Leader("L" + i, System.out, simulationTimer));
} else {
// Deploy components and ensembles
deeco.deployComponent(new Follower("F" + i, System.out, simulationTimer));
}

deeco.deployEnsemble(ConvoyEnsemble.class);
}

long startTime = System.currentTimeMillis();

// Run the simulation
realm.start(SIMULATION_DURATION_MS);

long endTime = System.currentTimeMillis();

System.out.format("Done, %d ms simulated in %d real ms. Sim/Real %f%n", SIMULATION_DURATION_MS, endTime - startTime, (double)(SIMULATION_DURATION_MS) / (endTime - startTime));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Random;

import org.junit.Ignore;
import org.junit.Test;

import cz.cuni.mff.d3s.deeco.runners.DEECoSimulation;
Expand Down Expand Up @@ -93,52 +91,5 @@ private void convoyRebroadcastLoopbackRunner(boolean silent) throws Exception {
assertThat(baos.toString(), containsString("Follower F0: me = (1,3) leader = (1,3)"));
assertThat(baos.toString(), containsString("Follower F1: me = (1,3) leader = (1,3)"));
}
}

/**
* Tests the performance of the rebroadcast system
*
* ### This is not to be run automatically. ###
*
* Instantiates a lot of nodes and tries rebroadcast.
*
* @throws Exception
*
*/
@Test
@Ignore("Please use this only to verify performance")
public void rebroadcastingPerformanceTest() throws Exception {
// Create main application container
SimulationTimer simulationTimer = new DiscreteEventTimer(); // also "new WallTimeSchedulerNotifier()"
DEECoSimulation realm = new DEECoSimulation(simulationTimer);
realm.addPlugin(new SimpleBroadcastDevice(25, 5, 250, 128));
realm.addPlugin(Network.class);
realm.addPlugin(KnowledgeInsertingStrategy.class);
realm.addPlugin(RebroadcastStrategy.class);
realm.addPlugin(DefaultKnowledgePublisher.class);

final int PLAYGROUND_WIDTH = 1000;
final int PLAYGROUND_HEIGHT = 1000;
final int NODES = 50;
final Random rand = new Random(42);

for (int i = 0; i < NODES; ++i) {
// Create DEECo node 1 - leader
DEECoNode deeco = realm.createNode(new PositionPlugin(rand.nextInt(PLAYGROUND_WIDTH), rand
.nextInt(PLAYGROUND_HEIGHT)));

if (rand.nextBoolean()) {
// Deploy components and ensembles
deeco.deployComponent(new Leader("L" + i, System.out, simulationTimer));
} else {
// Deploy components and ensembles
deeco.deployComponent(new Follower("F" + i, System.out, simulationTimer));
}

deeco.deployEnsemble(ConvoyEnsemble.class);
}

// WHEN simulation is performed
realm.start(120000);
}
}
}

0 comments on commit bfabce5

Please sign in to comment.