Search in sources :

Example 1 with AngelApplicationMaster

use of com.tencent.angel.master.AngelApplicationMaster in project angel by Tencent.

the class PSAgentTest method testClockCache.

@Test
public void testClockCache() 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);
        ClockCache clockCache = psAgent.getClockCache();
        assertTrue(clockCache != null);
        int rowClock = clockCache.getClock(1, 0);
        assertEquals(rowClock, 0);
    } catch (Exception x) {
        LOG.error("run testClockCache failed ", x);
        throw x;
    }
}
Also used : WorkerManager(com.tencent.angel.master.worker.WorkerManager) AMTaskManager(com.tencent.angel.master.task.AMTaskManager) ClockCache(com.tencent.angel.psagent.clock.ClockCache) AngelApplicationMaster(com.tencent.angel.master.AngelApplicationMaster) Worker(com.tencent.angel.worker.Worker) Test(org.junit.Test)

Example 2 with AngelApplicationMaster

use of com.tencent.angel.master.AngelApplicationMaster in project angel by Tencent.

the class PSAgentTest method testPSAgentContext.

@Test
public void testPSAgentContext() 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);
        PSAgentContext psAgentContext = PSAgentContext.get();
        assertTrue(psAgentContext.getPsAgent() != null);
        assertTrue(psAgentContext.getConf() != null);
        assertTrue(psAgentContext.getMetrics() != null);
        assertTrue(psAgentContext.getMasterClient() != null);
        assertTrue(psAgentContext.getIdProto() != null);
        assertTrue(psAgentContext.getOpLogCache() != null);
        assertTrue(psAgentContext.getMatrixTransportClient() != null);
        assertTrue(psAgentContext.getMatrixMetaManager() != null);
        assertTrue(psAgentContext.getMatrixMetaManager() != null);
        assertTrue(psAgentContext.getLocationManager() != null);
        assertEquals(psAgentContext.getRunningMode(), psAgent.getRunningMode());
        assertEquals(psAgentContext.getIp(), psAgent.getIp());
        assertEquals(psAgentContext.getStaleness(), psAgent.getConf().getInt(AngelConf.ANGEL_STALENESS, AngelConf.DEFAULT_ANGEL_STALENESS));
        assertEquals(psAgentContext.getConsistencyController(), psAgent.getConsistencyController());
        assertEquals(psAgentContext.getMatrixOpLogCache(), psAgent.getOpLogCache());
        assertEquals(psAgentContext.getClockCache(), psAgent.getClockCache());
        assertEquals(psAgentContext.getMatricesCache(), psAgent.getMatricesCache());
        assertEquals(psAgentContext.getMatrixStorageManager(), psAgent.getMatrixStorageManager());
        assertEquals(psAgentContext.getMatrixClientAdapter(), psAgent.getMatrixClientAdapter());
        assertEquals(psAgentContext.getExecutor(), psAgent.getExecutor());
        assertTrue(psAgentContext.getTaskContext(1) != null);
        assertTrue(psAgentContext.getTaskContext(2) != null);
        int taskNum = psAgentContext.getTotalTaskNum();
        assertEquals(taskNum, 2);
        int localTaskNum = psAgentContext.getLocalTaskNum();
        assertEquals(localTaskNum, 2);
    } catch (Exception x) {
        LOG.error("run testPSAgentContext failed ", x);
        throw x;
    }
}
Also used : WorkerManager(com.tencent.angel.master.worker.WorkerManager) AMTaskManager(com.tencent.angel.master.task.AMTaskManager) AngelApplicationMaster(com.tencent.angel.master.AngelApplicationMaster) Worker(com.tencent.angel.worker.Worker) Test(org.junit.Test)

Example 3 with AngelApplicationMaster

use of com.tencent.angel.master.AngelApplicationMaster in project angel by Tencent.

the class PSAgentTest method testTaskContext.

