Search in sources :

Example 16 with Execution

use of teetime.framework.Execution in project TeeTime by teetime-framework.

the class LoggedWordCounterTest method main.

public static void main(final String[] args) throws UnsupportedEncodingException, FileNotFoundException {
    int numWorkerThreads;
    try {
        numWorkerThreads = Integer.valueOf(args[0]);
    } catch (final NumberFormatException e) {
        numWorkerThreads = 3;
    }
    LOGGER.info("# worker threads: " + numWorkerThreads);
    int numWarmUps;
    try {
        numWarmUps = Integer.valueOf(args[1]);
    } catch (final NumberFormatException e) {
        numWarmUps = 1;
    }
    LOGGER.info("# warm ups: " + numWarmUps);
    final long[] timings = new long[1];
    final String fileName = args[2];
    final File testFile = new File(fileName);
    final StopWatch stopWatch = new StopWatch();
    for (int i = 0; i < numWarmUps; i++) {
        LOGGER.info("Warm up #" + i);
        final LoggedWordCounterConfiguration wcc = new LoggedWordCounterConfiguration(numWorkerThreads, testFile);
        final Execution<?> analysis = new Execution<LoggedWordCounterConfiguration>(wcc);
        stopWatch.start();
        analysis.executeBlocking();
        stopWatch.end();
        LOGGER.info("duration: " + TimeUnit.NANOSECONDS.toSeconds(stopWatch.getDurationInNs()) + " secs");
    }
    LOGGER.info("Starting analysis...");
    final WordCounterConfiguration wcc = new WordCounterConfiguration(numWorkerThreads, testFile);
    final Execution<?> analysis = new Execution<WordCounterConfiguration>(wcc);
    wcc.getMonitoringThread().start();
    stopWatch.start();
    analysis.executeBlocking();
    stopWatch.end();
    wcc.getMonitoringThread().terminate();
    LOGGER.info("duration: " + TimeUnit.NANOSECONDS.toMillis(stopWatch.getDurationInNs()) + " milli secs");
    timings[0] = stopWatch.getDurationInNs();
    // System.out.println("exceptions: " + exceptions);
    final CountingMap<String> map = wcc.getResult();
    System.out.println("vero: " + (map.get("vero") == 3813850) + "->" + map.get("vero") + " should be " + 3813850);
    System.out.println("sit: " + (map.get("sit") == 7627700) + "->" + map.get("sit") + " should be " + 7627700);
    final File outputFile = new File("timings.txt");
    writeTimingsToFile(outputFile, timings);
    System.out.println("distributor pipes:");
    for (final AbstractPort<?> port : wcc.getDistributorPorts()) {
        final IMonitorablePipe spscPipe = (IMonitorablePipe) port.getPipe();
        System.out.println("numWaits: " + spscPipe.getNumWaits());
    }
    System.out.println("merger pipes:");
    for (final AbstractPort<?> port : wcc.getMergerPorts()) {
        final IMonitorablePipe spscPipe = (IMonitorablePipe) port.getPipe();
        System.out.println("numWaits: " + spscPipe.getNumWaits());
    }
    System.out.println("distributor waits: " + ((NonBlockingRoundRobinStrategy) wcc.getDistributor().getStrategy()).getNumWaits());
    System.out.println(ActivationStateLogger.getInstance());
    ActivationStateLogger.getInstance().logToFile();
}
Also used : IMonitorablePipe(teetime.framework.pipe.IMonitorablePipe) StopWatch(teetime.util.StopWatch) NonBlockingRoundRobinStrategy(teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy) Execution(teetime.framework.Execution) File(java.io.File)

Example 17 with Execution

use of teetime.framework.Execution in project TeeTime by teetime-framework.

the class OneExecutionProducerIT method testRegularExecution.

void testRegularExecution(final List<String> expectedElements, final int numThreads) {
    for (int numOfExecutions = 1; numOfExecutions < expectedElements.size() + 1; numOfExecutions++) {
        List<String> actualElements = new ArrayList<>();
        Configuration configuration = new Configuration().from(new InitialElementProducer<String>(expectedElements)).end(new CollectorSink<String>(actualElements));
        GlobalTaskPoolScheduling scheduler = new GlobalTaskPoolScheduling(numThreads, configuration, numOfExecutions);
        Execution<Configuration> execution = new Execution<>(configuration, true, scheduler);
        execution.executeBlocking();
        assertThat("failed with numOfExecutions=" + numOfExecutions, actualElements, is(equalTo(expectedElements)));
    }
}
Also used : InitialElementProducer(teetime.stage.InitialElementProducer) Execution(teetime.framework.Execution) Configuration(teetime.framework.Configuration) ArrayList(java.util.ArrayList)

