Search in sources :

Example 1 with FSMerger

use of edu.iu.dsc.tws.comms.shuffle.FSMerger in project twister2 by DSC-SPIDAL.

the class DGatherBatchFinalReceiver method progress.

/**
 * Method used to communicationProgress work
 */
@SuppressWarnings("unchecked")
public boolean progress() {
    boolean needsFurtherProgress = false;
    for (int t : messages.keySet()) {
        FSMerger fsMerger = sortedMergers.get(t);
        if (batchDone.get(t)) {
            continue;
        }
        boolean allFinished = true;
        // now check weather we have the messages for this source
        Map<Integer, Queue<Object>> map = messages.get(t);
        Map<Integer, Boolean> finishedForTarget = finished.get(t);
        boolean found = true;
        boolean moreThanOne = false;
        for (Map.Entry<Integer, Queue<Object>> e : map.entrySet()) {
            if (e.getValue().size() == 0 && !finishedForTarget.get(e.getKey())) {
                found = false;
            } else {
                moreThanOne = true;
            }
            if (!finishedForTarget.get(e.getKey())) {
                allFinished = false;
            }
        }
        // if we have queues with 0 and more than zero we need further progress
        if (!found && moreThanOne) {
            needsFurtherProgress = true;
        }
        if (found) {
            List<Object> out = new AggregatedObjects<>();
            for (Map.Entry<Integer, Queue<Object>> e : map.entrySet()) {
                Queue<Object> valueList = e.getValue();
                if (valueList.size() > 0) {
                    Object value = valueList.poll();
                    if (value instanceof List) {
                        out.addAll((List) value);
                    } else {
                        out.add(value);
                    }
                    allFinished = false;
                }
            }
            for (Object o : out) {
                byte[] d = gather.getDataType().getDataPacker().packToByteArray(o);
                fsMerger.add(d, d.length);
            }
        } else {
            allFinished = false;
        }
        if (allFinished) {
            batchDone.put(t, true);
            fsMerger.switchToReading();
            bulkReceiver.receive(t, fsMerger.readIterator());
        }
    }
    if (!needsFurtherProgress) {
        complete = true;
    }
    return needsFurtherProgress;
}
Also used : FSMerger(edu.iu.dsc.tws.comms.shuffle.FSMerger) AggregatedObjects(edu.iu.dsc.tws.comms.dfw.io.AggregatedObjects) ArrayList(java.util.ArrayList) List(java.util.List) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Queue(java.util.Queue) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with FSMerger

use of edu.iu.dsc.tws.comms.shuffle.FSMerger in project twister2 by DSC-SPIDAL.

the class DPartitionBatchFinalReceiver method initMergers.

/**
 * Initialize the mergers, this happens after each refresh
 */
private void initMergers(long maxBytesInMemory, long maxRecordsInMemory, long maxFileSize, int parallelIOAllowance) {
    for (Integer target : expIds.keySet()) {
        String shuffleDirectory = this.shuffleDirectories.get(partition.getLogicalPlan().getIndexOfTaskInNode(target) % this.shuffleDirectories.size());
        Shuffle sortedMerger;
        if (partition.getKeyType() == null) {
            sortedMerger = new FSMerger(maxBytesInMemory, maxRecordsInMemory, shuffleDirectory, DFWIOUtils.getOperationName(target, partition, refresh), partition.getDataType());
        } else {
            if (comparator != null) {
                sortedMerger = new FSKeyedSortedMerger2(maxBytesInMemory, maxFileSize, shuffleDirectory, DFWIOUtils.getOperationName(target, partition, refresh), partition.getKeyType(), partition.getDataType(), comparator, target, groupByKey, parallelIOAllowance);
            } else {
                sortedMerger = new FSKeyedMerger(maxBytesInMemory, maxRecordsInMemory, shuffleDirectory, DFWIOUtils.getOperationName(target, partition, refresh), partition.getKeyType(), partition.getDataType());
            }
        }
        sortedMergers.put(target, sortedMerger);
        finishedSources.put(target, new HashSet<>());
    }
}
Also used : FSKeyedSortedMerger2(edu.iu.dsc.tws.comms.shuffle.FSKeyedSortedMerger2) Shuffle(edu.iu.dsc.tws.comms.shuffle.Shuffle) FSKeyedMerger(edu.iu.dsc.tws.comms.shuffle.FSKeyedMerger) FSMerger(edu.iu.dsc.tws.comms.shuffle.FSMerger)

Example 3 with FSMerger

use of edu.iu.dsc.tws.comms.shuffle.FSMerger in project twister2 by DSC-SPIDAL.

the class DGatherBatchFinalReceiver method init.

@Override
public void init(Config cfg, DataFlowOperation op, Map<Integer, List<Integer>> expectedIds) {
    long maxBytesInMemory = CommunicationContext.getShuffleMaxBytesInMemory(cfg);
    long maxRecordsInMemory = CommunicationContext.getShuffleMaxRecordsInMemory(cfg);
    gather = op;
    sendPendingMax = CommunicationContext.sendPendingMax(cfg);
    for (Map.Entry<Integer, List<Integer>> e : expectedIds.entrySet()) {
        Map<Integer, Queue<Object>> messagesPerTask = new HashMap<>();
        Map<Integer, Boolean> finishedPerTask = new HashMap<>();
        for (int i : e.getValue()) {
            messagesPerTask.put(i, new ArrayBlockingQueue<>(sendPendingMax));
            finishedPerTask.put(i, false);
        }
        messages.put(e.getKey(), messagesPerTask);
        finished.put(e.getKey(), finishedPerTask);
        finalMessages.put(e.getKey(), new ArrayList<>());
        batchDone.put(e.getKey(), false);
        FSMerger merger = new FSMerger(maxBytesInMemory, maxRecordsInMemory, shuffleDirectory, getOperationName(e.getKey()), gather.getDataType());
        sortedMergers.put(e.getKey(), merger);
    }
    this.bulkReceiver.init(cfg, expectedIds.keySet());
}
Also used : HashMap(java.util.HashMap) FSMerger(edu.iu.dsc.tws.comms.shuffle.FSMerger) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Queue(java.util.Queue)

Aggregations

FSMerger (edu.iu.dsc.tws.comms.shuffle.FSMerger)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Queue (java.util.Queue)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 AggregatedObjects (edu.iu.dsc.tws.comms.dfw.io.AggregatedObjects)1 FSKeyedMerger (edu.iu.dsc.tws.comms.shuffle.FSKeyedMerger)1 FSKeyedSortedMerger2 (edu.iu.dsc.tws.comms.shuffle.FSKeyedSortedMerger2)1 Shuffle (edu.iu.dsc.tws.comms.shuffle.Shuffle)1