Search in sources :

Example 6 with TeeTimeScheduler

use of teetime.framework.TeeTimeScheduler 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 7 with TeeTimeScheduler

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

the class PipelineIT method shouldExecutePipelineCorrectlyThreeElementsWithOneSingleThread.

@Test
public // FIXME stopped 22.12.2017
void shouldExecutePipelineCorrectlyThreeElementsWithOneSingleThread() {
    String[] inputElements = { "a", "b", "c" };
    GlobalTaskPoolConfig<String> config = new GlobalTaskPoolConfig<>(inputElements);
    TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(1, config, 1);
    Execution<GlobalTaskPoolConfig<String>> execution = new Execution<>(config, true, scheduling);
    execution.executeBlocking();
    List<String> processedElements = config.getSink().getElements();
    List<String> expectedElements = Arrays.asList("a", "b", "c");
    assertThat(WRONG_PIPELINE_EXECUTION, processedElements, is(equalTo(expectedElements)));
}
Also used : Execution(teetime.framework.Execution) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) Test(org.junit.Test)

Example 8 with TeeTimeScheduler

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

the class PipelineIT method shouldExecutePipelineCorrectlyThreeElements.

@Test
public void shouldExecutePipelineCorrectlyThreeElements() {
    String[] inputElements = { "a", "b", "c" };
    GlobalTaskPoolConfig<String> config = new GlobalTaskPoolConfig<>(inputElements);
    TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(NUM_THREADS, config, 1);
    Execution<GlobalTaskPoolConfig<String>> execution = new Execution<>(config, true, scheduling);
    execution.executeBlocking();
    List<String> processedElements = config.getSink().getElements();
    List<String> expectedElements = Arrays.asList("a", "b", "c");
    assertThat(WRONG_PIPELINE_EXECUTION, processedElements, is(equalTo(expectedElements)));
}
Also used : Execution(teetime.framework.Execution) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) Test(org.junit.Test)

Example 9 with TeeTimeScheduler

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

the class PipelineIT method shouldExecutePipelineCorrectlyThreeElementsWith2ExecutionsPerTask.

@Test
public void shouldExecutePipelineCorrectlyThreeElementsWith2ExecutionsPerTask() {
    String[] inputElements = { "a", "b", "c" };
    GlobalTaskPoolConfig<String> config = new GlobalTaskPoolConfig<>(inputElements);
    TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(NUM_THREADS, config, 2);
    Execution<GlobalTaskPoolConfig<String>> execution = new Execution<>(config, true, scheduling);
    execution.executeBlocking();
    List<String> processedElements = config.getSink().getElements();
    List<String> expectedElements = Arrays.asList("a", "b", "c");
    assertThat(WRONG_PIPELINE_EXECUTION, processedElements, is(equalTo(expectedElements)));
}
Also used : Execution(teetime.framework.Execution) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) Test(org.junit.Test)

Example 10 with TeeTimeScheduler

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

the class ThreeStagesPushPullIT method shouldExecutePipelineCorrectlyManyElements.

private void shouldExecutePipelineCorrectlyManyElements(final int numElements, final int numThreads) {
    List<Integer> processedElements = new ArrayList<>();
    IntStream inputElements = IntStream.iterate(0, i -> i + 1).limit(numElements);
    Configuration config = new Configuration().from(new StreamProducer<>(inputElements)).to(new Counter<>()).end(new CollectorSink<>(processedElements));
    TeeTimeScheduler scheduling = new PushPullScheduling(config);
    Execution<Configuration> execution = new Execution<>(config, true, scheduling);
    execution.executeBlocking();
    for (int i = 0; i < numElements; i++) {
        Integer actualElement = processedElements.get(i);
        assertThat(actualElement, is(i));
    }
    assertThat(processedElements, hasSize(numElements));
}
Also used : IntStream(java.util.stream.IntStream) MethodSorters(org.junit.runners.MethodSorters) StreamProducer(teetime.stage.StreamProducer) PushPullScheduling(teetime.framework.scheduling.pushpullmodel.PushPullScheduling) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) ArrayList(java.util.ArrayList) Configuration(teetime.framework.Configuration) List(java.util.List) CollectorSink(teetime.stage.CollectorSink) Execution(teetime.framework.Execution) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Counter(teetime.stage.Counter) Configuration(teetime.framework.Configuration) ArrayList(java.util.ArrayList) PushPullScheduling(teetime.framework.scheduling.pushpullmodel.PushPullScheduling) Counter(teetime.stage.Counter) Execution(teetime.framework.Execution) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) IntStream(java.util.stream.IntStream)

Aggregations

Execution (teetime.framework.Execution)10 TeeTimeScheduler (teetime.framework.TeeTimeScheduler)10 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)4 List (java.util.List)3 IntStream (java.util.stream.IntStream)3 Matchers (org.hamcrest.Matchers)3 Assert (org.junit.Assert)3 Configuration (teetime.framework.Configuration)3 CollectorSink (teetime.stage.CollectorSink)3 StreamProducer (teetime.stage.StreamProducer)3 FixMethodOrder (org.junit.FixMethodOrder)2 MethodSorters (org.junit.runners.MethodSorters)2 GlobalTaskPoolScheduling (teetime.framework.scheduling.globaltaskpool.GlobalTaskPoolScheduling)2 Counter (teetime.stage.Counter)2 Ignore (org.junit.Ignore)1 IMonitorablePipe (teetime.framework.pipe.IMonitorablePipe)1 PushPullScheduling (teetime.framework.scheduling.pushpullmodel.PushPullScheduling)1 NonBlockingRoundRobinStrategy (teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy)1 StopWatch (teetime.util.StopWatch)1