Search in sources :

Example 1 with PerfTimer

use of org.webpieces.nio.test.PerfTimer in project webpieces by deanhiller.

the class ZPerformanceSuper method testVerySmallReadWrite.

/**
	 * This is the difference in performance of writing/reading secure data vs.
	 * writing/reading non-secure data for a VERY SMALL payload.  Realize though,
	 * in this test, the data is encrypted, decrypted, encrypted again, and 
	 * decrypted again, so the server takes half this load, and the client the
	 * other half.  
	 * Basic seems to be 75% of secure's time. This is a slowdown of 133% 
	 * for echoing 'hello'.
	 * 
     * Basic....
     * total write time         =1732 ms
     * total write/response time=1802 ms
     * time per write/response  =45   ms
     * Secure....
     * total write time         =2374 ms
     * total write/response time=2424 ms
     * time per write/response  =60   ms
     * Basic with network delay of 1 seconds....
     * total write time         =1522 ms
     * total write/response time=3585 ms
     * time per write/response  =89   ms
	 * @throws Exception
	 */
public void testVerySmallReadWrite() throws Exception {
    ByteBuffer b = ByteBuffer.allocate(4000);
    log.info("getting all proper connections");
    int size = 40;
    String[] methodNames = new String[size];
    for (int i = 0; i < size; i++) {
        methodNames[i] = "finished";
    }
    TCPChannel[] clients = new TCPChannel[size];
    for (int i = 0; i < size; i++) {
        clients[i] = chanMgr.createTCPChannel("Client[" + i + "]", getClientFactoryHolder());
        FutureOperation future = clients[i].connect(svrAddr);
        future.setListener((OperationCallback) mockConnectOp);
    }
    mockConnectOp.expect(methodNames);
    log.info("done getting all connections");
    for (TCPChannel client : clients) {
        client.registerForReads((DataListener) mockHandler);
    }
    int numWrites = 200;
    String payload = "hello";
    helper.putString(b, payload);
    helper.doneFillingBuffer(b);
    int numBytes = b.remaining();
    methodNames = new String[size];
    for (int i = 0; i < size; i++) {
        methodNames[i] = "incomingData";
    }
    String[] finNames = new String[size];
    for (int i = 0; i < size; i++) {
        finNames[i] = "finished";
    }
    PerfTimer timer = new PerfTimer();
    PerfTimer timer2 = new PerfTimer();
    timer.start();
    timer2.start();
    CalledMethod[] methods = null;
    for (int i = 0; i < numWrites; i++) {
        for (TCPChannel client : clients) {
            FutureOperation write = client.write(b);
            write.setListener((OperationCallback) mockConnectOp);
            //client.oldWrite(b);
            b.rewind();
        }
        mockConnectOp.expect(finNames);
        methods = mockHandler.expect(methodNames);
    }
    long result2 = timer2.stop();
    long result = timer.stop();
    //pick a method and verify right data came back for performance test
    //to make sure performance test is valid....
    ByteBuffer actualBuf = (ByteBuffer) methods[5].getAllParams()[1];
    String actual = helper.readString(actualBuf, actualBuf.remaining());
    assertEquals(payload, actual);
    log.info("payload=" + actual);
    long readWriteTime = result / size;
    long byteTime = 100 * result / (numWrites * numBytes);
    log.info("total write time         =" + result2);
    log.info("total write/read time    =" + result);
    log.info("--time per 100 bytes     =" + byteTime);
    log.info("test result info:");
    log.info("--time per write/read    =" + readWriteTime);
    log.info("  time to beat           =" + getSmallReadWriteTimeLimit());
    assertTrue(readWriteTime < getSmallReadWriteTimeLimit());
}
Also used : PerfTimer(org.webpieces.nio.test.PerfTimer) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) ByteBuffer(java.nio.ByteBuffer) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) FutureOperation(org.webpieces.nio.api.handlers.FutureOperation) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 2 with PerfTimer

use of org.webpieces.nio.test.PerfTimer in project webpieces by deanhiller.

the class ZPerformanceSuper method testBasicConnect.

/**
	 * Testing difference between secureChanMgr with Basic, and just Basic
	 * and whatever other combinations are in PerfTestZ<Subclassname>.  Here
	 * we are testing the performance of connect method.  As you can see the
	 * establishing of a link is very expensive. 57 times difference!
	 * 
	 * Basic ChannelMgr....
	 * time for initiating all connects           = 180 ms
	 * time for initiating/finishing all connects = 180 ms
	 * time per connection                        = 4 ms
	 * 
	 * Secure ChannelMgr....
	 * time for initiating all connects           = 8,072 ms
	 * time for initiating/finishing all connects = 9,174 ms
	 * time per connection                        = 229 ms
	 * 
	 * 
	 * If you want to test difference between asynch connect and connect, you
	 * need to simulate a network delay in EchoServer class.  
	 * I did this and simulated one second.
	 * Then changing the connect from synchronous to asynchronous results in going
	 * from 7.401 seconds to .531 seconds.  ie. the thread calling connect is free
	 * to go do more work while in the process of connecting to a server or
	 * client for that matter.
	 */
