Search in sources :

Example 1 with Server

use of org.apache.hadoop.ipc.RPC.Server in project hadoop by apache.

the class RPCCallBenchmark method startServer.

private Server startServer(MyOptions opts) throws IOException {
    if (opts.serverThreads <= 0) {
        return null;
    }
    conf.setInt(CommonConfigurationKeys.IPC_SERVER_RPC_READ_THREADS_KEY, opts.serverReaderThreads);
    RPC.Server server;
    // Get RPC server for server side implementation
    if (opts.rpcEngine == ProtobufRpcEngine.class) {
        // Create server side implementation
        PBServerImpl serverImpl = new PBServerImpl();
        BlockingService service = TestProtobufRpcProto.newReflectiveBlockingService(serverImpl);
        server = new RPC.Builder(conf).setProtocol(TestRpcService.class).setInstance(service).setBindAddress(opts.host).setPort(opts.getPort()).setNumHandlers(opts.serverThreads).setVerbose(false).build();
    } else {
        throw new RuntimeException("Bad engine: " + opts.rpcEngine);
    }
    server.start();
    return server;
}
Also used : Server(org.apache.hadoop.ipc.RPC.Server) OptionBuilder(org.apache.commons.cli.OptionBuilder) BlockingService(com.google.protobuf.BlockingService)

Example 2 with Server

use of org.apache.hadoop.ipc.RPC.Server in project hadoop by apache.

the class RPCCallBenchmark method run.

