Search in sources :

Example 6 with Response

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

the class GetUDFHandler method handle.

@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
    GetPSFRequest getPSFRequest = (GetPSFRequest) userRequest;
    MapResponseCache cache = (MapResponseCache) responseCache;
    // Adaptor to Get PSF merge
    ConcurrentHashMap<Request, Response> responses = cache.getResponses();
    int responseNum = responses.size();
    List<PartitionGetResult> partGetResults = new ArrayList<>(responseNum);
    for (Response response : responses.values()) {
        partGetResults.add(((GetUDFResponse) response.getData()).getPartResult());
    }
    // Merge the sub-results
    try {
        finalResult.set(getPSFRequest.getGetFunc().merge(partGetResults));
    } catch (Exception x) {
        LOG.error("merge row failed ", x);
        finalResult.setExecuteException(new ExecutionException(x));
    }
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) GetUDFResponse(com.tencent.angel.ps.server.data.response.GetUDFResponse) Request(com.tencent.angel.ps.server.data.request.Request) GetPSFRequest(com.tencent.angel.psagent.matrix.transport.adapter.GetPSFRequest) UserRequest(com.tencent.angel.psagent.matrix.transport.adapter.UserRequest) ArrayList(java.util.ArrayList) GetPSFRequest(com.tencent.angel.psagent.matrix.transport.adapter.GetPSFRequest) ExecutionException(java.util.concurrent.ExecutionException) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with Response

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

the class IndexGetRowHandler method handle.

@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
    IndexGetRowRequest indexGetRowRequest = (IndexGetRowRequest) userRequest;
    MapResponseCache cache = (MapResponseCache) responseCache;
    ConcurrentHashMap<Request, Response> responses = cache.getResponses();
    // Merge
    Vector result = merge(indexGetRowRequest, responses);
    // Set matrix/row meta
    result.setMatrixId(indexGetRowRequest.getMatrixId());
    result.setRowId(indexGetRowRequest.getRowId());
    // Set final result
    finalResult.set(result);
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) StreamIndexPartGetRowResponse(com.tencent.angel.ps.server.data.response.StreamIndexPartGetRowResponse) IndexGetRowRequest(com.tencent.angel.psagent.matrix.transport.adapter.IndexGetRowRequest) Request(com.tencent.angel.ps.server.data.request.Request) IndexGetRowRequest(com.tencent.angel.psagent.matrix.transport.adapter.IndexGetRowRequest) IndexPartGetRowRequest(com.tencent.angel.ps.server.data.request.IndexPartGetRowRequest) UserRequest(com.tencent.angel.psagent.matrix.transport.adapter.UserRequest) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 8 with Response

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

the class WorkerPool method handle.

/**
 * Handle rpc
 *
 * @param requestHeader request meta data
 * @param in request data
 * @param ctx netty channel context
 */
private void handle(RequestHeader requestHeader, ByteBuf in, ChannelHandlerContext ctx) {
    ResponseData responseData = null;
    ResponseHeader responseHeader;
    ServerState state = runningContext.getState();
    if (state == ServerState.BUSY) {
        responseHeader = new ResponseHeader(requestHeader.seqId, requestHeader.methodId, ServerState.BUSY, ResponseType.SERVER_IS_BUSY, "server is busy now, retry later");
    } else {
        // Idle, handle the request
        // Parse head success
        Handler handler = methodIdToHandler.get(requestHeader.methodId);
        // Handle request
        if (handler != null) {
            try {
                ByteBufSerdeUtils.deserializeBoolean(in);
                RequestData request = handler.parseRequest(in);
                requestSize.addAndGet(request.requestSize);
                responseData = handler.handle(requestHeader, request);
                requestSize.addAndGet(responseData.bufferLen());
                responseHeader = new ResponseHeader(requestHeader.seqId, requestHeader.methodId, state, ResponseType.SUCCESS);
            } catch (Throwable e) {
                // Handle error, generate response
                responseHeader = new ResponseHeader(requestHeader.seqId, requestHeader.methodId, state, ResponseType.SERVER_HANDLE_FAILED, StringUtils.stringifyException(e));
            }
        } else {
            responseHeader = new ResponseHeader(requestHeader.seqId, requestHeader.methodId, state, ResponseType.UNSUPPORT_REQUEST);
        }
    }
    // Release the input buffer
    ByteBufUtils.releaseBuf(in);
    // Create response
    Response response = new Response(responseHeader, responseData);
    // LOG.info("Response header = " + responseHeader);
    // Serialize the response
    // 2. Serialize the response
    ByteBuf out = ByteBufUtils.serializeResponse(response, context.isUseDirectBuffer());
    // Send the serialized response
    if (out != null) {
        sendResult(requestHeader, ctx, out);
        return;
    } else {
        runningContext.after(requestHeader.clientId, requestHeader.seqId);
        return;
    }
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) ResponseHeader(com.tencent.angel.ps.server.data.response.ResponseHeader) RequestData(com.tencent.angel.ps.server.data.request.RequestData) ResponseData(com.tencent.angel.ps.server.data.response.ResponseData) GetPartHandler(com.tencent.angel.ps.server.data.handler.GetPartHandler) BasicStreamUpdateHandler(com.tencent.angel.ps.server.data.handler.BasicStreamUpdateHandler) StreamIndexGetRowHandler(com.tencent.angel.ps.server.data.handler.StreamIndexGetRowHandler) IndexGetRowHandler(com.tencent.angel.ps.server.data.handler.IndexGetRowHandler) IndexGetRowsHandler(com.tencent.angel.ps.server.data.handler.IndexGetRowsHandler) GetRowsHandler(com.tencent.angel.ps.server.data.handler.GetRowsHandler) Handler(com.tencent.angel.ps.server.data.handler.Handler) PSFUpdateHandler(com.tencent.angel.ps.server.data.handler.PSFUpdateHandler) PSFGetHandler(com.tencent.angel.ps.server.data.handler.PSFGetHandler) GetRowHandler(com.tencent.angel.ps.server.data.handler.GetRowHandler) StreamIndexGetRowsHandler(com.tencent.angel.ps.server.data.handler.StreamIndexGetRowsHandler) ByteBuf(io.netty.buffer.ByteBuf)

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