Search in sources :

Example 16 with MessageStat

use of com.baidu.hugegraph.computer.core.receiver.MessageStat in project hugegraph-computer by hugegraph.

the class PartitionStatTest method testReadWrite.

@Test
public void testReadWrite() throws IOException {
    PartitionStat stat1 = new PartitionStat(0, 1L, 2L, 0L);
    PartitionStat stat1ReadObj = new PartitionStat();
    UnitTestBase.assertEqualAfterWriteAndRead(stat1, stat1ReadObj);
    PartitionStat stat2 = new PartitionStat(1, 4L, 3L, 2L);
    stat2.mergeSendMessageStat(new MessageStat(5L, 6L));
    stat2.mergeRecvMessageStat(new MessageStat(7L, 8L));
    PartitionStat stat2ReadObj = new PartitionStat();
    UnitTestBase.assertEqualAfterWriteAndRead(stat2, stat2ReadObj);
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) Test(org.junit.Test)

Example 17 with MessageStat

use of com.baidu.hugegraph.computer.core.receiver.MessageStat 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)

Example 18 with MessageStat

use of com.baidu.hugegraph.computer.core.receiver.MessageStat in project hugegraph-computer by hugegraph.

the class ComputeManager method compute.

public WorkerStat compute(ComputationContext context, int superstep) {
    this.sendManager.startSend(MessageType.MSG);
    WorkerStat workerStat = new WorkerStat();
    Map<Integer, PartitionStat> partitionStats = new HashMap<>(this.partitions.size());
    // TODO: parallel compute process.
    for (FileGraphPartition<M> partition : this.partitions.values()) {
        PartitionStat stat = partition.compute(context, this.computation, superstep);
        partitionStats.put(stat.partitionId(), stat);
    }
    this.sendManager.finishSend(MessageType.MSG);
    // After compute and send finish signal.
    Map<Integer, MessageStat> recvStats = this.recvManager.messageStats();
    for (Map.Entry<Integer, PartitionStat> entry : partitionStats.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 : HashMap(java.util.HashMap) MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) WorkerStat(com.baidu.hugegraph.computer.core.worker.WorkerStat) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with MessageStat

use of com.baidu.hugegraph.computer.core.receiver.MessageStat in project hugegraph-computer by hugegraph.

the class MessageSendManager method sortAndSendLastBuffer.

private MessageStat sortAndSendLastBuffer(Map<Integer, WriteBuffers> all, MessageType type) {
    MessageStat messageWritten = new MessageStat();
    List<Future<?>> futures = new ArrayList<>(all.size());
    // Sort and send the last buffer
    for (Map.Entry<Integer, WriteBuffers> entry : all.entrySet()) {
        int partitionId = entry.getKey();
        WriteBuffers buffer = entry.getValue();
        /*
             * If the last buffer has already been sorted and sent (empty),
             * there is no need to send again here
             */
        if (!buffer.isEmpty()) {
            buffer.prepareSorting();
            futures.add(this.sortThenSend(partitionId, type, buffer));
        }
        // Record total message count & bytes
        messageWritten.increase(buffer.messageWritten());
    }
    this.checkException();
    // Wait all future finished
    try {
        for (Future<?> future : futures) {
            future.get(Constants.FUTURE_TIMEOUT, TimeUnit.SECONDS);
        }
    } catch (TimeoutException e) {
        throw new ComputerException("Timed out to wait for sorting task " + "to finished", e);
    } catch (InterruptedException | ExecutionException e) {
        throw new ComputerException("Failed to wait for sorting task " + "to finished", e);
    }
    return messageWritten;
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) ArrayList(java.util.ArrayList) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

MessageStat (com.baidu.hugegraph.computer.core.receiver.MessageStat)19 Test (org.junit.Test)14 PartitionStat (com.baidu.hugegraph.computer.core.graph.partition.PartitionStat)10 Map (java.util.Map)4 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)3 WorkerStat (com.baidu.hugegraph.computer.core.worker.WorkerStat)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 TimeoutException (java.util.concurrent.TimeoutException)2 Consumers (com.baidu.hugegraph.computer.core.util.Consumers)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1