Search in sources :

Example 1 with NonBlockingRoundRobinStrategy

use of teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy in project TeeTime by teetime-framework.

the class WordCounterTest method main.

public static void main(final String[] args) throws UnsupportedEncodingException, FileNotFoundException {
    // http://www.loremipsum.de/downloads/original.txt
    String numWorkerThreadsParam = (args.length > 0) ? args[0] : "3";
    String numWarmUpsParam = (args.length > 1) ? args[1] : "1";
    String fileNameParam = (args.length > 2) ? args[2] : "no default file name";
    String monitoringEnabledParam = (args.length > 3) ? args[3] : "true";
    int numWorkerThreads = parseAsInteger(numWorkerThreadsParam, 3);
    LOGGER.info("# worker threads: " + numWorkerThreads);
    int numWarmUps = parseAsInteger(numWarmUpsParam, 1);
    LOGGER.info("# warm ups: " + numWarmUps);
    final String fileName = fileNameParam;
    final File testFile = new File(fileName);
    LOGGER.info("Reading {}", testFile.getAbsolutePath());
    boolean monitoringEnabled = Boolean.valueOf(monitoringEnabledParam);
    final long[] timings = new long[1];
    final StopWatch stopWatch = new StopWatch();
    for (int i = 0; i < numWarmUps; i++) {
        LOGGER.info("Warm up #" + i);
        final WordCounterConfiguration wcc = new WordCounterConfiguration(numWorkerThreads, testFile);
        final Execution<?> analysis = new Execution<WordCounterConfiguration>(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);
    if (monitoringEnabled) {
        wcc.getMonitoringThread().start();
    }
    stopWatch.start();
    analysis.executeBlocking();
    stopWatch.end();
    wcc.getMonitoringThread().terminate();
    LOGGER.info("duration: " + TimeUnit.NANOSECONDS.toSeconds(stopWatch.getDurationInNs()) + " secs");
    timings[0] = stopWatch.getDurationInNs();
    // results for some words to verify the correctness of the word counter
    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);
    // some statistics about the output pipes of the distributor
    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("distributor waits: " + ((NonBlockingRoundRobinStrategy) wcc.getDistributor().getStrategy()).getNumWaits());
    // some statistics about the output pipes of the distributor
    System.out.println("merger pipes:");
    for (final AbstractPort<?> port : wcc.getMergerPorts()) {
        final IMonitorablePipe spscPipe = (IMonitorablePipe) port.getPipe();
        System.out.println("numWaits: " + spscPipe.getNumWaits());
    }
}
Also used : IMonitorablePipe(teetime.framework.pipe.IMonitorablePipe) StopWatch(teetime.util.StopWatch) NonBlockingRoundRobinStrategy(teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy) Execution(teetime.framework.Execution)

Example 2 with NonBlockingRoundRobinStrategy

use of teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy in project TeeTime by teetime-framework.

the class DistributorTest method roundRobin2ShouldWork.

@Test
public void roundRobin2ShouldWork() {
    distributor.setStrategy(new NonBlockingRoundRobinStrategy());
    test(distributor).and().send(1, 2, 3, 4, 5).to(distributor.getInputPort()).and().receive(firstIntegers).from(distributor.getNewOutputPort()).and().receive(secondIntegers).from(distributor.getNewOutputPort()).start();
    assertThat(this.firstIntegers, contains(1, 3, 5));
    assertThat(this.secondIntegers, contains(2, 4));
}
Also used : NonBlockingRoundRobinStrategy(teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy) Test(org.junit.Test)

Example 3 with NonBlockingRoundRobinStrategy

use of teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy 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 4 with NonBlockingRoundRobinStrategy

use of teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy in project TeeTime by teetime-framework.

the class WordCounterTestWithGlobalTaskPool method main.

