use of org.webpieces.nio.api.BackpressureConfig in project webpieces by deanhiller.
the class TestSslCloseClient method createClientChannel.
public static TCPChannel createClientChannel(String name, MockJdk mockJdk) throws GeneralSecurityException, IOException {
ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, Metrics.globalRegistry);
BufferPool pool = new TwoPools("pClient", new SimpleMeterRegistry());
ChannelManager chanMgr = factory.createMultiThreadedChanMgr(name + "Mgr", pool, new BackpressureConfig(), new DirectExecutor());
MockSSLEngineFactory sslFactory = new MockSSLEngineFactory();
SSLEngine clientSsl = sslFactory.createEngineForSocket();
TCPChannel channel1 = chanMgr.createTCPChannel("client", clientSsl);
return channel1;
}
use of org.webpieces.nio.api.BackpressureConfig in project webpieces by deanhiller.
the class GuiceModule method createClient.
@Provides
@Singleton
public Http2Client createClient(MeterRegistry metrics) {
BackpressureConfig config = new BackpressureConfig();
// clients should NOT have backpressure or it could screw the server over when the server does not support backpresssure
config.setMaxBytes(null);
// This is an http1_1 client masquerading as an http2 client so we can switch to http2 faster when ready!!
Http2Client httpClient = Http2to11ClientFactory.createHttpClient("httpclient", 10, config, metrics);
return httpClient;
}
use of org.webpieces.nio.api.BackpressureConfig in project webpieces by deanhiller.
the class IntegSingleRequest method createHttpClient.
public static Http2Socket createHttpClient(String id, boolean isHttp, InetSocketAddress addr) {
BufferPool pool2 = new TwoPools("pl", new SimpleMeterRegistry());
HpackParser hpackParser = HpackParserFactory.createParser(pool2, false);
Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
ChannelManagerFactory factory = ChannelManagerFactory.createFactory(Metrics.globalRegistry);
ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, new BackpressureConfig(), executor2);
InjectionConfig injConfig = new InjectionConfig(hpackParser);
String host = addr.getHostName();
int port = addr.getPort();
ForTestSslClientEngineFactory ssl = new ForTestSslClientEngineFactory();
SSLEngine engine = ssl.createSslEngine(host, port);
Http2Client client = Http2ClientFactory.createHttpClient("myClient", mgr, injConfig);
Http2Socket socket;
if (isHttp) {
socket = client.createHttpSocket(new Http2CloseListener());
} else {
socket = client.createHttpsSocket(engine, new Http2CloseListener());
}
return socket;
}
use of org.webpieces.nio.api.BackpressureConfig in project webpieces by deanhiller.
the class SingleSocketThroughput method main.
public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException {
// All of these are variables that can impact performance so we surface them here to play with
BackpressureConfig backpressureConfig = new BackpressureConfig();
// num unacked bytes (client did not ack yet) before we backpressure
backpressureConfig.setMaxBytes(8_192 * 8);
// once backpressure is on, instead of flapping, we wait for client to catch up quite a bit(may increase performance in certain use cases)
// or at the very least create more fairness if one client is giving more requests than another
backpressureConfig.setStartReadingThreshold(8_192 * 2);
AsyncConfig config = new AsyncConfig();
// turns off mulithreaded but useless for this test!!! since there is only one socket
config.setClientThreadCount(null);
// turns off mulithreaded but useless for this test!!! since there is only one socket
config.setServerThreadCount(null);
config.setHttps(false);
config.setBackPressureConfig(backpressureConfig);
// this setting only applies to http2 server/client pair...
config.setHttp2ClientMaxConcurrentRequests(200);
config.setNumSockets(1);
ThroughputEngine example = new ThroughputEngine(config, Metrics.globalRegistry);
// BIG NOTE: It is not fair to set multiThreaded=true BECAUSE in that case you would need
// many many sockets because the threadpool causes context switching BUT keeps the one socket
// virtually single threaded(this is a BIG pretty awesome feature actually). The REASON it keeps
// it virtually single threaded is so that SSL handshaking, http2 parsing, http1.1 parsing can
// all be delayed until the thread pool. BUT we leave the switch here so we can play with it
// AND we need to code up another rps example for many many sockets
// yes, 8 combinations that can be tried (as we wanted to compare old IO while we were doing this)
// example.start(Mode.ASYNCHRONOUS, Mode.ASYNCHRONOUS, Protocol.HTTP11);
// example.start(Mode.SYNCHRONOUS, Mode.SYNCHRONOUS, Protocol.HTTP11);
// example.start(Mode.SYNCHRONOUS, Mode.ASYNCHRONOUS, Protocol.HTTP11);
// example.start(Mode.ASYNCHRONOUS, Mode.SYNCHRONOUS, Protocol.HTTP11);
//
example.start(Mode.ASYNCHRONOUS, Mode.ASYNCHRONOUS, Protocol.HTTP2);
// NOTE: Synchronous is HARD to implement and must use the http2 engine to do it properly.
// This is an exercise for later.....
// example.start(Mode.SYNCHRONOUS, Mode.SYNCHRONOUS, Protocol.HTTP2);
// example.start(Mode.SYNCHRONOUS, Mode.ASYNCHRONOUS, Protocol.HTTP2);
// example.start(Mode.SYNCHRONOUS, Mode.ASYNCHRONOUS, Protocol.HTTP2);
}
use of org.webpieces.nio.api.BackpressureConfig in project webpieces by deanhiller.
the class IntegTestClientNotRead method testSoTimeoutOnSocket.
public void testSoTimeoutOnSocket() throws InterruptedException {
TwoPools pool = new TwoPools("pl", new SimpleMeterRegistry());
AsyncServerManager serverMgr = AsyncServerMgrFactory.createAsyncServer("server", pool, new BackpressureConfig(), Metrics.globalRegistry);
AsyncServer server = serverMgr.createTcpServer(new AsyncConfig("tcpServer"), new IntegTestClientNotReadListener());
server.start(new InetSocketAddress(8080));
TwoPools pool2 = new TwoPools("pl", new SimpleMeterRegistry());
ChannelManagerFactory factory = ChannelManagerFactory.createFactory(Metrics.globalRegistry);
ChannelManager mgr = factory.createSingleThreadedChanMgr("client", pool2, new BackpressureConfig());
TCPChannel channel = mgr.createTCPChannel("clientChan");
log.info("client");
timer.schedule(new TimerTask() {
@Override
public void run() {
logBytesTxfrd();
}
}, 1000, 5000);
XFuture<Void> connect = channel.connect(new InetSocketAddress(8080), new ClientDataListener());
connect.thenAccept(p -> runWriting(channel));
Thread.sleep(1000000000);
}
Aggregations