Example 18 with Execution

use of teetime.framework.Execution in project TeeTime by teetime-framework.

the class DynamicTaskFarmStageTest method testDynamicTaskFarmStage.

@Test
@Ignore("declareActive at runtime is required, but not yet implemented/merged")
public void testDynamicTaskFarmStage() throws Exception {
    final Integer[] elements = { 1, 2, 3 };
    final ElementTrigger<Integer> producer = new ElementTrigger<Integer>(elements);
    final DynamicTaskFarmStage<Integer, Integer, Counter<Integer>> dynamicTaskFarmStage = new DynamicTaskFarmStage<Integer, Integer, Counter<Integer>>(new Counter<Integer>(), 1);
    final CollectorSink<Integer> collectorSink = new CollectorSink<Integer>();
    Configuration configuration = new Configuration() {

        {
            connectPorts(producer.getOutputPort(), dynamicTaskFarmStage.getInputPort());
            connectPorts(dynamicTaskFarmStage.getOutputPort(), collectorSink.getInputPort());
        }
    };
    Execution<Configuration> execution = new Execution<Configuration>(configuration);
    execution.executeNonBlocking();
    producer.trigger();
    assertThat(dynamicTaskFarmStage.getMerger().isActive(), is(false));
    dynamicTaskFarmStage.addStageAtRuntime();
    producer.trigger();
    // assertThat(dynamicTaskFarmStage.getMerger().isActive(), is(true)); // TODO uncomment if "declareActive at runtime" is implemented
    dynamicTaskFarmStage.removeStageAtRuntime();
    producer.trigger();
    // assertThat(dynamicTaskFarmStage.getMerger().isActive(), is(false)); // TODO uncomment if "declareActive at runtime" is implemented
    execution.abortEventually();
}
Also used : Configuration(teetime.framework.Configuration) CollectorSink(teetime.stage.CollectorSink) Counter(teetime.stage.Counter) Execution(teetime.framework.Execution) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with Execution

use of teetime.framework.Execution in project iobserve-analysis by research-iobserve.

the class ComposedActionComputationTest method executeStage.

private SystemAdaptation executeStage(final AdaptationData adaptationData) {
    final InitialElementProducer<AdaptationData> producer = new InitialElementProducer<>(adaptationData);
    final ComposedActionComputation composedActionComputation = new ComposedActionComputation();
    final CollectorSink<SystemAdaptation> collector = new CollectorSink<>();
    final ComposedActionComputationTestConfig configuration = new ComposedActionComputationTestConfig(producer, this.actionFactoryInitializer, composedActionComputation, collector);
    final Execution<ComposedActionComputationTestConfig> execution = new Execution<>(configuration);
    execution.executeBlocking();
    return collector.getElements().get(0);
}
Also used : SystemAdaptation(org.iobserve.planning.systemadaptation.SystemAdaptation) InitialElementProducer(teetime.stage.InitialElementProducer) Execution(teetime.framework.Execution) CollectorSink(teetime.stage.CollectorSink) AdaptationData(org.iobserve.adaptation.data.AdaptationData) ComposedActionComputation(org.iobserve.adaptation.stages.ComposedActionComputation)

Aggregations

Execution (teetime.framework.Execution)19 Test (org.junit.Test)10 TeeTimeScheduler (teetime.framework.TeeTimeScheduler)10 Configuration (teetime.framework.Configuration)7 ArrayList (java.util.ArrayList)6 CollectorSink (teetime.stage.CollectorSink)6 File (java.io.File)3 List (java.util.List)3 IntStream (java.util.stream.IntStream)3 Matchers (org.hamcrest.Matchers)3 Assert (org.junit.Assert)3 IMonitorablePipe (teetime.framework.pipe.IMonitorablePipe)3 Counter (teetime.stage.Counter)3 InitialElementProducer (teetime.stage.InitialElementProducer)3 StreamProducer (teetime.stage.StreamProducer)3 NonBlockingRoundRobinStrategy (teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy)3 StopWatch (teetime.util.StopWatch)3 SystemAdaptation (org.iobserve.planning.systemadaptation.SystemAdaptation)2 FixMethodOrder (org.junit.FixMethodOrder)2 Ignore (org.junit.Ignore)2