use of com.tencent.angel.protobuf.generated.PSMasterServiceProtos.PSReportRequest in project angel by Tencent.
the class ParameterServer method heartbeat.
private void heartbeat() throws Exception {
PSReportRequest.Builder builder = PSReportRequest.newBuilder();
builder.setPsAttemptId(attemptIdProto);
if (heartbeatCount.incrementAndGet() % dataCollectionInterval == 0) {
// calculate data size of all partitions of ps
Map<Integer, ServerMatrix> serverMatrixMap = matrixStorageManager.getMatrices();
long dataSize = 0;
for (ServerMatrix serverMatrix : serverMatrixMap.values()) {
Map<Integer, ServerPartition> partitions = serverMatrix.getPartitions();
for (ServerPartition partition : partitions.values()) {
dataSize += partition.dataSize();
}
}
Pair.Builder pairBuilder = Pair.newBuilder();
pairBuilder.setKey("key");
pairBuilder.setValue("value");
builder.addMetrics(pairBuilder.build());
// totalRPC
pairBuilder.setKey("totalRPC");
pairBuilder.setValue(WorkerPool.total.toString());
builder.addMetrics(pairBuilder.build());
// request size
pairBuilder.setKey("requestSize");
pairBuilder.setValue(String.format("%.2f", WorkerPool.requestSize.longValue() * 1.0 / 1024 / 1024));
builder.addMetrics(pairBuilder.build());
// data size
pairBuilder.setKey("dataSize");
pairBuilder.setValue(String.format("%.2f", dataSize * 1.0 / 1024 / 1024));
builder.addMetrics(pairBuilder.build());
}
builder.addAllMatrixReports(buildMatrixReports());
PSReportResponse ret;
PSReportRequest request = builder.build();
LOG.debug("ps hb = " + request);
ret = master.psReport(request);
switch(ret.getPsCommand()) {
case PSCOMMAND_REGISTER:
try {
register();
} catch (Exception x) {
LOG.error("register failed: ", x);
stop(-1);
}
break;
case PSCOMMAND_SHUTDOWN:
LOG.error("shutdown command come from appmaster, exit now!!");
stop(-1);
break;
default:
break;
}
LOG.debug("ps hb ret = " + ret);
if (ret.hasNeedSaveMatrices()) {
saver.save(ProtobufUtil.convert(ret.getNeedSaveMatrices()));
}
if (ret.hasNeedLoadMatrices()) {
loader.load(ProtobufUtil.convert(ret.getNeedLoadMatrices()));
}
syncMatrices(ret.getNeedCreateMatricesList(), ret.getNeedReleaseMatrixIdsList(), ret.getNeedRecoverPartsList());
}
Aggregations