Search in sources :

Example 1 with BackpressureConfig

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;
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) BufferPool(org.webpieces.data.api.BufferPool) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) SSLEngine(javax.net.ssl.SSLEngine) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DirectExecutor(org.webpieces.util.threading.DirectExecutor) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Example 2 with BackpressureConfig

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;
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) Http2Client(org.webpieces.http2client.api.Http2Client) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 3 with BackpressureConfig

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;
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) Http2Socket(org.webpieces.http2client.api.Http2Socket) Http2Client(org.webpieces.http2client.api.Http2Client)

Example 4 with BackpressureConfig

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);
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig)

Example 5 with BackpressureConfig

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);
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) InetSocketAddress(java.net.InetSocketAddress) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) TimerTask(java.util.TimerTask)

Aggregations

BackpressureConfig (org.webpieces.nio.api.BackpressureConfig)10 ChannelManager (org.webpieces.nio.api.ChannelManager)8 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 TwoPools (org.webpieces.data.api.TwoPools)7 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)7 BufferPool (org.webpieces.data.api.BufferPool)6 Executor (java.util.concurrent.Executor)5 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)5 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)4 InetSocketAddress (java.net.InetSocketAddress)3 SSLEngine (javax.net.ssl.SSLEngine)3 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)3 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)3 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)3 Http2Client (org.webpieces.http2client.api.Http2Client)3 HpackParser (com.webpieces.hpack.api.HpackParser)2 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)2 Http2Socket (org.webpieces.http2client.api.Http2Socket)2 Provides (com.google.inject.Provides)1 TimerTask (java.util.TimerTask)1