Search in sources :

Example 16 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class IndexGetRowHandler method handle.

@Override
public ResponseData handle(RequestHeader header, RequestData data) throws Exception {
    IndexPartGetRowRequest request = (IndexPartGetRowRequest) data;
    KeyPart keyPart = request.getKeyPart();
    ServerRow row = MatrixUtils.getRow(context.getMatrixStorageManager(), header.matrixId, header.partId, request.getRowId());
    ValuePart result;
    StreamIndexPartGetRowResponse response;
    row.startRead();
    try {
        result = ServerRowUtils.getByKeys(row, keyPart);
        response = new StreamIndexPartGetRowResponse(result);
        return response;
    } finally {
        row.endRead();
    }
}
Also used : IndexPartGetRowRequest(com.tencent.angel.ps.server.data.request.IndexPartGetRowRequest) ValuePart(com.tencent.angel.psagent.matrix.transport.router.ValuePart) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) StreamIndexPartGetRowResponse(com.tencent.angel.ps.server.data.response.StreamIndexPartGetRowResponse)

Example 17 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class IndexGetRowsHandler method handle.

@Override
public ResponseData handle(RequestHeader header, RequestData data) throws Exception {
    IndexPartGetRowsRequest request = (IndexPartGetRowsRequest) data;
    int[] rowIds = request.getRowIds();
    KeyPart keyPart = request.getKeyPart();
    ServerRow[] rows = new ServerRow[rowIds.length];
    ValuePart[] results = new ValuePart[rowIds.length];
    for (int i = 0; i < rowIds.length; i++) {
        rows[i] = context.getMatrixStorageManager().getRow(header.matrixId, rowIds[i], header.partId);
        rows[i].startRead();
        try {
            results[i] = ServerRowUtils.getByKeys(rows[i], keyPart);
        } finally {
            rows[i].endRead();
        }
    }
    IndexPartGetRowsResponse response = new IndexPartGetRowsResponse(results);
    return response;
}
Also used : IndexPartGetRowsRequest(com.tencent.angel.ps.server.data.request.IndexPartGetRowsRequest) ValuePart(com.tencent.angel.psagent.matrix.transport.router.ValuePart) IndexPartGetRowsResponse(com.tencent.angel.ps.server.data.response.IndexPartGetRowsResponse) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow)

Example 18 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class UserRequestAdapter method get.

private FutureResult<Vector> get(IndexGetRowRequest request) {
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(request.getMatrixId());
    PartitionKey[] parts = matrixMeta.getPartitionKeys();
    // Split the user request to partition requests
    FutureResult<Vector> result = new FutureResult<>();
    KeyPart[] splits;
    long startTs = System.currentTimeMillis();
    if (request instanceof IntIndexGetRowRequest) {
        splits = RouterUtils.split(matrixMeta, -1, ((IntIndexGetRowRequest) request).getKeys());
    } else if (request instanceof LongIndexGetRowRequest) {
        splits = RouterUtils.split(matrixMeta, -1, ((LongIndexGetRowRequest) request).getKeys());
    } else {
        throw new UnsupportedOperationException("Unsupport index request type " + request.getClass().toString());
    }
    LOG.info("Get by indices split use time: " + (System.currentTimeMillis() - startTs));
    assert parts.length == splits.length;
    // filter empty partition requests
    int needRequestPartNum = noEmptyPartNum(splits);
    if (needRequestPartNum == 0) {
        result.set(null);
        return result;
    }
    // Create partition results cache
    ResponseCache cache = new MapResponseCache(needRequestPartNum);
    int requestId = request.getRequestId();
    requestIdToResponseCache.put(requestId, cache);
    requestIdToResultMap.put(requestId, result);
    requests.put(requestId, request);
    // Send all the partition requests
    MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
    for (int i = 0; i < splits.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            sendIndexGetRowRequest(matrixClient, requestId, request.getMatrixId(), request.getRowId(), parts[i].getPartitionId(), splits[i], request.getFunc());
        }
    }
    return result;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache) MatrixTransportClient(com.tencent.angel.psagent.matrix.transport.MatrixTransportClient) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) PartitionKey(com.tencent.angel.PartitionKey) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache) ResponseCache(com.tencent.angel.psagent.matrix.transport.response.ResponseCache) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 19 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class GeneralGetUtils method partitionGet.

public static PartitionGetResult partitionGet(PSContext psContext, PartitionGetParam partParam) {
    GeneralPartGetParam param = (GeneralPartGetParam) partParam;
    KeyPart keyPart = param.getIndicesPart();
    // Long type node id
    long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
    // Get data
    IElement[] data = new IElement[nodeIds.length];
    for (int i = 0; i < nodeIds.length; i++) {
        data[i] = row.get(nodeIds[i]);
    }
    MatrixMeta meta = psContext.getMatrixMetaManager().getMatrixMeta(param.getMatrixId());
    try {
        return new PartGeneralGetResult(meta.getValueClass(), nodeIds, data);
    } catch (ClassNotFoundException e) {
        throw new AngelException("Can not get value class ");
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) IElement(com.tencent.angel.ps.storage.vector.element.IElement) PartGeneralGetResult(com.tencent.angel.graph.model.general.get.PartGeneralGetResult) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)

Example 20 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class IntKeysGetParam method split.

@Override
public List<PartitionGetParam> split() {
    // Get matrix meta
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = meta.getPartitionKeys();
    // Split
    KeyPart[] nodeIdsParts = RouterUtils.split(meta, 0, nodeIds, false);
    // Generate Part psf get param
    List<PartitionGetParam> partParams = new ArrayList<>(parts.length);
    assert parts.length == nodeIdsParts.length;
    for (int i = 0; i < parts.length; i++) {
        if (nodeIdsParts[i] != null && nodeIdsParts[i].size() > 0) {
            partParams.add(new GeneralPartGetParam(matrixId, parts[i], nodeIdsParts[i]));
        }
    }
    return partParams;
}
Also used : GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)

Aggregations

KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)26 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)13 PartitionKey (com.tencent.angel.PartitionKey)12 ArrayList (java.util.ArrayList)10 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)9 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)9 InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)8 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)8 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)7 ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)3 PartGetFloatArrayAttrsResult (com.tencent.angel.graph.client.psf.get.utils.PartGetFloatArrayAttrsResult)2 PartGetIntArrayAttrsResult (com.tencent.angel.graph.client.psf.get.utils.PartGetIntArrayAttrsResult)2 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)2 MatrixTransportClient (com.tencent.angel.psagent.matrix.transport.MatrixTransportClient)2 MapResponseCache (com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)2 ResponseCache (com.tencent.angel.psagent.matrix.transport.response.ResponseCache)2 ValuePart (com.tencent.angel.psagent.matrix.transport.router.ValuePart)2 DynamicLongArray (com.tencent.angel.common.collections.DynamicLongArray)1