@Test
public void testTaskContext() 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);
        PSAgentContext psAgentContext = PSAgentContext.get();
        assertTrue(psAgentContext.getPsAgent() != null);
        TaskContext taskContext1 = psAgentContext.getTaskContext(1);
        TaskContext taskContext2 = psAgentContext.getTaskContext(2);
        assertTrue(taskContext1 != null);
        assertTrue(taskContext2 != null);
        assertEquals(taskContext1.getIndex(), 1);
        assertEquals(taskContext2.getIndex(), 2);
        assertEquals(taskContext1.getEpoch(), 0);
        assertEquals(taskContext2.getEpoch(), 0);
        assertEquals(taskContext1.getMatrixClock(1), 0);
        assertEquals(taskContext2.getMatrixClock(2), 0);
        assertEquals(taskContext1.getMatrixClocks().size(), 1);
        assertEquals(taskContext2.getMatrixClocks().size(), 1);
        assertEquals(taskContext1.getProgress(), 0.0, 1e-5);
        assertEquals(taskContext2.getProgress(), 0.0, 1e-5);
    } catch (Exception x) {
        LOG.error("run testTaskContext failed ", x);
        throw x;
    }
}
Also used : WorkerManager(com.tencent.angel.master.worker.WorkerManager) AMTaskManager(com.tencent.angel.master.task.AMTaskManager) TaskContext(com.tencent.angel.psagent.task.TaskContext) AngelApplicationMaster(com.tencent.angel.master.AngelApplicationMaster) Worker(com.tencent.angel.worker.Worker) Test(org.junit.Test)

Example 4 with AngelApplicationMaster

use of com.tencent.angel.master.AngelApplicationMaster in project angel by Tencent.

the class PSAgentTest method testPSClient.

@Test
public void testPSClient() 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);
        // psAgent.initAndStart();
        // test conf
        Configuration conf = psAgent.getConf();
        assertTrue(conf != null);
        assertEquals(conf.get(AngelConf.ANGEL_DEPLOY_MODE), "LOCAL");
        // test master location
        Location masterLoc = psAgent.getMasterLocation();
        String ipRegex = "(2[5][0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})";
        Pattern pattern = Pattern.compile(ipRegex);
        Matcher matcher = pattern.matcher(masterLoc.getIp());
        assertTrue(matcher.matches());
        assertTrue(masterLoc.getPort() >= 1 && masterLoc.getPort() <= 65535);
        // test app id
        ApplicationId appId = psAgent.getAppId();
        // test user
        String user = psAgent.getUser();
        // test ps agent attempt id
        PSAgentAttemptId psAgentAttemptId = psAgent.getId();
        assertEquals(psAgentAttemptId.toString(), "PSAgentAttempt_0_0");
        assertEquals(psAgentAttemptId.getIndex(), 0);
        // test ps agent id
        PSAgentId psAgentId = psAgentAttemptId.getPsAgentId();
        assertEquals(psAgentId.toString(), "PSAgent_0");
        assertEquals(psAgentId.getIndex(), 0);
        // test connection
        TConnection conn = psAgent.getConnection();
        assertTrue(conn != null);
        // test master client
        MasterClient masterClient = psAgent.getMasterClient();
        assertTrue(masterClient != null);
        // test ip
        String ip = psAgent.getIp();
        matcher = pattern.matcher(ip);
        assertTrue(matcher.matches());
        // test loc
        Location loc = psAgent.getLocation();
        assertTrue(loc != null);
        matcher = pattern.matcher(loc.getIp());
        assertTrue(matcher.matches());
        assertTrue(loc.getPort() >= 1 && loc.getPort() <= 65535);
    } catch (Exception x) {
        LOG.error("run testPSClient failed ", x);
        throw x;
    }
}
Also used : Pattern(java.util.regex.Pattern) Configuration(org.apache.hadoop.conf.Configuration) Matcher(java.util.regex.Matcher) MasterClient(com.tencent.angel.psagent.client.MasterClient) WorkerManager(com.tencent.angel.master.worker.WorkerManager) AMTaskManager(com.tencent.angel.master.task.AMTaskManager) TConnection(com.tencent.angel.ipc.TConnection) AngelApplicationMaster(com.tencent.angel.master.AngelApplicationMaster) Worker(com.tencent.angel.worker.Worker) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Location(com.tencent.angel.common.location.Location) Test(org.junit.Test)

Example 5 with AngelApplicationMaster

