Search in sources :

Example 6 with WorkerService

use of com.baidu.hugegraph.computer.core.worker.WorkerService in project hugegraph-computer by hugegraph.

the class SenderIntegrateTest method testMultiWorkers.

@Test
public void testMultiWorkers() throws InterruptedException {
    int workerCount = 3;
    int partitionCount = 3;
    Thread masterThread = new Thread(() -> {
        String[] args = OptionsBuilder.newInstance().withJobId("local_003").withAlgorithm(PageRankParams.class).withResultName("rank").withResultClass(DoubleValue.class).withMessageClass(DoubleValue.class).withMaxSuperStep(3).withComputationClass(COMPUTATION).withWorkerCount(workerCount).withPartitionCount(partitionCount).withRpcServerHost("127.0.0.1").withRpcServerPort(8090).build();
        try {
            MasterService service = initMaster(args);
            service.execute();
            service.close();
        } catch (Exception e) {
            Assert.fail(e.getMessage());
        }
    });
    List<Thread> workers = new ArrayList<>(workerCount);
    for (int i = 1; i <= workerCount; i++) {
        int port = 8090 + i;
        String dir = "[jobs-" + i + "]";
        workers.add(new Thread(() -> {
            String[] args;
            args = OptionsBuilder.newInstance().withJobId("local_003").withAlgorithm(PageRankParams.class).withResultName("rank").withResultClass(DoubleValue.class).withMessageClass(DoubleValue.class).withMaxSuperStep(3).withComputationClass(COMPUTATION).withWorkerCount(workerCount).withPartitionCount(partitionCount).withTransoprtServerPort(port).withRpcServerRemote("127.0.0.1:8090").withDataDirs(dir).build();
            try {
                WorkerService service = initWorker(args);
                service.execute();
                service.close();
            } catch (Exception e) {
                Assert.fail(e.getMessage());
            }
        }));
    }
    masterThread.start();
    for (Thread worker : workers) {
        worker.start();
    }
    for (Thread worker : workers) {
        worker.join();
    }
    masterThread.join();
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) ArrayList(java.util.ArrayList) PageRankParams(com.baidu.hugegraph.computer.algorithm.centrality.pagerank.PageRankParams) MasterService(com.baidu.hugegraph.computer.core.master.MasterService) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException) WorkerService(com.baidu.hugegraph.computer.core.worker.WorkerService) Test(org.junit.Test)

Example 7 with WorkerService

use of com.baidu.hugegraph.computer.core.worker.WorkerService in project hugegraph-computer by hugegraph.

the class SenderIntegrateTest method slowSendFunc.

private void slowSendFunc(WorkerService service) throws TransportException {
    Managers managers = Whitebox.getInternalState(service, "managers");
    DataClientManager clientManager = managers.get(DataClientManager.NAME);
    ConnectionManager connManager = Whitebox.getInternalState(clientManager, "connManager");
    NettyTransportClient client = (NettyTransportClient) connManager.getOrCreateClient("127.0.0.1", 8091);
    ClientSession clientSession = Whitebox.invoke(client.getClass(), "clientSession", client);
    Function<Message, Future<Void>> sendFuncBak = Whitebox.getInternalState(clientSession, "sendFunction");
    Function<Message, Future<Void>> sendFunc = message -> {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return sendFuncBak.apply(message);
    };
    Whitebox.setInternalState(clientSession, "sendFunction", sendFunc);
}
Also used : PageRankParams(com.baidu.hugegraph.computer.algorithm.centrality.pagerank.PageRankParams) ComputerOptions(com.baidu.hugegraph.computer.core.config.ComputerOptions) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BeforeClass(org.junit.BeforeClass) Managers(com.baidu.hugegraph.computer.core.manager.Managers) RpcOptions(com.baidu.hugegraph.config.RpcOptions) Function(java.util.function.Function) MasterService(com.baidu.hugegraph.computer.core.master.MasterService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Whitebox(com.baidu.hugegraph.testutil.Whitebox) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException) ComputerContextUtil(com.baidu.hugegraph.computer.core.util.ComputerContextUtil) Message(com.baidu.hugegraph.computer.core.network.message.Message) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) ConnectionManager(com.baidu.hugegraph.computer.core.network.connection.ConnectionManager) Test(org.junit.Test) NettyTransportClient(com.baidu.hugegraph.computer.core.network.netty.NettyTransportClient) ClientSession(com.baidu.hugegraph.computer.core.network.session.ClientSession) Config(com.baidu.hugegraph.computer.core.config.Config) DataClientManager(com.baidu.hugegraph.computer.core.network.DataClientManager) List(java.util.List) Log(com.baidu.hugegraph.util.Log) WorkerService(com.baidu.hugegraph.computer.core.worker.WorkerService) Assert(com.baidu.hugegraph.testutil.Assert) ConnectionManager(com.baidu.hugegraph.computer.core.network.connection.ConnectionManager) Message(com.baidu.hugegraph.computer.core.network.message.Message) Managers(com.baidu.hugegraph.computer.core.manager.Managers) DataClientManager(com.baidu.hugegraph.computer.core.network.DataClientManager) NettyTransportClient(com.baidu.hugegraph.computer.core.network.netty.NettyTransportClient) ClientSession(com.baidu.hugegraph.computer.core.network.session.ClientSession) Future(java.util.concurrent.Future)

Aggregations

WorkerService (com.baidu.hugegraph.computer.core.worker.WorkerService)7 MasterService (com.baidu.hugegraph.computer.core.master.MasterService)5 PageRankParams (com.baidu.hugegraph.computer.algorithm.centrality.pagerank.PageRankParams)4 TransportException (com.baidu.hugegraph.computer.core.common.exception.TransportException)4 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)4 Test (org.junit.Test)4 Config (com.baidu.hugegraph.computer.core.config.Config)3 ArrayList (java.util.ArrayList)2 Logger (org.slf4j.Logger)2 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)1 Managers (com.baidu.hugegraph.computer.core.manager.Managers)1 DataClientManager (com.baidu.hugegraph.computer.core.network.DataClientManager)1 ConnectionManager (com.baidu.hugegraph.computer.core.network.connection.ConnectionManager)1 Message (com.baidu.hugegraph.computer.core.network.message.Message)1 NettyTransportClient (com.baidu.hugegraph.computer.core.network.netty.NettyTransportClient)1 ClientSession (com.baidu.hugegraph.computer.core.network.session.ClientSession)1 ComputerContextUtil (com.baidu.hugegraph.computer.core.util.ComputerContextUtil)1 MockWorkerService (com.baidu.hugegraph.computer.core.worker.MockWorkerService)1 RpcOptions (com.baidu.hugegraph.config.RpcOptions)1 Assert (com.baidu.hugegraph.testutil.Assert)1