/// <summary>Create a client proxy for the specified engine.</summary> /// <exception cref="System.IO.IOException"/> private RPCCallBenchmark.RpcServiceWrapper CreateRpcClient(RPCCallBenchmark.MyOptions opts) { IPEndPoint addr = NetUtils.CreateSocketAddr(opts.host, opts.GetPort()); if (opts.rpcEngine == typeof(ProtobufRpcEngine)) { TestProtoBufRpc.TestRpcService proxy = RPC.GetProxy <TestProtoBufRpc.TestRpcService >(0, addr, conf); return(new _RpcServiceWrapper_394(proxy)); } else { if (opts.rpcEngine == typeof(WritableRpcEngine)) { TestRPC.TestProtocol proxy = RPC.GetProxy <TestRPC.TestProtocol>(TestRPC.TestProtocol .versionID, addr, conf); return(new _RpcServiceWrapper_407(proxy)); } else { throw new RuntimeException("unsupported engine: " + opts.rpcEngine); } } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> private MultithreadedTestUtil.TestContext SetupClientTestContext(RPCCallBenchmark.MyOptions opts) { if (opts.clientThreads <= 0) { return(null); } // Set up a separate proxy for each client thread, // rather than making them share TCP pipes. int numProxies = opts.clientThreads; RPCCallBenchmark.RpcServiceWrapper[] proxies = new RPCCallBenchmark.RpcServiceWrapper [numProxies]; for (int i = 0; i < numProxies; i++) { proxies[i] = UserGroupInformation.CreateUserForTesting("proxy-" + i, new string[] { }).DoAs(new _PrivilegedExceptionAction_347(this, opts)); } // Create an echo message of the desired length StringBuilder msgBuilder = new StringBuilder(opts.msgSize); for (int c = 0; c < opts.msgSize; c++) { msgBuilder.Append('x'); } string echoMessage = msgBuilder.ToString(); // Create the clients in a test context MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(); for (int i_1 = 0; i_1 < opts.clientThreads; i_1++) { RPCCallBenchmark.RpcServiceWrapper proxy = proxies[i_1 % numProxies]; ctx.AddThread(new _RepeatingTestThread_367(this, proxy, echoMessage, ctx)); } return(ctx); }
/// <exception cref="System.IO.IOException"/> private RPC.Server StartServer(RPCCallBenchmark.MyOptions opts) { if (opts.serverThreads <= 0) { return(null); } conf.SetInt(CommonConfigurationKeys.IpcServerRpcReadThreadsKey, opts.serverReaderThreads ); RPC.Server server; // Get RPC server for server side implementation if (opts.rpcEngine == typeof(ProtobufRpcEngine)) { // Create server side implementation TestProtoBufRpc.PBServerImpl serverImpl = new TestProtoBufRpc.PBServerImpl(); BlockingService service = TestRpcServiceProtos.TestProtobufRpcProto.NewReflectiveBlockingService (serverImpl); server = new RPC.Builder(conf).SetProtocol(typeof(TestProtoBufRpc.TestRpcService) ).SetInstance(service).SetBindAddress(opts.host).SetPort(opts.GetPort()).SetNumHandlers (opts.serverThreads).SetVerbose(false).Build(); } else { if (opts.rpcEngine == typeof(WritableRpcEngine)) { server = new RPC.Builder(conf).SetProtocol(typeof(TestRPC.TestProtocol)).SetInstance (new TestRPC.TestImpl()).SetBindAddress(opts.host).SetPort(opts.GetPort()).SetNumHandlers (opts.serverThreads).SetVerbose(false).Build(); } else { throw new RuntimeException("Bad engine: " + opts.rpcEngine); } } server.Start(); return(server); }
public _PrivilegedExceptionAction_347(RPCCallBenchmark _enclosing, RPCCallBenchmark.MyOptions opts) { this._enclosing = _enclosing; this.opts = opts; }
/// <exception cref="System.Exception"/> public virtual int Run(string[] args) { RPCCallBenchmark.MyOptions opts = new RPCCallBenchmark.MyOptions(args); if (opts.failed) { return(-1); } // Set RPC engine to the configured RPC engine RPC.SetProtocolEngine(conf, typeof(TestProtoBufRpc.TestRpcService), opts.rpcEngine ); RPC.Server server = StartServer(opts); try { MultithreadedTestUtil.TestContext ctx = SetupClientTestContext(opts); if (ctx != null) { long totalCalls = 0; ctx.StartThreads(); long veryStart = Runtime.NanoTime(); // Loop printing results every second until the specified // time has elapsed for (int i = 0; i < opts.secondsToRun; i++) { long st = Runtime.NanoTime(); ctx.WaitFor(1000); long et = Runtime.NanoTime(); long ct = callCount.GetAndSet(0); totalCalls += ct; double callsPerSec = (ct * 1000000000) / (et - st); System.Console.Out.WriteLine("Calls per second: " + callsPerSec); } // Print results if (totalCalls > 0) { long veryEnd = Runtime.NanoTime(); double callsPerSec = (totalCalls * 1000000000) / (veryEnd - veryStart); long cpuNanosClient = GetTotalCpuTime(ctx.GetTestThreads()); long cpuNanosServer = -1; if (server != null) { cpuNanosServer = GetTotalCpuTime(server.GetHandlers()); } System.Console.Out.WriteLine("====== Results ======"); System.Console.Out.WriteLine("Options:\n" + opts); System.Console.Out.WriteLine("Total calls per second: " + callsPerSec); System.Console.Out.WriteLine("CPU time per call on client: " + (cpuNanosClient / totalCalls) + " ns"); if (server != null) { System.Console.Out.WriteLine("CPU time per call on server: " + (cpuNanosServer / totalCalls) + " ns"); } } else { System.Console.Out.WriteLine("No calls!"); } ctx.Stop(); } else { while (true) { Thread.Sleep(10000); } } } finally { if (server != null) { server.Stop(); } } return(0); }