Search in sources :

Example 1 with IntroductionRequestMessage

use of org.nd4j.parameterserver.distributed.messages.requests.IntroductionRequestMessage in project nd4j by deeplearning4j.

the class RoutedTransport method launch.

@Override
public void launch(@NonNull ThreadingModel threading) {
    super.launch(threading);
    // send introductory message
    // if (nodeRole == NodeRole.CLIENT) {
    // shards.parallelStream().forEach((rc) -> {
    IntroductionRequestMessage irm = new IntroductionRequestMessage(getIp(), getPort());
    irm.setTargetId((short) -1);
    sendCoordinationCommand(irm);
// });
// }
}
Also used : IntroductionRequestMessage(org.nd4j.parameterserver.distributed.messages.requests.IntroductionRequestMessage)

Example 2 with IntroductionRequestMessage

use of org.nd4j.parameterserver.distributed.messages.requests.IntroductionRequestMessage in project nd4j by deeplearning4j.

the class RoutedTransportTest method testMessaging1.

/**
 * This test
 *
 * @throws Exception
 */
@Test
public void testMessaging1() throws Exception {
    List<String> list = new ArrayList<>();
    for (int t = 0; t < 5; t++) {
        list.add("127.0.0.1:3838" + t);
    }
    VoidConfiguration voidConfiguration = // this port will be used only by client
    VoidConfiguration.builder().shardAddresses(list).unicastPort(43120).build();
    // first of all we start shards
    RoutedTransport[] transports = new RoutedTransport[list.size()];
    for (int t = 0; t < transports.length; t++) {
        Clipboard clipboard = new Clipboard();
        transports[t] = new RoutedTransport();
        transports[t].setIpAndPort("127.0.0.1", Integer.valueOf("3838" + t));
        transports[t].init(voidConfiguration, clipboard, NodeRole.SHARD, "127.0.0.1", voidConfiguration.getUnicastPort(), (short) t);
    }
    for (int t = 0; t < transports.length; t++) {
        transports[t].launch(Transport.ThreadingModel.DEDICATED_THREADS);
    }
    // now we start client, for this test we'll have only one client
    Clipboard clipboard = new Clipboard();
    RoutedTransport clientTransport = new RoutedTransport();
    clientTransport.setIpAndPort("127.0.0.1", voidConfiguration.getUnicastPort());
    // setRouter call should be called before init, and we need
    ClientRouter router = new InterleavedRouter(0);
    clientTransport.setRouter(router);
    router.init(voidConfiguration, clientTransport);
    clientTransport.init(voidConfiguration, clipboard, NodeRole.CLIENT, "127.0.0.1", voidConfiguration.getUnicastPort(), (short) -1);
    clientTransport.launch(Transport.ThreadingModel.DEDICATED_THREADS);
    // we send message somewhere
    VoidMessage message = new IntroductionRequestMessage("127.0.0.1", voidConfiguration.getUnicastPort());
    clientTransport.sendMessage(message);
    Thread.sleep(500);
    message = transports[0].messages.poll(1, TimeUnit.SECONDS);
    assertNotEquals(null, message);
    for (int t = 1; t < transports.length; t++) {
        message = transports[t].messages.poll(1, TimeUnit.SECONDS);
        assertEquals(null, message);
    }
    /**
     * This is very important part, shutting down all transports
     */
    for (RoutedTransport transport : transports) {
        transport.shutdown();
    }
    clientTransport.shutdown();
}
Also used : VoidConfiguration(org.nd4j.parameterserver.distributed.conf.VoidConfiguration) VoidMessage(org.nd4j.parameterserver.distributed.messages.VoidMessage) InterleavedRouter(org.nd4j.parameterserver.distributed.logic.routing.InterleavedRouter) ArrayList(java.util.ArrayList) ClientRouter(org.nd4j.parameterserver.distributed.logic.ClientRouter) IntroductionRequestMessage(org.nd4j.parameterserver.distributed.messages.requests.IntroductionRequestMessage) Clipboard(org.nd4j.parameterserver.distributed.logic.completion.Clipboard) Test(org.junit.Test)

Aggregations

IntroductionRequestMessage (org.nd4j.parameterserver.distributed.messages.requests.IntroductionRequestMessage)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 VoidConfiguration (org.nd4j.parameterserver.distributed.conf.VoidConfiguration)1 ClientRouter (org.nd4j.parameterserver.distributed.logic.ClientRouter)1 Clipboard (org.nd4j.parameterserver.distributed.logic.completion.Clipboard)1 InterleavedRouter (org.nd4j.parameterserver.distributed.logic.routing.InterleavedRouter)1 VoidMessage (org.nd4j.parameterserver.distributed.messages.VoidMessage)1