Search in sources :

Example 1 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, MessageSendPartition> all, MessageType type) {
    MessageStat messageWritten = new MessageStat();
    List<Future<?>> futures = new ArrayList<>(all.size());
    // Sort and send the last buffer
    for (Map.Entry<Integer, MessageSendPartition> entry : all.entrySet()) {
        int partitionId = entry.getKey();
        MessageSendPartition partition = entry.getValue();
        /*
             * If the last buffer has already been sorted and sent (empty),
             * there is no need to send again here
             */
        for (WriteBuffers buffer : partition.buffers()) {
            if (!buffer.isEmpty()) {
                buffer.prepareSorting();
                futures.add(this.sortThenSend(partitionId, type, buffer));
            }
        }
        // Record total message count & bytes
        messageWritten.increase(partition.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)

Example 2 with MessageStat

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

the class MessageSendManager method finishSend.

/**
 * Finsih send message, send the last buffer and put an END signal
 * into queue
 * @param type the message type
 */
public void finishSend(MessageType type) {
    Map<Integer, MessageSendPartition> all = this.buffers.all();
    MessageStat stat = this.sortAndSendLastBuffer(all, type);
    Set<Integer> workerIds = all.keySet().stream().map(this.partitioner::workerId).collect(Collectors.toSet());
    this.sendControlMessageToWorkers(workerIds, MessageType.FINISH);
    LOG.info("Finish sending message(type={},count={},bytes={})", type, stat.messageCount(), stat.messageBytes());
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat)

Example 3 with MessageStat

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

the class PartitionStatTest method testToString.

@Test
public void testToString() {
    PartitionStat stat = new PartitionStat(1, 4L, 3L, 2L);
    stat.mergeSendMessageStat(new MessageStat(5L, 6L));
    stat.mergeRecvMessageStat(new MessageStat(7L, 8L));
    String str = "PartitionStat{\"partitionId\":1,\"vertexCount\":4,\"" + "edgeCount\":3,\"finishedVertexCount\":2," + "\"messageSendCount\":5,\"messageSendBytes\":6," + "\"messageRecvCount\":7,\"messageRecvBytes\":8}";
    Assert.assertEquals(str, stat.toString());
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) Test(org.junit.Test)

Example 4 with MessageStat

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

the class PartitionStatTest method testMerge.

@Test
public void testMerge() throws IOException {
    PartitionStat stat1 = new PartitionStat(0, 1L, 2L, 0L);
    stat1.mergeSendMessageStat(new MessageStat(5L, 6L));
    stat1.mergeRecvMessageStat(new MessageStat(7L, 8L));
    Assert.assertEquals(1L, stat1.vertexCount());
    Assert.assertEquals(2L, stat1.edgeCount());
    Assert.assertEquals(5L, stat1.messageSendCount());
    Assert.assertEquals(6L, stat1.messageSendBytes());
    Assert.assertEquals(7L, stat1.messageRecvCount());
    Assert.assertEquals(8L, stat1.messageRecvBytes());
    stat1.mergeSendMessageStat(new MessageStat(15L, 16L));
    stat1.mergeRecvMessageStat(new MessageStat(17L, 18L));
    Assert.assertEquals(20L, stat1.messageSendCount());
    Assert.assertEquals(22L, stat1.messageSendBytes());
    Assert.assertEquals(24L, stat1.messageRecvCount());
    Assert.assertEquals(26L, stat1.messageRecvBytes());
    MessageStat messageStat = new MessageStat(100L, 400L);
    stat1.mergeSendMessageStat(messageStat);
    stat1.mergeRecvMessageStat(messageStat);
    Assert.assertEquals(1L, stat1.vertexCount());
    Assert.assertEquals(2L, stat1.edgeCount());
    Assert.assertEquals(120L, stat1.messageSendCount());
    Assert.assertEquals(422L, stat1.messageSendBytes());
    Assert.assertEquals(124L, stat1.messageRecvCount());
    Assert.assertEquals(426L, stat1.messageRecvBytes());
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) Test(org.junit.Test)

Example 5 with MessageStat

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

the class PartitionStatTest method testEquals.

@Test
public void testEquals() {
    PartitionStat stat1 = new PartitionStat(0, 1L, 2L, 0L);
    PartitionStat stat2 = new PartitionStat(0, 1L, 2L, 0L);
    PartitionStat stat3 = new PartitionStat(1, 4L, 3L, 2L);
    stat3.mergeSendMessageStat(new MessageStat(5L, 6L));
    PartitionStat stat4 = new PartitionStat(1, 4L, 3L, 2L);
    stat4.mergeRecvMessageStat(new MessageStat(5L, 6L));
    PartitionStat stat30 = new PartitionStat(1, 4L, 3L, 2L);
    stat30.mergeSendMessageStat(new MessageStat(5L, 6L));
    PartitionStat stat40 = new PartitionStat(1, 4L, 3L, 2L);
    stat40.mergeRecvMessageStat(new MessageStat(5L, 6L));
    Assert.assertEquals(stat1, stat2);
    Assert.assertNotEquals(stat1, stat3);
    Assert.assertNotEquals(stat1, stat4);
    Assert.assertNotEquals(stat3, stat4);
    Assert.assertNotEquals(stat1, new Object());
    Assert.assertEquals(stat3, stat30);
    Assert.assertEquals(stat4, stat40);
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) Test(org.junit.Test)

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