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;
}
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());
}
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());
}
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());
}
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);
}
Aggregations