use of com.tencent.angel.worker.Worker in project angel by Tencent.
the class UpdateRowsTest method testSparseFloatUDF.
public void testSparseFloatUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_FLOAT_MAT, 0);
int[] index = genIndexs(feaNum, nnz);
IntFloatVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = new IntFloatVector(feaNum, new IntFloatSparseVectorStorage(feaNum));
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
client1.update(rowId, deltaVec);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntFloatVector) rows[i]).get(id), deltaVec.get(id), zero);
}
Assert.assertTrue(index.length == ((IntFloatVector) rows[i]).size());
}
client1.zero();
IntFloatVector[] deltaVecs = new IntFloatVector[rowNum];
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseFloatVector(feaNum, index.length);
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
deltaVecs[rowId] = deltaVec;
}
client1.update(rowIds, deltaVecs);
rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntFloatVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
client1.zero();
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseFloatVector(feaNum, index.length);
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
deltaVecs[rowId] = deltaVec;
}
client1.increment(rowIds, deltaVecs, true);
rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntFloatVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
}
use of com.tencent.angel.worker.Worker in project angel by Tencent.
the class UpdateRowsTest method testSparseIntLongKeyUDF.
public void testSparseIntLongKeyUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_INT_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
long[] index = genLongIndexs(feaNum, nnz);
LongIntVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = new LongIntVector(feaNum, new LongIntSparseVectorStorage(feaNum));
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], (int) index[i]);
}
client1.update(rowId, deltaVec);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (long id : index) {
Assert.assertEquals(((LongIntVector) rows[i]).get(id), deltaVec.get(id), zero);
}
}
client1.zero();
LongIntVector[] deltaVecs = new LongIntVector[rowNum];
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseLongKeyIntVector(feaNum, index.length);
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], (int) index[i]);
}
deltaVecs[rowId] = deltaVec;
}
client1.update(rowIds, deltaVecs);
rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (long id : index) {
Assert.assertEquals(((LongIntVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
client1.zero();
deltaVecs = new LongIntVector[rowNum];
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseLongKeyIntVector(feaNum, index.length);
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], (int) index[i]);
}
deltaVecs[rowId] = deltaVec;
}
client1.increment(rowIds, deltaVecs, true);
rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (long id : index) {
Assert.assertEquals(((LongIntVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
}
use of com.tencent.angel.worker.Worker in project angel by Tencent.
the class UpdateRowsTest method testDenseIntUDF.
public void testDenseIntUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_INT_MAT, 0);
int matrixW1Id = client1.getMatrixId();
int[] index = genIndexs(feaNum, nnz);
IntIntVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = new IntIntVector(feaNum, new IntIntDenseVectorStorage(feaNum));
for (int i = 0; i < feaNum; i++) deltaVec.set(i, i);
client1.update(rowId, deltaVec);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVec.get(id), zero);
}
}
client1.zero();
IntIntVector[] deltaVecs = new IntIntVector[rowNum];
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseIntVector(feaNum, index.length);
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
deltaVecs[rowId] = deltaVec;
}
client1.update(rowIds, deltaVecs);
rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
client1.zero();
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseIntVector(feaNum, index.length);
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
deltaVecs[rowId] = deltaVec;
}
client1.increment(rowIds, deltaVecs, true);
rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
}
use of com.tencent.angel.worker.Worker in project angel by Tencent.
the class UpdateRowsTest method testDenseLongUDF.
public void testDenseLongUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
int[] index = genIndexs(feaNum, nnz);
IntLongVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = new IntLongVector(feaNum, new IntLongDenseVectorStorage(feaNum));
for (int i = 0; i < feaNum; i++) deltaVec.set(i, i);
client1.update(rowId, deltaVec);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntLongVector) rows[i]).get(id), deltaVec.get(id), zero);
}
}
client1.zero();
IntLongVector[] deltaVecs = new IntLongVector[rowNum];
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseLongVector(feaNum, index.length);
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
deltaVecs[rowId] = deltaVec;
}
client1.update(rowIds, deltaVecs);
rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntLongVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
client1.zero();
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseLongVector(feaNum, index.length);
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
deltaVecs[rowId] = deltaVec;
}
client1.increment(rowIds, deltaVecs, true);
rows = client1.get(rowIds, index);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((IntLongVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
}
use of com.tencent.angel.worker.Worker in project angel by Tencent.
the class MasterServiceTest method testMasterService.
@Test
public void testMasterService() throws Exception {
try {
LOG.info("===========================testMasterService===============================");
Worker worker = LocalClusterContext.get().getWorker(worker0Attempt0Id).getWorker();
Location masterLoc = LocalClusterContext.get().getMaster().getAppMaster().getAppContext().getMasterService().getLocation();
TConnection connection = TConnectionManager.getConnection(worker.getConf());
MasterProtocol master = connection.getMasterService(masterLoc.getIp(), masterLoc.getPort());
int psAgentId = master.getPSAgentId(null, PSAgentMasterServiceProtos.GetPSAgentIdRequest.getDefaultInstance()).getPsAgentId();
// worker register
WorkerAttemptId worker1Attempt0Id = new WorkerAttemptId(new WorkerId(new WorkerGroupId(1), 0), 0);
WorkerRegisterRequest registeRequest = WorkerRegisterRequest.newBuilder().setPsAgentId(psAgentId).setWorkerAttemptId(ProtobufUtil.convertToIdProto(worker1Attempt0Id)).setLocation(LocationProto.newBuilder().setIp("0.0.0.0").setPort(10000).build()).build();
WorkerRegisterResponse registerResponse = master.workerRegister(null, registeRequest);
assertTrue(registerResponse.getCommand() == WorkerCommandProto.W_SHUTDOWN);
WorkerReportRequest.Builder reportBuilder = WorkerReportRequest.newBuilder();
Pair.Builder kvBuilder = Pair.newBuilder();
TaskStateProto.Builder taskBuilder = TaskStateProto.newBuilder();
reportBuilder.setWorkerAttemptId(ProtobufUtil.convertToIdProto(worker0Attempt0Id));
taskBuilder.setProgress(0.20f);
taskBuilder.setState("RUNNING");
taskBuilder.setTaskId(ProtobufUtil.convertToIdProto(task0Id));
kvBuilder.setKey("task_key1");
kvBuilder.setValue("100");
taskBuilder.addCounters(kvBuilder.build());
kvBuilder.setKey("task_key2");
kvBuilder.setValue("200");
taskBuilder.addCounters(kvBuilder.build());
reportBuilder.addTaskReports(taskBuilder.build());
taskBuilder.setProgress(0.30f);
taskBuilder.setState("RUNNING");
taskBuilder.setTaskId(ProtobufUtil.convertToIdProto(task1Id));
kvBuilder.setKey("task_key1");
kvBuilder.setValue("1000");
taskBuilder.addCounters(kvBuilder.build());
kvBuilder.setKey("task_key2");
kvBuilder.setValue("2000");
taskBuilder.addCounters(kvBuilder.build());
reportBuilder.addTaskReports(taskBuilder.build());
kvBuilder.setKey("worker_key1");
kvBuilder.setValue("100");
reportBuilder.addPairs(kvBuilder.build());
kvBuilder.setKey("worker_key2");
kvBuilder.setValue("200");
reportBuilder.addPairs(kvBuilder.build());
WorkerReportResponse reportResponse = master.workerReport(null, reportBuilder.build());
assertTrue(reportResponse.getCommand() == WorkerCommandProto.W_SUCCESS);
assertEquals(reportResponse.getActiveTaskNum(), 2);
AngelApplicationMaster angelAppMaster = LocalClusterContext.get().getMaster().getAppMaster();
WorkerAttempt worker0Attempt = angelAppMaster.getAppContext().getWorkerManager().getWorker(worker0Attempt0Id.getWorkerId()).getWorkerAttempt(worker0Attempt0Id);
assertTrue(worker0Attempt != null);
Map<String, String> workerMetrics = worker0Attempt.getMetrics();
String valueForWorkerKey1 = workerMetrics.get("worker_key1");
String valueForWorkerKey2 = workerMetrics.get("worker_key2");
assertNotNull(valueForWorkerKey1);
assertNotNull(valueForWorkerKey2);
assertEquals(valueForWorkerKey1, "100");
assertEquals(valueForWorkerKey2, "200");
AMTaskManager amTaskManager = angelAppMaster.getAppContext().getTaskManager();
AMTask task0 = amTaskManager.getTask(task0Id);
AMTask task1 = amTaskManager.getTask(task1Id);
assertTrue(task0 != null);
assertTrue(task1 != null);
Map<String, String> task0Metrics = task0.getMetrics();
Map<String, String> task1Metrics = task1.getMetrics();
String valueForTask0Key1 = task0Metrics.get("task_key1");
String valueForTask0Key2 = task0Metrics.get("task_key2");
String valueForTask1Key1 = task1Metrics.get("task_key1");
String valueForTask1Key2 = task1Metrics.get("task_key2");
assertTrue(valueForTask0Key1 != null);
assertTrue(valueForTask0Key2 != null);
assertTrue(valueForTask1Key1 != null);
assertTrue(valueForTask1Key2 != null);
assertEquals(valueForTask0Key1, "100");
assertEquals(valueForTask0Key2, "200");
assertEquals(valueForTask1Key1, "1000");
assertEquals(valueForTask1Key2, "2000");
assertEquals(task0.getProgress(), 0.20f, 0.000001);
assertEquals(task1.getProgress(), 0.30f, 0.000001);
} catch (Exception x) {
LOG.error("run testMasterService failed ", x);
throw x;
}
}
Aggregations