Search in sources :

Example 1 with Consumers

use of com.baidu.hugegraph.computer.core.util.Consumers in project hugegraph-computer by hugegraph.

the class ComputeManager method compute.

public WorkerStat compute(WorkerContext context, int superstep) {
    this.sendManager.startSend(MessageType.MSG);
    WorkerStat workerStat = new WorkerStat();
    Map<Integer, PartitionStat> stats = new ConcurrentHashMap<>();
    /*
         * Remark: The main thread can perceive the partition compute exception
         * only after all partition compute completed, and only record the last
         * exception.
         */
    Consumers<FileGraphPartition> consumers = new Consumers<>(this.computeExecutor, partition -> {
        PartitionStat stat = partition.compute(context, superstep);
        stats.put(stat.partitionId(), stat);
    });
    consumers.start("partition-compute");
    try {
        for (FileGraphPartition partition : this.partitions.values()) {
            consumers.provide(partition);
        }
        consumers.await();
    } catch (Throwable t) {
        throw new ComputerException("An exception occurred when " + "partition parallel compute", t);
    }
    this.sendManager.finishSend(MessageType.MSG);
    // After compute and send finish signal.
    Map<Integer, MessageStat> recvStats = this.recvManager.messageStats();
    for (Map.Entry<Integer, PartitionStat> entry : stats.entrySet()) {
        PartitionStat partStat = entry.getValue();
        int partitionId = partStat.partitionId();
        MessageStat sendStat = this.sendManager.messageStat(partitionId);
        partStat.mergeSendMessageStat(sendStat);
        MessageStat recvStat = recvStats.get(partitionId);
        if (recvStat != null) {
            partStat.mergeRecvMessageStat(recvStat);
        }
        workerStat.add(partStat);
    }
    return workerStat;
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) Consumers(com.baidu.hugegraph.computer.core.util.Consumers) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) WorkerStat(com.baidu.hugegraph.computer.core.worker.WorkerStat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)1 PartitionStat (com.baidu.hugegraph.computer.core.graph.partition.PartitionStat)1 MessageStat (com.baidu.hugegraph.computer.core.receiver.MessageStat)1 Consumers (com.baidu.hugegraph.computer.core.util.Consumers)1 WorkerStat (com.baidu.hugegraph.computer.core.worker.WorkerStat)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1