@Override
public int run(String[] args) throws Exception {
    MyOptions opts = new MyOptions(args);
    if (opts.failed) {
        return -1;
    }
    // Set RPC engine to the configured RPC engine
    RPC.setProtocolEngine(conf, TestRpcService.class, opts.rpcEngine);
    Server server = startServer(opts);
    try {
        TestContext ctx = setupClientTestContext(opts);
        if (ctx != null) {
            long totalCalls = 0;
            ctx.startThreads();
            long veryStart = System.nanoTime();
            // time has elapsed
            for (int i = 0; i < opts.secondsToRun; i++) {
                long st = System.nanoTime();
                ctx.waitFor(1000);
                long et = System.nanoTime();
                long ct = callCount.getAndSet(0);
                totalCalls += ct;
                double callsPerSec = (ct * 1000000000) / (et - st);
                System.out.println("Calls per second: " + callsPerSec);
            }
            if (totalCalls > 0) {
                long veryEnd = System.nanoTime();
                double callsPerSec = (totalCalls * 1000000000) / (veryEnd - veryStart);
                long cpuNanosClient = getTotalCpuTime(ctx.getTestThreads());
                long cpuNanosServer = -1;
                if (server != null) {
                    cpuNanosServer = getTotalCpuTime(server.getHandlers());
                    ;
                }
                System.out.println("====== Results ======");
                System.out.println("Options:\n" + opts);
                System.out.println("Total calls per second: " + callsPerSec);
                System.out.println("CPU time per call on client: " + (cpuNanosClient / totalCalls) + " ns");
                if (server != null) {
                    System.out.println("CPU time per call on server: " + (cpuNanosServer / totalCalls) + " ns");
                }
            } else {
                System.out.println("No calls!");
            }
            ctx.stop();
        } else {
            while (true) {
                Thread.sleep(10000);
            }
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
    return 0;
}
Also used : Server(org.apache.hadoop.ipc.RPC.Server) TestContext(org.apache.hadoop.test.MultithreadedTestUtil.TestContext)

Example 3 with Server

use of org.apache.hadoop.ipc.RPC.Server in project apex-core by apache.

the class StramRecoveryTest method testRpcFailover.

@Test
public void testRpcFailover() throws Exception {
    String appPath = testMeta.getPath();
    Configuration conf = new Configuration(false);
    final AtomicBoolean timedout = new AtomicBoolean();
    StreamingContainerUmbilicalProtocol impl = Mockito.mock(StreamingContainerUmbilicalProtocol.class, Mockito.withSettings().extraInterfaces(Closeable.class));
    final Answer<Void> answer = new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            LOG.debug("got call: " + invocation.getMethod());
            if (!timedout.get()) {
                try {
                    timedout.set(true);
                    Thread.sleep(1000);
                } catch (Exception e) {
                // ignore
                }
            //throw new RuntimeException("fail");
            }
            return null;
        }
    };
    Mockito.doAnswer(answer).when(impl).log("containerId", "timeout");
    Mockito.doAnswer(answer).when(impl).reportError("containerId", null, "timeout", null);
    Server server = new RPC.Builder(conf).setProtocol(StreamingContainerUmbilicalProtocol.class).setInstance(impl).setBindAddress("0.0.0.0").setPort(0).setNumHandlers(1).setVerbose(false).build();
    server.start();
    InetSocketAddress address = NetUtils.getConnectAddress(server);
    LOG.info("Mock server listening at " + address);
    int rpcTimeoutMillis = 500;
    int retryDelayMillis = 100;
    int retryTimeoutMillis = 500;
    FSRecoveryHandler recoveryHandler = new FSRecoveryHandler(appPath, conf);
    URI uri = RecoverableRpcProxy.toConnectURI(address, rpcTimeoutMillis, retryDelayMillis, retryTimeoutMillis);
    recoveryHandler.writeConnectUri(uri.toString());
    RecoverableRpcProxy rp = new RecoverableRpcProxy(appPath, conf);
    StreamingContainerUmbilicalProtocol protocolProxy = rp.getProxy();
    protocolProxy.log("containerId", "msg");
    // simulate socket read timeout
    try {
        protocolProxy.log("containerId", "timeout");
        Assert.fail("expected socket timeout");
    } catch (java.net.SocketTimeoutException e) {
    // expected
    }
    Assert.assertTrue("timedout", timedout.get());
    rp.close();
    // test success on retry
    timedout.set(false);
    retryTimeoutMillis = 1500;
    uri = RecoverableRpcProxy.toConnectURI(address, rpcTimeoutMillis, retryDelayMillis, retryTimeoutMillis);
    recoveryHandler.writeConnectUri(uri.toString());
    protocolProxy.log("containerId", "timeout");
    Assert.assertTrue("timedout", timedout.get());
    rp.close();
    String rpcTimeout = System.getProperty(RecoverableRpcProxy.RPC_TIMEOUT);
    String rpcRetryDelay = System.getProperty(RecoverableRpcProxy.RETRY_DELAY);
    String rpcRetryTimeout = System.getProperty(RecoverableRpcProxy.RETRY_TIMEOUT);
    System.setProperty(RecoverableRpcProxy.RPC_TIMEOUT, Integer.toString(500));
    System.setProperty(RecoverableRpcProxy.RETRY_DELAY, Long.toString(100));
    System.setProperty(RecoverableRpcProxy.RETRY_TIMEOUT, Long.toString(500));
    timedout.set(false);
    uri = RecoverableRpcProxy.toConnectURI(address);
    recoveryHandler.writeConnectUri(uri.toString());
    rp = new RecoverableRpcProxy(appPath, conf);
    protocolProxy = rp.getProxy();
    protocolProxy.reportError("containerId", null, "msg", null);
    try {
        protocolProxy.log("containerId", "timeout");
        Assert.fail("expected socket timeout");
    } catch (java.net.SocketTimeoutException e) {
    // expected
    }
    Assert.assertTrue("timedout", timedout.get());
    rp.close();
    timedout.set(false);
    System.setProperty(RecoverableRpcProxy.RETRY_TIMEOUT, Long.toString(1500));
    uri = RecoverableRpcProxy.toConnectURI(address);
    recoveryHandler.writeConnectUri(uri.toString());
    protocolProxy.reportError("containerId", null, "timeout", null);
    Assert.assertTrue("timedout", timedout.get());
    restoreSystemProperty(RecoverableRpcProxy.RPC_TIMEOUT, rpcTimeout);
    restoreSystemProperty(RecoverableRpcProxy.RETRY_DELAY, rpcRetryDelay);
    restoreSystemProperty(RecoverableRpcProxy.RETRY_TIMEOUT, rpcRetryTimeout);
    server.stop();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.ipc.RPC.Server) RPC(org.apache.hadoop.ipc.RPC) InetSocketAddress(java.net.InetSocketAddress) Closeable(java.io.Closeable) URI(java.net.URI) IOException(java.io.IOException) Checkpoint(com.datatorrent.stram.api.Checkpoint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StreamingContainerUmbilicalProtocol(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol) Test(org.junit.Test)

Aggregations

Server (org.apache.hadoop.ipc.RPC.Server)3 Checkpoint (com.datatorrent.stram.api.Checkpoint)1 StreamingContainerUmbilicalProtocol (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol)1 BlockingService (com.google.protobuf.BlockingService)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 URI (java.net.URI)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 OptionBuilder (org.apache.commons.cli.OptionBuilder)1 Configuration (org.apache.hadoop.conf.Configuration)1 RPC (org.apache.hadoop.ipc.RPC)1 TestContext (org.apache.hadoop.test.MultithreadedTestUtil.TestContext)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1