Search in sources :

Example 1 with Response

use of com.tencent.angel.ps.server.data.response.Response in project angel by Tencent.

the class GetRowsHandler method merge.

private Vector[] merge(int matrixId, int[] rowIds, Collection<Response> responses) {
    Map<Integer, List<ServerRow>> rowIdToserverRows = new HashMap<>(rowIds.length);
    int valueNum = responses.size();
    for (Response response : responses) {
        ServerRow[] serverRows = ((GetRowsSplitResponse) (response.getData())).getRowsSplit();
        for (int j = 0; j < serverRows.length; j++) {
            int rowId = serverRows[j].getRowId();
            List<ServerRow> rowSplits = rowIdToserverRows.get(rowId);
            if (rowSplits == null) {
                rowSplits = new ArrayList<>(valueNum);
                rowIdToserverRows.put(rowId, rowSplits);
            }
            rowSplits.add(serverRows[j]);
        }
    }
    Vector[] vectors = new Vector[rowIds.length];
    for (int i = 0; i < rowIds.length; i++) {
        vectors[i] = MergeUtils.combineServerRowSplits(rowIdToserverRows.get(rowIds[i]), matrixId, rowIds[i]);
        vectors[i].setMatrixId(matrixId);
        vectors[i].setRowId(rowIds[i]);
    }
    return vectors;
}
Also used : HashMap(java.util.HashMap) Response(com.tencent.angel.ps.server.data.response.Response) GetRowsSplitResponse(com.tencent.angel.ps.server.data.response.GetRowsSplitResponse) GetRowsSplitResponse(com.tencent.angel.ps.server.data.response.GetRowsSplitResponse) ArrayList(java.util.ArrayList) List(java.util.List) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 2 with Response

use of com.tencent.angel.ps.server.data.response.Response in project angel by Tencent.

the class UpdateUDFHandler method handle.

@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
    MapResponseCache cache = (MapResponseCache) responseCache;
    // Check update result
    Map<Request, Response> responses = cache.getResponses();
    boolean success = true;
    String detail = "";
    for (Response response : responses.values()) {
        success = success && (response.getResponseType() == ResponseType.SUCCESS);
        if (!success) {
            detail = response.getDetail();
            break;
        }
    }
    // Set the final result
    if (success) {
        finalResult.set(new VoidResult(com.tencent.angel.psagent.matrix.ResponseType.SUCCESS));
    } else {
        finalResult.set(new VoidResult(com.tencent.angel.psagent.matrix.ResponseType.FAILED, detail));
    }
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) UpdateUDFResponse(com.tencent.angel.ps.server.data.response.UpdateUDFResponse) VoidResult(com.tencent.angel.ml.matrix.psf.update.base.VoidResult) Request(com.tencent.angel.ps.server.data.request.Request) UserRequest(com.tencent.angel.psagent.matrix.transport.adapter.UserRequest)

Example 3 with Response

use of com.tencent.angel.ps.server.data.response.Response in project angel by Tencent.

the class GetRowHandler method handle.

@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
    GetRowRequest getRowRequest = (GetRowRequest) userRequest;
    MapResponseCache cache = (MapResponseCache) responseCache;
    // Merge the sub-response
    List<ServerRow> serverRows = new ArrayList<>(cache.expectedResponseNum);
    for (Response response : cache.getResponses().values()) {
        serverRows.add(((GetRowSplitResponse) (response.getData())).getRowSplit());
    }
    Vector vector = MergeUtils.combineServerRowSplits(serverRows, getRowRequest.getMatrixId(), getRowRequest.getRowId());
    // Set matrix/row information
    vector.setMatrixId(getRowRequest.getMatrixId());
    vector.setRowId(getRowRequest.getRowId());
    // Set result
    finalResult.set(vector);
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) GetRowSplitResponse(com.tencent.angel.ps.server.data.response.GetRowSplitResponse) GetRowRequest(com.tencent.angel.psagent.matrix.transport.adapter.GetRowRequest) ArrayList(java.util.ArrayList) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 4 with Response

