use of com.tencent.angel.psagent.consistency.ConsistencyController in project angel by Tencent.
the class PSAgent method initAndStart.
public void initAndStart() throws Exception {
// Get ps locations from master and put them to the location cache.
locationManager = new PSAgentLocationManager(PSAgentContext.get());
locationManager.setMasterLocation(masterLocation);
// Build and initialize rpc client to master
masterClient = new MasterClient();
masterClient.init();
// Build local location
String localIp = NetUtils.getRealLocalIP();
int port = NetUtils.chooseAListenPort(conf);
location = new Location(localIp, port);
// Initialize matrix meta information
clockCache = new ClockCache();
List<MatrixMeta> matrixMetas = masterClient.getMatrices();
LOG.info("===========================PSAgent get matrices from master," + matrixMetas.size());
this.matrixMetaManager = new PSAgentMatrixMetaManager(clockCache);
matrixMetaManager.addMatrices(matrixMetas);
Map<ParameterServerId, Location> psIdToLocMap = masterClient.getPSLocations();
List<ParameterServerId> psIds = new ArrayList<>(psIdToLocMap.keySet());
Collections.sort(psIds, new Comparator<ParameterServerId>() {
@Override
public int compare(ParameterServerId s1, ParameterServerId s2) {
return s1.getIndex() - s2.getIndex();
}
});
int size = psIds.size();
locationManager.setPsIds(psIds.toArray(new ParameterServerId[0]));
for (int i = 0; i < size; i++) {
if (psIdToLocMap.containsKey(psIds.get(i))) {
locationManager.setPsLocation(psIds.get(i), psIdToLocMap.get(psIds.get(i)));
}
}
matrixTransClient = new MatrixTransportClient();
matrixClientAdapter = new MatrixClientAdapter();
opLogCache = new MatrixOpLogCache();
matrixStorageManager = new MatrixStorageManager();
matricesCache = new MatricesCache();
int staleness = conf.getInt(AngelConf.ANGEL_STALENESS, AngelConf.DEFAULT_ANGEL_STALENESS);
consistencyController = new ConsistencyController(staleness);
consistencyController.init();
psAgentInitFinishedFlag.set(true);
// Start heartbeat thread if need
if (needHeartBeat) {
startHeartbeatThread();
}
// Start all services
matrixTransClient.start();
matrixClientAdapter.start();
clockCache.start();
opLogCache.start();
matricesCache.start();
}
use of com.tencent.angel.psagent.consistency.ConsistencyController in project angel by Tencent.
the class PSAgentTest method testConsistencyController.
@Test
public void testConsistencyController() throws Exception {
try {
AngelApplicationMaster angelAppMaster = LocalClusterContext.get().getMaster().getAppMaster();
assertTrue(angelAppMaster != null);
AMTaskManager taskManager = angelAppMaster.getAppContext().getTaskManager();
assertTrue(taskManager != null);
WorkerManager workerManager = angelAppMaster.getAppContext().getWorkerManager();
assertTrue(workerManager != null);
Worker worker = LocalClusterContext.get().getWorker(worker0Attempt0Id).getWorker();
assertTrue(worker != null);
PSAgent psAgent = worker.getPSAgent();
assertTrue(psAgent != null);
ConsistencyController consistControl = psAgent.getConsistencyController();
assertTrue(consistControl != null);
PSAgentContext psAgentContext = PSAgentContext.get();
assertTrue(psAgentContext.getPsAgent() != null);
TaskContext taskContext1 = psAgentContext.getTaskContext(1);
TaskContext taskContext2 = psAgentContext.getTaskContext(2);
assertTrue(taskContext1 != null);
assertTrue(taskContext2 != null);
int matrix1Id = LocalClusterContext.get().getMaster().getAppMaster().getAppContext().getMatrixMetaManager().getMatrix("w1").getId();
int matrix2Id = LocalClusterContext.get().getMaster().getAppMaster().getAppContext().getMatrixMetaManager().getMatrix("w2").getId();
TVector row1 = consistControl.getRow(taskContext1, matrix1Id, 0);
assertTrue(row1 != null);
assertEquals(row1.size(), 100000);
TVector row2 = consistControl.getRow(taskContext1, matrix2Id, 0);
assertTrue(row2 != null);
assertEquals(row2.size(), 100000);
consistControl.clock(taskContext1, matrix1Id, true);
assertEquals(taskContext1.getMatrixClock(matrix1Id), 1);
int staleness = psAgent.getConf().getInt(AngelConf.ANGEL_STALENESS, AngelConf.DEFAULT_ANGEL_STALENESS);
} catch (Exception x) {
LOG.error("run testConsistencyController failed ", x);
throw x;
}
}
Aggregations