Search in sources :

Example 16 with FutureResult

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

the class UserRequestAdapter method get.

/**
 * Get a row from ps use a udf.
 *
 * @param func get row udf
 * @return GetResult the result of the udf
 * @throws ExecutionException exception thrown when attempting to retrieve the result of a task
 * that aborted by throwing an exception
 * @throws InterruptedException interrupted while wait the result
 */
public FutureResult<GetResult> get(GetFunc func) throws InterruptedException, ExecutionException {
    MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
    GetParam param = func.getParam();
    // Split param use matrix partitons
    List<PartitionGetParam> partParams = param.split();
    int size = partParams.size();
    GetPSFRequest request = new GetPSFRequest(func);
    int requestId = request.getRequestId();
    FutureResult<GetResult> result = new FutureResult<>();
    ResponseCache cache = new MapResponseCache(size);
    requests.put(requestId, request);
    requestIdToResponseCache.put(requestId, cache);
    requestIdToResultMap.put(requestId, result);
    for (int i = 0; i < size; i++) {
        sendGetUDFRequest(matrixClient, requestId, partParams.get(i).getMatrixId(), partParams.get(i).getPartKey().getPartitionId(), func, partParams.get(i));
    }
    return result;
}
Also used : MatrixTransportClient(com.tencent.angel.psagent.matrix.transport.MatrixTransportClient) GetResult(com.tencent.angel.ml.matrix.psf.get.base.GetResult) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) GetParam(com.tencent.angel.ml.matrix.psf.get.base.GetParam) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache) ResponseCache(com.tencent.angel.psagent.matrix.transport.response.ResponseCache) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)

Example 17 with FutureResult

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

the class UserRequestAdapter method getRows.

public FutureResult<Vector[]> getRows(int matrixId, int[] rowIds) {
    checkParams(matrixId, rowIds);
    // Get partitions for this row
    List<PartitionKey> parts = PSAgentContext.get().getMatrixMetaManager().getPartitions(matrixId, rowIds[0]);
    GetRowsRequest request = new GetRowsRequest(matrixId, rowIds);
    int requestId = request.getRequestId();
    FutureResult<Vector[]> result = new FutureResult<>();
    ResponseCache responseCache = new MapResponseCache(parts.size());
    requests.put(requestId, request);
    requestIdToResultMap.put(requestId, result);
    requestIdToResponseCache.put(requestId, responseCache);
    MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
    for (PartitionKey part : parts) {
        LOG.info("Get row " + part);
        sendGetRowsRequest(matrixClient, requestId, part.getMatrixId(), rowIds, part.getPartitionId());
    }
    return result;
}
Also used : MatrixTransportClient(com.tencent.angel.psagent.matrix.transport.MatrixTransportClient) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) PartitionKey(com.tencent.angel.PartitionKey) IndexPartGetRowsRequest(com.tencent.angel.ps.server.data.request.IndexPartGetRowsRequest) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache) ResponseCache(com.tencent.angel.psagent.matrix.transport.response.ResponseCache) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)

Example 18 with FutureResult

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

the class UserRequestAdapter method update.

public Future<VoidResult> update(int matrixId, Matrix delta, UpdateOp op) {
    checkParams(matrixId);
    delta.setMatrixId(matrixId);
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = matrixMeta.getPartitionKeys();
    CompStreamKeyValuePart[] splits = RouterUtils.splitStream(matrixMeta, delta);
    int needRequestPartNum = noEmptyPartNum(splits);
    FutureResult<VoidResult> result = new FutureResult<>();
    if (needRequestPartNum == 0) {
        result.set(null);
        return result;
    }
    UpdateMatrixRequest request = new UpdateMatrixRequest(matrixId, op);
    ResponseCache cache = new MapResponseCache(needRequestPartNum);
    int requestId = request.getRequestId();
    requestIdToResponseCache.put(requestId, cache);
    requestIdToResultMap.put(requestId, result);
    requests.put(requestId, request);
    MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
    for (int i = 0; i < splits.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            sendUpdateRequest(matrixClient, requestId, matrixId, parts[i].getPartitionId(), splits[i], op);
        }
    }
    return result;
}
Also used : VoidResult(com.tencent.angel.ml.matrix.psf.update.base.VoidResult) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) 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) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)

Example 19 with FutureResult

use of com.tencent.angel.psagent.matrix.transport.FutureResult 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 20 with FutureResult

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

the class MatrixClientImpl method asyncUpdate.

@Override
public Future<VoidResult> asyncUpdate(int[] rowIds, Vector[] rows) throws AngelException {
    checkNotNull(rowIds, "rowIds");
    checkNotNull(rows, "rows");
    assert rowIds.length == rows.length;
    // Just return
    if (rowIds.length == 0) {
        LOG.warn("parameter rowIds is empty, you should check it, just return now!!!");
        FutureResult<VoidResult> result = new FutureResult<>();
        result.set(new VoidResult(ResponseType.SUCCESS));
        return result;
    }
    try {
        return PSAgentContext.get().getUserRequestAdapter().update(matrixId, rowIds, rows, UpdateOp.REPLACE);
    } catch (Throwable e) {
        throw new AngelException(e);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) VoidResult(com.tencent.angel.ml.matrix.psf.update.base.VoidResult) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult)

Aggregations

FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)29 PartitionKey (com.tencent.angel.PartitionKey)10 AngelException (com.tencent.angel.exception.AngelException)10 MatrixTransportClient (com.tencent.angel.psagent.matrix.transport.MatrixTransportClient)9 MapResponseCache (com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)9 ResponseCache (com.tencent.angel.psagent.matrix.transport.response.ResponseCache)9 VoidResult (com.tencent.angel.ml.matrix.psf.update.base.VoidResult)8 Vector (com.tencent.angel.ml.math2.vector.Vector)6 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)5 Response (com.tencent.angel.ml.matrix.transport.Response)4 CompStreamKeyValuePart (com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)3 ServerPartition (com.tencent.angel.ps.impl.matrix.ServerPartition)2 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)2 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 GetParam (com.tencent.angel.ml.matrix.psf.get.base.GetParam)1 GetResult (com.tencent.angel.ml.matrix.psf.get.base.GetResult)1 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)1 PartitionUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam)1