Search in sources :

Example 6 with StopWatch

use of teetime.util.StopWatch in project TeeTime by teetime-framework.

the class ExecutionTest method testExecuteNonBlocking.

@Test
public void testExecuteNonBlocking() throws Exception {
    StopWatch watch = new StopWatch();
    watch.start();
    execution.executeNonBlocking();
    watch.end();
    assertThat(watch.getDurationInMs(), is(lessThan(DELAY_IN_MS)));
    assertFalse(execution.getConfiguration().delay.finished);
    execution.waitForTermination();
    assertTrue(execution.getConfiguration().delay.finished);
}
Also used : StopWatch(teetime.util.StopWatch) Test(org.junit.Test)

Example 7 with StopWatch

use of teetime.util.StopWatch 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)

Aggregations

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