Search in sources :

Example 11 with TestContext

use of org.apache.hadoop.test.MultithreadedTestUtil.TestContext 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)

Aggregations

TestContext (org.apache.hadoop.test.MultithreadedTestUtil.TestContext)11 Test (org.junit.Test)8 IOException (java.io.IOException)7 FileSystem (org.apache.hadoop.fs.FileSystem)4 Path (org.apache.hadoop.fs.Path)4 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)3 TestingThread (org.apache.hadoop.test.MultithreadedTestUtil.TestingThread)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Configuration (org.apache.hadoop.conf.Configuration)2 RepeatingTestThread (org.apache.hadoop.test.MultithreadedTestUtil.RepeatingTestThread)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 ParseException (org.apache.commons.cli.ParseException)1 AlwaysSucceedFencer (org.apache.hadoop.ha.TestNodeFencer.AlwaysSucceedFencer)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 MiniDFSNNTopology (org.apache.hadoop.hdfs.MiniDFSNNTopology)1 Server (org.apache.hadoop.ipc.RPC.Server)1 GenericTestUtils (org.apache.hadoop.test.GenericTestUtils)1 MultithreadedTestUtil (org.apache.hadoop.test.MultithreadedTestUtil)1