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