use of com.tencent.angel.ps.server.data.response.Response in project angel by Tencent.

the class IndexGetRowsHandler method handle.

@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
    IndexGetRowsRequest indexGetRowsRequest = (IndexGetRowsRequest) userRequest;
    MapResponseCache cache = (MapResponseCache) responseCache;
    ConcurrentHashMap<Request, Response> responses = cache.getResponses();
    // Merge
    Vector[] result = merge(indexGetRowsRequest, responses);
    // Set final result
    finalResult.set(result);
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) IndexPartGetRowsResponse(com.tencent.angel.ps.server.data.response.IndexPartGetRowsResponse) IndexGetRowsRequest(com.tencent.angel.psagent.matrix.transport.adapter.IndexGetRowsRequest) Request(com.tencent.angel.ps.server.data.request.Request) IndexPartGetRowsRequest(com.tencent.angel.ps.server.data.request.IndexPartGetRowsRequest) IndexGetRowsRequest(com.tencent.angel.psagent.matrix.transport.adapter.IndexGetRowsRequest) UserRequest(com.tencent.angel.psagent.matrix.transport.adapter.UserRequest) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 5 with Response

use of com.tencent.angel.ps.server.data.response.Response in project angel by Tencent.

the class UpdateHandler method handle.

@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
    MapResponseCache cache = (MapResponseCache) responseCache;
    // Check update result
    boolean success = true;
    String detail = "";
    for (Response response : cache.getResponses().values()) {
        success = success && (response.getResponseType() == ResponseType.SUCCESS);
        if (!success) {
            detail = response.getDetail();
            break;
        }
    }
    // Set the final result
    if (success) {
        finalResult.set(new VoidResult(com.tencent.angel.psagent.matrix.ResponseType.SUCCESS));
    } else {
        finalResult.set(new VoidResult(com.tencent.angel.psagent.matrix.ResponseType.FAILED, detail));
    }
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) UpdateResponse(com.tencent.angel.ps.server.data.response.UpdateResponse) VoidResult(com.tencent.angel.ml.matrix.psf.update.base.VoidResult)

Aggregations

Response (com.tencent.angel.ps.server.data.response.Response)8 Vector (com.tencent.angel.ml.math2.vector.Vector)4 Request (com.tencent.angel.ps.server.data.request.Request)4 UserRequest (com.tencent.angel.psagent.matrix.transport.adapter.UserRequest)4 ArrayList (java.util.ArrayList)3 VoidResult (com.tencent.angel.ml.matrix.psf.update.base.VoidResult)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)1 BasicStreamUpdateHandler (com.tencent.angel.ps.server.data.handler.BasicStreamUpdateHandler)1 GetPartHandler (com.tencent.angel.ps.server.data.handler.GetPartHandler)1 GetRowHandler (com.tencent.angel.ps.server.data.handler.GetRowHandler)1 GetRowsHandler (com.tencent.angel.ps.server.data.handler.GetRowsHandler)1 Handler (com.tencent.angel.ps.server.data.handler.Handler)1 IndexGetRowHandler (com.tencent.angel.ps.server.data.handler.IndexGetRowHandler)1 IndexGetRowsHandler (com.tencent.angel.ps.server.data.handler.IndexGetRowsHandler)1 PSFGetHandler (com.tencent.angel.ps.server.data.handler.PSFGetHandler)1 PSFUpdateHandler (com.tencent.angel.ps.server.data.handler.PSFUpdateHandler)1 StreamIndexGetRowHandler (com.tencent.angel.ps.server.data.handler.StreamIndexGetRowHandler)1 StreamIndexGetRowsHandler (com.tencent.angel.ps.server.data.handler.StreamIndexGetRowsHandler)1 IndexPartGetRowRequest (com.tencent.angel.ps.server.data.request.IndexPartGetRowRequest)1