use of com.tencent.angel.master.AngelApplicationMaster in project angel by Tencent.

the class PSAgentTest method testMatrixMetaManager.

@Test
public void testMatrixMetaManager() 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);
        PSAgentMatrixMetaManager matrixMetaManager = psAgent.getMatrixMetaManager();
        assertTrue(matrixMetaManager != null);
        // test all matrix ids
        assertEquals(matrixMetaManager.getMatrixMetas().size(), 2);
        // test all matrix names
        assertNotNull(matrixMetaManager.getMatrixMeta("w1"));
        assertNotNull(matrixMetaManager.getMatrixMeta("w2"));
        // test matrix attribute
        int matrixId1 = matrixMetaManager.getMatrixId("w1");
        int matrixId2 = matrixMetaManager.getMatrixId("w2");
        String hogwildAttr = matrixMetaManager.getMatrixMeta(matrixId1).getAttribute(MatrixConf.MATRIX_HOGWILD, "true");
        assertEquals(hogwildAttr, "true");
        hogwildAttr = matrixMetaManager.getMatrixMeta(matrixId2).getAttribute(MatrixConf.MATRIX_HOGWILD, "true");
        assertEquals(hogwildAttr, "true");
        int matrix1Id = LocalClusterContext.get().getMaster().getAppMaster().getAppContext().getMatrixMetaManager().getMatrix("w1").getId();
        int matrix2Id = LocalClusterContext.get().getMaster().getAppMaster().getAppContext().getMatrixMetaManager().getMatrix("w2").getId();
        // test matrix meta
        MatrixMeta matrixMetaById = matrixMetaManager.getMatrixMeta(matrix1Id);
        MatrixMeta matrixMetaByName = matrixMetaManager.getMatrixMeta("w1");
        assertEquals(matrixMetaById, matrixMetaByName);
        assertEquals(matrixMetaById.getName(), "w1");
        assertEquals(matrixMetaById.getRowNum(), 1);
        assertEquals(matrixMetaById.getColNum(), 100000);
        assertEquals(matrixMetaById.getRowType(), RowType.T_DOUBLE_DENSE);
        assertEquals(matrixMetaById.getAttribute(MatrixConf.MATRIX_HOGWILD, "true"), "true");
        assertEquals(matrixMetaById.getStaleness(), 0);
    } catch (Exception x) {
        LOG.error("run testMatrixMetaManager failed ", x);
        throw x;
    }
}
Also used : WorkerManager(com.tencent.angel.master.worker.WorkerManager) AMTaskManager(com.tencent.angel.master.task.AMTaskManager) AngelApplicationMaster(com.tencent.angel.master.AngelApplicationMaster) PSAgentMatrixMetaManager(com.tencent.angel.psagent.matrix.PSAgentMatrixMetaManager) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) Worker(com.tencent.angel.worker.Worker) Test(org.junit.Test)

Aggregations

AngelApplicationMaster (com.tencent.angel.master.AngelApplicationMaster)9 AMTaskManager (com.tencent.angel.master.task.AMTaskManager)9 WorkerManager (com.tencent.angel.master.worker.WorkerManager)9 Worker (com.tencent.angel.worker.Worker)9 Test (org.junit.Test)9 Location (com.tencent.angel.common.location.Location)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 PSAgentMatrixMetaManager (com.tencent.angel.psagent.matrix.PSAgentMatrixMetaManager)3 ParameterServerId (com.tencent.angel.ps.ParameterServerId)2 MasterClient (com.tencent.angel.psagent.client.MasterClient)2 PSAgentLocationManager (com.tencent.angel.psagent.matrix.PSAgentLocationManager)2 TaskContext (com.tencent.angel.psagent.task.TaskContext)2 PartitionKey (com.tencent.angel.PartitionKey)1 TConnection (com.tencent.angel.ipc.TConnection)1 TVector (com.tencent.angel.ml.math.TVector)1 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)1 ClockCache (com.tencent.angel.psagent.clock.ClockCache)1 ConsistencyController (com.tencent.angel.psagent.consistency.ConsistencyController)1 Configuration (org.apache.hadoop.conf.Configuration)1