Search in sources :

Example 16 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GetNodes method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    ServerPartition part = psContext.getMatrixStorageManager().getPart(partParam.getPartKey());
    ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(partParam.getPartKey(), 0);
    LongArrayList ret = new LongArrayList();
    row.startRead();
    try {
        ObjectIterator<Long2ObjectMap.Entry<IElement>> it = row.iterator();
        while (it.hasNext()) {
            Long2ObjectMap.Entry<IElement> entry = it.next();
            ret.add(entry.getLongKey() + partParam.getPartKey().getStartCol());
        }
    } finally {
        row.endRead();
    }
    return new IndexPartGetLongResult(part.getPartitionKey(), ret.toLongArray());
}
Also used : IndexPartGetLongResult(com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult) IElement(com.tencent.angel.ps.storage.vector.element.IElement) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 17 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GetNodes method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    ServerPartition part = psContext.getMatrixStorageManager().getPart(partParam.getPartKey());
    ServerRow ranks = psContext.getMatrixStorageManager().getRow(partParam.getPartKey(), 2);
    FloatVector ranksVector = ServerRowUtils.getVector((ServerLongFloatRow) ranks);
    long[] ret;
    if (ranksVector instanceof IntFloatVector)
        ret = gatherNodes((IntFloatVector) ranksVector, part.getPartitionKey().getStartCol());
    else if (ranksVector instanceof LongFloatVector)
        ret = gatherNodes((LongFloatVector) ranksVector, part.getPartitionKey().getStartCol());
    else {
        throw new AngelException("vector should be intfloat or longfloat but is " + ranksVector.getClass().getName());
    }
    return new IndexPartGetLongResult(part.getPartitionKey(), ret);
}
Also used : AngelException(com.tencent.angel.exception.AngelException) IndexPartGetLongResult(com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) FloatVector(com.tencent.angel.ml.math2.vector.FloatVector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 18 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GetOutDegreeFunc method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartGetOutDegreeParam param = (PartGetOutDegreeParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongIntRow row = (ServerLongIntRow) (((RowBasedPartition) part).getRow(0));
    long[] nodeIds = param.getNodeIds();
    int[] outDegrees = new int[nodeIds.length];
    for (int i = 0; i < nodeIds.length; i++) {
        outDegrees[i] = row.get(nodeIds[i]);
    }
    return new PartGetOutDegreeResult(part.getPartitionKey().getPartitionId(), outDegrees);
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition) ServerLongIntRow(com.tencent.angel.ps.storage.vector.ServerLongIntRow)

Example 19 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition 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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) PSReportResponse(com.tencent.angel.protobuf.generated.PSMasterServiceProtos.PSReportResponse) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition) ServiceException(com.google.protobuf.ServiceException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) PSReportRequest(com.tencent.angel.protobuf.generated.PSMasterServiceProtos.PSReportRequest) Pair(com.tencent.angel.protobuf.generated.MLProtos.Pair)

Example 20 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class MatrixFormatImpl method load.

private void load(ServerMatrix matrix, Path matrixPath, FileSystem fs, List<Integer> partIds, PSMatrixLoadContext loadContext, int startPos, int endPos, PSMatrixFilesMeta dataFilesMeta) throws IOException {
    ServerPartition partition;
    FSDataInputStream input = null;
    long offset = 0;
    String currentFileName = "";
    for (int i = startPos; i < endPos; i++) {
        partition = matrix.getPartition(partIds.get(i));
        MatrixPartitionMeta partMeta = dataFilesMeta.getPartitionMeta(partIds.get(i));
        String fileName = partMeta.getFileName();
        offset = partMeta.getOffset();
        if (!fileName.equals(currentFileName)) {
            currentFileName = fileName;
            if (input != null) {
                input.close();
            }
            input = fs.open(new Path(matrixPath, currentFileName));
        }
        input.seek(offset);
        load(partition, partMeta, loadContext, input);
    }
    if (input != null) {
        input.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Aggregations

ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)30 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)22 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)20 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)11 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 Random (java.util.Random)4 Path (org.apache.hadoop.fs.Path)3 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)2 ObjectNotFoundException (com.tencent.angel.ps.server.data.exception.ObjectNotFoundException)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 IOException (java.io.IOException)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 ServiceException (com.google.protobuf.ServiceException)1 PartitionKey (com.tencent.angel.PartitionKey)1 AngelException (com.tencent.angel.exception.AngelException)1 Node (com.tencent.angel.graph.data.Node)1 FloatVector (com.tencent.angel.ml.math2.vector.FloatVector)1