Search in sources :

Example 6 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class IntegTestClientToEchoServer method createClientChannel.

private TCPChannel createClientChannel(BufferPool pool2, Executor executor) {
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, executor);
    TCPChannel channel = mgr.createTCPChannel("clientChan");
    return channel;
}
Also used : ChannelManager(org.webpieces.nio.api.ChannelManager) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Example 7 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class IntegTestClientToEchoServer method testSoTimeoutOnSocket.

public void testSoTimeoutOnSocket() throws InterruptedException {
    runEchoServer();
    BufferPool pool2 = new BufferCreationPool();
    DataListener listener = new ClientDataListener(pool2, recorder);
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    TCPChannel channel = createClientChannel(pool2, executor2);
    //TCPChannel channel = createNettyChannel();
    recorder.start();
    CompletableFuture<Channel> connect = channel.connect(new InetSocketAddress(4444), listener);
    connect.thenAccept(p -> runWriting(channel));
    synchronized (this) {
        this.wait();
    }
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) InetSocketAddress(java.net.InetSocketAddress) Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) DataListener(org.webpieces.nio.api.handlers.DataListener) BufferCreationPool(org.webpieces.data.api.BufferCreationPool)

Example 8 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class ZNioFailureSuperclass method expectServerChannel.

static TCPChannel expectServerChannel(MockNIOServer mockServer, Class c) {
    CalledMethod method = mockServer.expect(MockNIOServer.CONNECTED);
    TCPChannel svrChan = (TCPChannel) method.getAllParams()[0];
    assertEquals("should be instance of correct channel type", c, svrChan.getClass());
    return svrChan;
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 9 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel 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 10 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel 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)

Aggregations

TCPChannel (org.webpieces.nio.api.channels.TCPChannel)39 InetSocketAddress (java.net.InetSocketAddress)12 ByteBuffer (java.nio.ByteBuffer)10 CalledMethod (biz.xsoftware.mock.CalledMethod)8 CloneByteBuffer (org.webpieces.nio.api.testutil.CloneByteBuffer)6 ChannelManager (org.webpieces.nio.api.ChannelManager)5 Channel (org.webpieces.nio.api.channels.Channel)5 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)4 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)4 FutureOperation (org.webpieces.nio.api.handlers.FutureOperation)4 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)3 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)3 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)3 BufferPool (org.webpieces.data.api.BufferPool)3 PerfTimer (org.webpieces.nio.test.PerfTimer)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 Executor (java.util.concurrent.Executor)2 Test (org.junit.Test)2 TCPServerChannel (org.webpieces.nio.api.channels.TCPServerChannel)2