Search in sources :

Example 21 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.

the class GetSort method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) part.getRow(0);
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = row.getStorage().iterator();
    row.startWrite();
    try {
        while (it.hasNext()) {
            Long2ObjectMap.Entry<IElement> next = it.next();
            DynamicNeighborElement ele = (DynamicNeighborElement) next.getValue();
            if (ele != null) {
                ele.trans();
            }
        }
    } finally {
        row.endWrite();
    }
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) DynamicNeighborElement(com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 22 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix 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 23 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix 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 24 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.

the class InitNeighborOver method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam param) {
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(param.getMatrixId());
    CSRPartition part = (CSRPartition) matrix.getPartition(param.getPartKey().getPartitionId());
    IntCSRStorage storage = (IntCSRStorage) part.getStorage();
    int startCol = (int) param.getPartKey().getStartCol();
    synchronized (storage) {
        // No data in this partition
        if (storage.getTempRowIds() == null) {
            return;
        }
        // Get total neighbor number
        int[] rowOffsets = storage.getRowOffsets();
        int accumOffset = 0;
        for (int i = 0; i < rowOffsets.length - 1; i++) {
            int offset = rowOffsets[i];
            rowOffsets[i] = accumOffset;
            accumOffset += offset;
        }
        rowOffsets[rowOffsets.length - 1] = accumOffset;
        // Final matrix column indices: neighbors node ids
        int[] cloumnIndices = new int[accumOffset];
        // Write positions in cloumnIndices for nodes
        int[] copyOffsets = new int[rowOffsets.length - 1];
        System.arraycopy(rowOffsets, 0, copyOffsets, 0, rowOffsets.length - 1);
        List<int[]> tempRowIds = storage.getTempRowIds();
        List<int[]> tempRowLens = storage.getTempRowLens();
        List<int[]> tempColumnIndices = storage.getTempColumnIndices();
        // Copy all cached sub column indices to final column indices
        int size = tempRowIds.size();
        for (int i = 0; i < size; i++) {
            // Read position for a sub column indices
            int copyLen = 0;
            int[] subTempRowIds = tempRowIds.get(i);
            int[] subTempLens = tempRowLens.get(i);
            int[] subTempColumnIndices = tempColumnIndices.get(i);
            for (int j = 0; j < subTempRowIds.length; j++) {
                // Copy column indices for a node to final column indices
                System.arraycopy(subTempColumnIndices, copyLen, cloumnIndices, copyOffsets[subTempRowIds[j] - startCol], subTempLens[j]);
                // Update write position for this node in final column indices
                copyOffsets[subTempRowIds[j] - startCol] += subTempLens[j];
                // Update the read position in sub column indices
                copyLen += subTempLens[j];
            }
        }
        storage.setColumnIndices(cloumnIndices);
        // Clear all temp data
        storage.setTempRowIds(null);
        storage.setTempRowLens(null);
        storage.setTempColumnIndices(null);
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) IntCSRStorage(com.tencent.angel.ps.storage.partition.storage.IntCSRStorage) CSRPartition(com.tencent.angel.ps.storage.partition.CSRPartition)

Example 25 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.

the class InitAliasTable method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    InitAliasTablePartParam param = (InitAliasTablePartParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) part.getRow(0);
    ObjectIterator<Long2ObjectMap.Entry<AliasElement>> iter = param.getNodeId2Neighbors().long2ObjectEntrySet().iterator();
    row.startWrite();
    try {
        while (iter.hasNext()) {
            Long2ObjectMap.Entry<AliasElement> entry = iter.next();
            AliasElement element = entry.getValue();
            if (element == null) {
                row.set(entry.getLongKey(), null);
            } else {
                row.set(entry.getLongKey(), new AliasElement(element.getNeighborIds(), element.getAccept(), element.getAlias()));
            }
        }
    } finally {
        row.endWrite();
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Aggregations

ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)39 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)28 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)22 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)15 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)5 Random (java.util.Random)5 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 CSRPartition (com.tencent.angel.ps.storage.partition.CSRPartition)3 IntCSRStorage (com.tencent.angel.ps.storage.partition.storage.IntCSRStorage)3 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)3 AngelException (com.tencent.angel.exception.AngelException)2 MatrixFormat (com.tencent.angel.model.output.format.MatrixFormat)2 Pair (com.tencent.angel.protobuf.generated.MLProtos.Pair)2 ParameterServer (com.tencent.angel.ps.ParameterServer)2 ObjectNotFoundException (com.tencent.angel.ps.server.data.exception.ObjectNotFoundException)2 MatrixStorageManager (com.tencent.angel.ps.storage.MatrixStorageManager)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongLongRow (com.tencent.angel.ps.storage.vector.ServerLongLongRow)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)2