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();
}
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);
}
Aggregations