Search in sources :

Example 1 with IMonitorablePipe

use of teetime.framework.pipe.IMonitorablePipe in project TeeTime by teetime-framework.

the class DynamicTaskFarmStage method getStageIndexWithLeastRemainingInput.

// FIXME the task farm itself should not choose which stage to remove.
// Instead, a strategy from outside the task farm should determine.
private int getStageIndexWithLeastRemainingInput() {
    // NOPMD (DU: caused by loop)
    int currentMinimum = Integer.MAX_VALUE;
    // NOPMD (DU: caused by loop)
    int currentMinumumStageIndex = getWorkerStages().size() - 1;
    // do not remove basic stage
    for (int i = 1; i < getWorkerStages().size(); i++) {
        final ITaskFarmDuplicable<I, O> instance = getWorkerStages().get(i);
        InputPort<I> port = instance.getInputPort();
        IMonitorablePipe monitorablePipe = null;
        try {
            monitorablePipe = (IMonitorablePipe) port.getPipe();
        } catch (ClassCastException e) {
            throw new TaskFarmInvalidPipeException("The input pipe of an enclosed stage instance inside a Task Farm" + " does not implement IMonitorablePipe, which is required. Instead, the type is " + port.getPipe().getClass().getSimpleName() + ".", e);
        }
        if (monitorablePipe != null && monitorablePipe.size() < currentMinimum) {
            currentMinimum = monitorablePipe.size();
            currentMinumumStageIndex = i;
        }
    }
    return currentMinumumStageIndex;
}
Also used : IMonitorablePipe(teetime.framework.pipe.IMonitorablePipe) TaskFarmInvalidPipeException(teetime.stage.taskfarm.exception.TaskFarmInvalidPipeException)

Example 2 with IMonitorablePipe

use of teetime.framework.pipe.IMonitorablePipe in project TeeTime by teetime-framework.

the class TaskFarmHistoryService method getSumOfPipePushThroughputs.

private double getSumOfPipePushThroughputs() {
    this.lastPullThroughputs = new HashMap<IMonitorablePipe, Long>();
    this.lastPushThroughputs = new HashMap<IMonitorablePipe, Long>();
    // NOPMD
    double sum = 0;
    try {
        for (ITaskFarmDuplicable<I, O> enclosedStage : this.taskFarmStage.getWorkerStages()) {
            IMonitorablePipe inputPipe = (IMonitorablePipe) enclosedStage.getInputPort().getPipe();
            if (inputPipe != null) {
                // we record the throughput measurements as a sum in the history
                // and separately in maps for further use
                long pushThroughput = inputPipe.getPushThroughput();
                this.lastPushThroughputs.put(inputPipe, pushThroughput);
                long pullThroughput = inputPipe.getPullThroughput();
                this.lastPullThroughputs.put(inputPipe, pullThroughput);
                sum += pullThroughput;
            }
        }
    } catch (ClassCastException e) {
        throw new TaskFarmInvalidPipeException("The input pipe of an enclosed stage instance inside a Task Farm" + " does not implement IMonitorablePipe, which is required.", e);
    }
    return sum;
}
Also used : IMonitorablePipe(teetime.framework.pipe.IMonitorablePipe) TaskFarmInvalidPipeException(teetime.stage.taskfarm.exception.TaskFarmInvalidPipeException)

Example 3 with IMonitorablePipe

use of teetime.framework.pipe.IMonitorablePipe in project TeeTime by teetime-framework.

the class TaskFarmReconfigurationCommandService method decideForRemovingMode.

private TaskFarmReconfigurationCommand decideForRemovingMode(final double throughputScore) {
    // NOPMD
    TaskFarmReconfigurationCommand command = TaskFarmReconfigurationCommand.NONE;
    // we never want to remove the basic stage since it would destroy the pipeline
    for (int i = 1; i < this.taskFarmStage.getWorkerStages().size() - 1; i++) {
        ITaskFarmDuplicable<?, ?> stage = this.taskFarmStage.getWorkerStages().get(i);
        IMonitorablePipe monitorableInputPipe = (IMonitorablePipe) stage.getInputPort().getPipe();
        int sizeOfInputQueue = monitorableInputPipe.size();
        if (sizeOfInputQueue == 0) {
            // there is still a stage which is currently unused can be safely removed
            command = TaskFarmReconfigurationCommand.REMOVE;
            break;
        }
    }
    if (throughputScore > this.taskFarmStage.getConfiguration().getThroughputScoreBoundary()) {
        // performance need has risen again, so we are parallelizing more
        this.currentMode = ReconfigurationMode.ADDING;
    }
    return command;
}
Also used : IMonitorablePipe(teetime.framework.pipe.IMonitorablePipe)

Example 4 with IMonitorablePipe

use of teetime.framework.pipe.IMonitorablePipe in project TeeTime by teetime-framework.

the class PipeMonitoringService method doMeasurement.

@Override
public void doMeasurement() {
    long currentTimestamp = System.currentTimeMillis();
    if (this.startingTimestamp == INIT) {
        this.startingTimestamp = currentTimestamp;
    }
    PipeMonitoringDataContainer container = new PipeMonitoringDataContainer(currentTimestamp - this.startingTimestamp);
    for (int i = 0; i < this.pipes.size(); i++) {
        IMonitorablePipe pipe = this.pipes.get(i);
        if (pipe != null) {
            // if we use a task farm, we want to use throughput measurements of the history service
            long pullThroughput = 0;
            long pushThroughput = 0;
            if (this.history == null) {
                pullThroughput = pipe.getPullThroughput();
                pushThroughput = pipe.getPushThroughput();
            } else {
                pullThroughput = this.history.getLastPullThroughputOfPipe(pipe);
                pushThroughput = this.history.getLastPushThroughputOfPipe(pipe);
            }
            PipeMonitoringData monitoringData = new PipeMonitoringData(pipe.getNumPushesSinceAppStart(), pipe.getNumPullsSinceAppStart(), pipe.size(), pipe.capacity(), pushThroughput, pullThroughput, pipe.getNumWaits(), i);
            container.addMonitoringData(monitoringData);
        }
    }
    this.containers.add(container);
}
Also used : IMonitorablePipe(teetime.framework.pipe.IMonitorablePipe)

Example 5 with IMonitorablePipe

use of teetime.framework.pipe.IMonitorablePipe 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)

Aggregations

IMonitorablePipe (teetime.framework.pipe.IMonitorablePipe)9 Execution (teetime.framework.Execution)3 NonBlockingRoundRobinStrategy (teetime.stage.basic.distributor.strategy.NonBlockingRoundRobinStrategy)3 TaskFarmInvalidPipeException (teetime.stage.taskfarm.exception.TaskFarmInvalidPipeException)3 StopWatch (teetime.util.StopWatch)3 File (java.io.File)1 TeeTimeScheduler (teetime.framework.TeeTimeScheduler)1 GlobalTaskPoolScheduling (teetime.framework.scheduling.globaltaskpool.GlobalTaskPoolScheduling)1