public Collection<PartitionStats> call() {
// Thread initialization (for locality)
WorkerClientRequestProcessor<I, V, E> workerClientRequestProcessor =
new NettyWorkerClientRequestProcessor<I, V, E>(
context, configuration, serviceWorker);
WorkerThreadGlobalCommUsage aggregatorUsage =
serviceWorker.getAggregatorHandler().newThreadAggregatorUsage();
WorkerContext workerContext = serviceWorker.getWorkerContext();
vertexWriter = serviceWorker.getSuperstepOutput().getVertexWriter();
List<PartitionStats> partitionStatsList = Lists.newArrayList();
while (!partitionIdQueue.isEmpty()) {
Integer partitionId = partitionIdQueue.poll();
if (partitionId == null) {
break;
}
Partition<I, V, E> partition =
serviceWorker.getPartitionStore().getOrCreatePartition(partitionId);
Computation<I, V, E, M1, M2> computation =
(Computation<I, V, E, M1, M2>) configuration.createComputation();
computation.initialize(graphState, workerClientRequestProcessor,
serviceWorker.getGraphTaskManager(), aggregatorUsage, workerContext);
computation.preSuperstep();
try {
PartitionStats partitionStats =
computePartition(computation, partition);
partitionStatsList.add(partitionStats);
long partitionMsgs = workerClientRequestProcessor.resetMessageCount();
partitionStats.addMessagesSentCount(partitionMsgs);
messagesSentCounter.inc(partitionMsgs);
long partitionMsgBytes =
workerClientRequestProcessor.resetMessageBytesCount();
partitionStats.addMessageBytesSentCount(partitionMsgBytes);
messageBytesSentCounter.inc(partitionMsgBytes);
timedLogger.info("call: Completed " +
partitionStatsList.size() + " partitions, " +
partitionIdQueue.size() + " remaining " +
MemoryUtils.getRuntimeMemoryStats());
} catch (IOException e) {
throw new IllegalStateException("call: Caught unexpected IOException," +
" failing.", e);
} catch (InterruptedException e) {
throw new IllegalStateException("call: Caught unexpected " +
"InterruptedException, failing.", e);
} finally {
serviceWorker.getPartitionStore().putPartition(partition);
}
computation.postSuperstep();
}
// Return VertexWriter after the usage
serviceWorker.getSuperstepOutput().returnVertexWriter(vertexWriter);
if (LOG.isInfoEnabled()) {
float seconds = Times.getNanosSince(TIME, startNanos) /
Time.NS_PER_SECOND_AS_FLOAT;
LOG.info("call: Computation took " + seconds + " secs for " +
partitionStatsList.size() + " partitions on superstep " +
graphState.getSuperstep() + ". Flushing started");
}
try {
workerClientRequestProcessor.flush();
// The messages flushed out from the cache is
// from the last partition processed
if (partitionStatsList.size() > 0) {
long partitionMsgBytes =
workerClientRequestProcessor.resetMessageBytesCount();
partitionStatsList.get(partitionStatsList.size() - 1).
addMessageBytesSentCount(partitionMsgBytes);
messageBytesSentCounter.inc(partitionMsgBytes);
}
aggregatorUsage.finishThreadComputation();
} catch (IOException e) {
throw new IllegalStateException("call: Flushing failed.", e);
}
return partitionStatsList;
}