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