public void testBasicConnect() throws Exception {
    int size = 40;
    String[] methodNames = new String[size];
    for (int i = 0; i < size; i++) {
        methodNames[i] = "finished";
    }
    TCPChannel[] clients = new TCPChannel[size];
    for (int i = 0; i < size; i++) {
        clients[i] = chanMgr.createTCPChannel("Client[" + i + "]", getClientFactoryHolder());
    }
    PerfTimer timer = new PerfTimer();
    PerfTimer timer2 = new PerfTimer();
    log.info("Starting test connecting to=" + svrAddr);
    timer.start();
    timer2.start();
    for (int i = 0; i < size; i++) {
        FutureOperation future = clients[i].connect(svrAddr);
        future.setListener((OperationCallback) mockConnectOp);
    }
    long result2 = timer2.stop();
    mockConnectOp.expect(methodNames);
    long result = timer.stop();
    long timePerConnect = result / size;
    log.info("time for initiating connects          =" + result2);
    log.info("time for initiating/finishing connects=" + result);
    log.info("connected per connection time         =" + timePerConnect);
    log.info("--time to beat           =" + getBasicConnectTimeLimit());
    assertTrue(timePerConnect < getBasicConnectTimeLimit());
}
Also used : PerfTimer(org.webpieces.nio.test.PerfTimer) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) FutureOperation(org.webpieces.nio.api.handlers.FutureOperation)

Example 3 with PerfTimer

use of org.webpieces.nio.test.PerfTimer in project webpieces by deanhiller.

the class ZPerformanceSuper method testLargeReadWrite.

/**
	 * This is the difference in performance of writing/reading secure data vs.
	 * writing/reading non-secure data for a very small payload.  
	 * Basic seems to be 75% of secure's time. This is a slowdown of 133% 
	 * for echoing 'hello'.
	 * 
     * Basic....
     * total write time         = 1402 ms
     * total write/response time= 1433 ms
     * time per write/response  = 35   ms

     * Secure....
     * total write time         = 6119 ms
     * total write/response time= 6159 ms
     * time per write/response  = 153 ms
     *
	 * @throws Exception
	 */
public void testLargeReadWrite() throws Exception {
    ByteBuffer b = ByteBuffer.allocate(4000);
    log.info("getting all proper connections");
    int size = 40;
    String[] methodNames = new String[size];
    for (int i = 0; i < size; i++) {
        methodNames[i] = "connected";
    }
    TCPChannel[] clients = new TCPChannel[size];
    for (int i = 0; i < size; i++) {
        clients[i] = chanMgr.createTCPChannel("Client[" + i + "]", getClientFactoryHolder());
        clients[i].oldConnect(svrAddr, (ConnectionCallback) mockConnect);
    }
    mockConnect.expect(methodNames);
    log.info("done getting all connections");
    for (TCPChannel client : clients) {
        client.registerForReads((DataListener) mockHandler);
    }
    int numWrites = 100;
    String payload = "hello";
    for (int i = 0; i < 3000; i++) {
        payload += "i";
    }
    helper.putString(b, payload);
    helper.doneFillingBuffer(b);
    int numBytes = b.remaining();
    log.info("size=" + b.remaining());
    methodNames = new String[size * numWrites];
    for (int i = 0; i < size * numWrites; i++) {
        methodNames[i] = "incomingData";
    }
    PerfTimer timer = new PerfTimer();
    PerfTimer timer2 = new PerfTimer();
    timer.start();
    timer2.start();
    for (TCPChannel client : clients) {
        for (int i = 0; i < numWrites; i++) {
            FutureOperation future = client.write(b);
            future.waitForOperation(5000);
            b.rewind();
        }
    }
    long result2 = timer2.stop();
    CalledMethod[] methods = mockHandler.expect(methodNames);
    long result = timer.stop();
    ByteBuffer actualBuf = (ByteBuffer) methods[6].getAllParams()[1];
    String actual = helper.readString(actualBuf, actualBuf.remaining());
    assertEquals(payload, actual);
    log.info("payload=" + actual);
    long readWriteTime = result / size;
    long byteTime = 100 * result / (numWrites * numBytes);
    log.info("total write time         =" + result2);
    log.info("total write/read time    =" + result);
    log.info("--time per 100 bytes     =" + byteTime);
    log.info("test result info:");
    log.info("--time per write/read    =" + readWriteTime);
    log.info("--time to beat           =" + getLargerReadWriteTimeLimit());
    assertTrue(readWriteTime < getLargerReadWriteTimeLimit());
}
Also used : PerfTimer(org.webpieces.nio.test.PerfTimer) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) ByteBuffer(java.nio.ByteBuffer) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) FutureOperation(org.webpieces.nio.api.handlers.FutureOperation) CalledMethod(biz.xsoftware.mock.CalledMethod)

Aggregations

TCPChannel (org.webpieces.nio.api.channels.TCPChannel)3 FutureOperation (org.webpieces.nio.api.handlers.FutureOperation)3 PerfTimer (org.webpieces.nio.test.PerfTimer)3 CalledMethod (biz.xsoftware.mock.CalledMethod)2 ByteBuffer (java.nio.ByteBuffer)2 CloneByteBuffer (org.webpieces.nio.api.testutil.CloneByteBuffer)2