Search in sources :

Example 26 with FutureResult

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

the class MatrixClientAdapter method flush.

/**
 * Flush the matrix oplog to parameter servers.
 *
 * @param matrixId    matrix id
 * @param taskContext task context
 * @param matrixOpLog matrix oplog
 * @param updateClock true means we should update the clock value after update matrix
 * @return Future<VoidResult> flush future result
 */
public Future<VoidResult> flush(int matrixId, TaskContext taskContext, MatrixOpLog matrixOpLog, boolean updateClock) {
    if (!updateClock && (matrixOpLog == null)) {
        FutureResult<VoidResult> ret = new FutureResult<VoidResult>();
        ret.set(new VoidResult(ResponseType.SUCCESS));
        return ret;
    }
    Map<PartitionKey, List<RowUpdateSplit>> psUpdateData = new HashMap<PartitionKey, List<RowUpdateSplit>>();
    FlushRequest request = new FlushRequest(taskContext.getMatrixClock(matrixId), taskContext.getIndex(), matrixId, matrixOpLog, updateClock);
    LOG.debug("start to flush update for matrix=" + matrixId + ", taskIndex=" + taskContext.getIndex());
    long startTs = System.currentTimeMillis();
    // Split the matrix oplog according to the matrix partitions
    if (matrixOpLog != null) {
        matrixOpLog.split(psUpdateData);
    }
    LOG.debug("split use time=" + (System.currentTimeMillis() - startTs));
    // If need update clock, we should send requests to all partitions
    if (updateClock) {
        fillPartRequestForClock(matrixId, psUpdateData, taskContext);
    }
    FlushResponseCache cache = new FlushResponseCache(psUpdateData.size());
    pushUpdates(matrixId, psUpdateData, taskContext, updateClock, cache);
    requestToResponseMap.put(request, cache);
    return cache.getMergedResult();
}
Also used : VoidResult(com.tencent.angel.ml.matrix.psf.update.enhance.VoidResult) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) PartitionKey(com.tencent.angel.PartitionKey) RowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit)

Example 27 with FutureResult

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

the class PS2PSPusherImpl method updateClock.

@Override
public void updateClock(PartitionKey partKey, int taskIndex, int clock, PartitionLocation partLoc) {
    if (partLoc.psLocs.size() == 1) {
        return;
    } else {
        if (partLoc.psLocs.get(0).psId.equals(context.getPSAttemptId().getPsId())) {
            int size = partLoc.psLocs.size();
            List<FutureResult> results = new ArrayList<>(size - 1);
            for (int i = 1; i < size; i++) {
                results.add(psClient.updateClock(partLoc.psLocs.get(i).psId, partLoc.psLocs.get(i).loc, partKey, taskIndex, clock));
            }
            size = results.size();
            for (int i = 0; i < size; i++) {
                try {
                    Response result = (Response) results.get(i).get();
                    if (result.getResponseType() != ResponseType.SUCCESS) {
                        if (result.getResponseType() == ResponseType.NETWORK_ERROR || result.getResponseType() == ResponseType.TIMEOUT) {
                            context.getPSFailedReport().psFailed(partLoc.psLocs.get(i));
                        }
                        increaseFailedCounter(partKey, partLoc.psLocs.get(i));
                    }
                } catch (Exception e) {
                    LOG.error("wait for result for sync failed ", e);
                    increaseFailedCounter(partKey, partLoc.psLocs.get(i));
                }
            }
        }
    }
}
Also used : Response(com.tencent.angel.ml.matrix.transport.Response) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException)

Example 28 with FutureResult

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

the class PeriodPusher method recover.

@Override
public FutureResult<Response> recover(RecoverPartKey partKey) {
    FutureResult<Response> result = new FutureResult<>();
    workerPool.execute(() -> {
        ServerPartition part = context.getMatrixStorageManager().getPart(partKey.partKey);
        if (part == null) {
            result.set(new Response(ResponseType.UNKNOWN_ERROR, "Can not find partition " + partKey.partKey.getMatrixId() + ":" + partKey.partKey.getPartitionId()));
            return;
        }
        try {
            result.set(psClient.recoverPart(partKey.psLoc.psId, partKey.psLoc.loc, part).get());
        } catch (Throwable e) {
            LOG.error("recover part " + partKey + " falied ", e);
            result.set(new Response(ResponseType.UNKNOWN_ERROR, e.getMessage()));
        }
    });
    return result;
}
Also used : Response(com.tencent.angel.ml.matrix.transport.Response) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) ServerPartition(com.tencent.angel.ps.impl.matrix.ServerPartition)

Example 29 with FutureResult

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

the class PSClient method updateClock.

/**
 * Update partition clock
 * @param serverId ps id
 * @param location ps location
 * @param partKey partition information
 * @param taskIndex task index
 * @param clock clock value
 * @return future result
 */
public FutureResult<Response> updateClock(ParameterServerId serverId, Location location, PartitionKey partKey, int taskIndex, int clock) {
    int seqId = seqIdGen.incrementAndGet();
    UpdateClockRequest request = new UpdateClockRequest(partKey, taskIndex, clock);
    FutureResult<Response> response = new FutureResult<>();
    seqIdToResultMap.put(seqId, response);
    seqIdToRequestMap.put(seqId, request);
    // Serialize the request
    ByteBuf msg = ByteBufUtils.newByteBuf(8 + request.bufferLen(), useDirectBuf);
    msg.writeInt(seqId);
    msg.writeInt(request.getType().getMethodId());
    request.serialize(msg);
    send(serverId, location, seqId, request, msg, response);
    return response;
}
Also used : FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) ByteBuf(io.netty.buffer.ByteBuf)

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