public static void main(final String[] args) throws UnsupportedEncodingException, FileNotFoundException {
    String numWorkerThreadsParam = (args.length > 0) ? args[0] : "3";
    String numWarmUpsParam = (args.length > 1) ? args[1] : "1";
    String fileNameParam = (args.length > 2) ? args[2] : "data\\wordcounter\\medium_textfile.txt";
    String monitoringEnabledParam = (args.length > 3) ? args[3] : "true";
    int numWorkerThreads = parseAsInteger(numWorkerThreadsParam, 3);
    LOGGER.info("# worker threads: " + numWorkerThreads);
    int numWarmUps = parseAsInteger(numWarmUpsParam, 1);
    LOGGER.info("# warm ups: " + numWarmUps);
    final String fileName = fileNameParam;
    final File testFile = new File(fileName);
    LOGGER.info("Reading {}", testFile.getAbsolutePath());
    boolean monitoringEnabled = Boolean.valueOf(monitoringEnabledParam);
    final long[] timings = new long[1];
    final StopWatch stopWatch = new StopWatch();
    /**
     * maximal number of executions for a scheduled stage per thread
     */
    final int numOfExecutions = 1;
    for (int i = 0; i < numWarmUps; i++) {
        LOGGER.info("Warm up #{}", i);
        final WordCounterConfiguration wcc = new WordCounterConfiguration(numWorkerThreads, testFile);
        final TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(numWorkerThreads, wcc, numOfExecutions);
        final Execution<?> analysis = new Execution<WordCounterConfiguration>(wcc, true, scheduling);
        stopWatch.start();
        analysis.executeBlocking();
        stopWatch.end();
        LOGGER.info("duration: {} secs", TimeUnit.NANOSECONDS.toSeconds(stopWatch.getDurationInNs()));
    }
    LOGGER.info("Starting analysis...");
    final WordCounterConfiguration wcc = new WordCounterConfiguration(numWorkerThreads, testFile);
    final TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(numWorkerThreads, wcc, numOfExecutions);
    final Execution<?> analysis = new Execution<WordCounterConfiguration>(wcc, true, scheduling);
    if (monitoringEnabled) {
        wcc.getMonitoringThread().start();
    }
    stopWatch.start();
    analysis.executeBlocking();
    stopWatch.end();
    wcc.getMonitoringThread().terminate();
    LOGGER.info("duration: " + TimeUnit.NANOSECONDS.toSeconds(stopWatch.getDurationInNs()) + " secs");
    timings[0] = stopWatch.getDurationInNs();
    // results for some words to verify the correctness of the word counter
    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);
    // some statistics about the output pipes of the distributor
    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("distributor waits: " + ((NonBlockingRoundRobinStrategy) wcc.getDistributor().getStrategy()).getNumWaits());
    // some statistics about the output pipes of the distributor
    System.out.println("merger pipes:");
    for (final AbstractPort<?> port : wcc.getMergerPorts()) {
        final IMonitorablePipe spscPipe = (IMonitorablePipe) port.getPipe();
        System.out.println("numWaits: " + spscPipe.getNumWaits());
    }
}
Also used : IMonitorablePipe(teetime.framework.pipe.IMonitorablePipe) StopWatch(teetime.util.StopWatch) NonBlockingRoundRobinStrategy(teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy) Execution(teetime.framework.Execution) GlobalTaskPoolScheduling(teetime.framework.scheduling.globaltaskpool.GlobalTaskPoolScheduling) TeeTimeScheduler(teetime.framework.TeeTimeScheduler)

Example 5 with NonBlockingRoundRobinStrategy

use of teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy in project TeeTime by teetime-framework.

the class DistributorTest method singleElementRoundRobin2ShouldWork.

@Test
public void singleElementRoundRobin2ShouldWork() {
    distributor.setStrategy(new NonBlockingRoundRobinStrategy());
    test(distributor).and().send(1).to(distributor.getInputPort()).and().receive(firstIntegers).from(distributor.getNewOutputPort()).and().receive(secondIntegers).from(distributor.getNewOutputPort()).start();
    assertThat(this.firstIntegers, contains(1));
    assertThat(this.secondIntegers, is(empty()));
}
Also used : NonBlockingRoundRobinStrategy(teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy) Test(org.junit.Test)

Aggregations

NonBlockingRoundRobinStrategy (teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy)5 Execution (teetime.framework.Execution)3 IMonitorablePipe (teetime.framework.pipe.IMonitorablePipe)3 StopWatch (teetime.util.StopWatch)3 Test (org.junit.Test)2 File (java.io.File)1 TeeTimeScheduler (teetime.framework.TeeTimeScheduler)1 GlobalTaskPoolScheduling (teetime.framework.scheduling.globaltaskpool.GlobalTaskPoolScheduling)1