use of com.tencent.angel.psagent.matrix.transport.MatrixTransportClient in project angel by Tencent.
the class UserRequestAdapter method update.
public Future<VoidResult> update(int matrixId, int rowId, Vector delta, UpdateOp op) {
checkParams(matrixId, rowId);
delta.setMatrixId(matrixId);
delta.setRowId(rowId);
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = matrixMeta.getPartitionKeys();
CompStreamKeyValuePart[] splits = RouterUtils.splitStream(matrixMeta, delta);
FutureResult<VoidResult> result = new FutureResult<>();
int needRequestPartNum = noEmptyPartNum(splits);
if (needRequestPartNum == 0) {
result.set(null);
return result;
}
UpdateRowRequest request = new UpdateRowRequest(matrixId, rowId, 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;
}
use of com.tencent.angel.psagent.matrix.transport.MatrixTransportClient in project angel by Tencent.
the class UserRequestAdapter method update.
/**
* Update matrix use a udf.
*
* @param updateFunc update udf function
* @return Future<VoidResult> update future result
*/
public Future<VoidResult> update(UpdateFunc updateFunc) {
MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
UpdateParam param = updateFunc.getParam();
// Split the param use matrix partitions
List<PartitionUpdateParam> partParams = param.split();
int size = partParams.size();
UpdatePSFRequest request = new UpdatePSFRequest(updateFunc);
ResponseCache cache = new MapResponseCache(size);
FutureResult<VoidResult> result = new FutureResult<>();
int requestId = request.getRequestId();
requests.put(requestId, request);
requestIdToResponseCache.put(requestId, cache);
requestIdToResultMap.put(requestId, result);
// Send request to PSS
for (int i = 0; i < size; i++) {
sendUpdateUDFRequest(matrixClient, requestId, partParams.get(i).getMatrixId(), partParams.get(i).getPartKey().getPartitionId(), updateFunc, partParams.get(i));
}
return result;
}
use of com.tencent.angel.psagent.matrix.transport.MatrixTransportClient in project angel by Tencent.
the class UserRequestAdapter method update.
public Future<VoidResult> update(int matrixId, int[] rowIds, Vector[] rows, UpdateOp op) {
assert rowIds.length == rows.length;
checkParams(matrixId, rowIds);
for (int i = 0; i < rowIds.length; i++) {
rows[i].setRowId(rowIds[i]);
}
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = matrixMeta.getPartitionKeys();
CompStreamKeyValuePart[] splits = RouterUtils.splitStream(matrixMeta, rows);
int needRequestPartNum = noEmptyPartNum(splits);
FutureResult<VoidResult> result = new FutureResult<>();
if (needRequestPartNum == 0) {
result.set(null);
return result;
}
UpdateRowsRequest request = new UpdateRowsRequest(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;
}
use of com.tencent.angel.psagent.matrix.transport.MatrixTransportClient 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;
}
use of com.tencent.angel.psagent.matrix.transport.MatrixTransportClient 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;
}
Aggregations