Search in sources :

Example 1 with LeakTrackingByteBufferPool

use of org.eclipse.jetty.io.LeakTrackingByteBufferPool in project jetty.project by eclipse.

the class AbstractHttpClientServerTest method start.

public void start(Handler handler) throws Exception {
    server = new Server();
    ServerFCGIConnectionFactory fcgiConnectionFactory = new ServerFCGIConnectionFactory(new HttpConfiguration());
    serverBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
    connector = new ServerConnector(server, null, null, serverBufferPool, 1, Math.max(1, Runtime.getRuntime().availableProcessors() / 2), fcgiConnectionFactory);
    //        connector.setPort(9000);
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();
    QueuedThreadPool executor = new QueuedThreadPool();
    executor.setName(executor.getName() + "-client");
    client = new HttpClient(new HttpClientTransportOverFCGI(1, false, "") {

        @Override
        public HttpDestination newHttpDestination(Origin origin) {
            return new HttpDestinationOverFCGI(client, origin) {

                @Override
                protected DuplexConnectionPool newConnectionPool(HttpClient client) {
                    return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this) {

                        @Override
                        protected void leaked(LeakDetector.LeakInfo leakInfo) {
                            connectionLeaks.incrementAndGet();
                        }
                    };
                }
            };
        }
    }, null);
    client.setExecutor(executor);
    clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
    client.setByteBufferPool(clientBufferPool);
    client.start();
}
Also used : Origin(org.eclipse.jetty.client.Origin) HttpDestinationOverFCGI(org.eclipse.jetty.fcgi.client.http.HttpDestinationOverFCGI) Server(org.eclipse.jetty.server.Server) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServerConnector(org.eclipse.jetty.server.ServerConnector) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpClient(org.eclipse.jetty.client.HttpClient) LeakTrackingConnectionPool(org.eclipse.jetty.client.LeakTrackingConnectionPool) HttpClientTransportOverFCGI(org.eclipse.jetty.fcgi.client.http.HttpClientTransportOverFCGI)

Example 2 with LeakTrackingByteBufferPool

use of org.eclipse.jetty.io.LeakTrackingByteBufferPool in project jetty.project by eclipse.

the class HttpClientLoadTest method testConcurrent.

@Test
public void testConcurrent() throws Exception {
    start(new LoadHandler());
    client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
    client.setMaxConnectionsPerDestination(32768);
    client.setMaxRequestsQueuedPerDestination(1024 * 1024);
    int runs = 1;
    int iterations = 256;
    IntStream.range(0, 16).parallel().forEach(i -> IntStream.range(0, runs).forEach(j -> run(iterations)));
}
Also used : IntStream(java.util.stream.IntStream) HttpClientTransport(org.eclipse.jetty.client.HttpClientTransport) LeakDetector(org.eclipse.jetty.util.LeakDetector) Result(org.eclipse.jetty.client.api.Result) ServletException(javax.servlet.ServletException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) Scheduler(org.eclipse.jetty.util.thread.Scheduler) Request(org.eclipse.jetty.client.api.Request) ByteBuffer(java.nio.ByteBuffer) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) ArrayList(java.util.ArrayList) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) HttpClient(org.eclipse.jetty.client.HttpClient) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) Assert.assertThat(org.junit.Assert.assertThat) HttpClientTransportOverHTTP(org.eclipse.jetty.client.http.HttpClientTransportOverHTTP) HttpHeader(org.eclipse.jetty.http.HttpHeader) HttpServletRequest(javax.servlet.http.HttpServletRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConnectionPool(org.eclipse.jetty.client.ConnectionPool) Locale(java.util.Locale) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) HttpDestinationOverFCGI(org.eclipse.jetty.fcgi.client.http.HttpDestinationOverFCGI) Response(org.eclipse.jetty.client.api.Response) Server(org.eclipse.jetty.server.Server) HttpDestination(org.eclipse.jetty.client.HttpDestination) LeakTrackingConnectionPool(org.eclipse.jetty.client.LeakTrackingConnectionPool) HttpServletResponse(javax.servlet.http.HttpServletResponse) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) IO(org.eclipse.jetty.util.IO) TimeUnit(java.util.concurrent.TimeUnit) HttpDestinationOverHTTP(org.eclipse.jetty.client.http.HttpDestinationOverHTTP) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Origin(org.eclipse.jetty.client.Origin) HttpMethod(org.eclipse.jetty.http.HttpMethod) ServerConnector(org.eclipse.jetty.server.ServerConnector) Log(org.eclipse.jetty.util.log.Log) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) Logger(org.eclipse.jetty.util.log.Logger) Assert(org.junit.Assert) HttpClientTransportOverFCGI(org.eclipse.jetty.fcgi.client.http.HttpClientTransportOverFCGI) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) Test(org.junit.Test)

Example 3 with LeakTrackingByteBufferPool

use of org.eclipse.jetty.io.LeakTrackingByteBufferPool in project jetty.project by eclipse.

the class HttpClientLoadTest method testIterative.

@Test
public void testIterative() throws Exception {
    start(new LoadHandler());
    client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
    client.setMaxConnectionsPerDestination(32768);
    client.setMaxRequestsQueuedPerDestination(1024 * 1024);
    // At least 25k requests to warmup properly (use -XX:+PrintCompilation to verify JIT activity)
    int runs = 1;
    int iterations = 500;
    for (int i = 0; i < runs; ++i) run(iterations);
    // Re-run after warmup
    iterations = 5_000;
    for (int i = 0; i < runs; ++i) run(iterations);
    System.gc();
    ByteBufferPool byteBufferPool = connector.getByteBufferPool();
    if (byteBufferPool instanceof LeakTrackingByteBufferPool) {
        LeakTrackingByteBufferPool serverBufferPool = (LeakTrackingByteBufferPool) byteBufferPool;
        assertThat("Server BufferPool - leaked acquires", serverBufferPool.getLeakedAcquires(), Matchers.is(0L));
        assertThat("Server BufferPool - leaked releases", serverBufferPool.getLeakedReleases(), Matchers.is(0L));
        assertThat("Server BufferPool - unreleased", serverBufferPool.getLeakedResources(), Matchers.is(0L));
    }
    byteBufferPool = client.getByteBufferPool();
    if (byteBufferPool instanceof LeakTrackingByteBufferPool) {
        LeakTrackingByteBufferPool clientBufferPool = (LeakTrackingByteBufferPool) byteBufferPool;
        assertThat("Client BufferPool - leaked acquires", clientBufferPool.getLeakedAcquires(), Matchers.is(0L));
        assertThat("Client BufferPool - leaked releases", clientBufferPool.getLeakedReleases(), Matchers.is(0L));
        assertThat("Client BufferPool - unreleased", clientBufferPool.getLeakedResources(), Matchers.is(0L));
    }
    assertThat("Connection Leaks", connectionLeaks.get(), Matchers.is(0L));
}
Also used : LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) Test(org.junit.Test)

Example 4 with LeakTrackingByteBufferPool

use of org.eclipse.jetty.io.LeakTrackingByteBufferPool in project jetty.project by eclipse.

the class ThreadStarvationTest method params.

@Parameterized.Parameters(name = "{0}")
public static List<Object[]> params() {
    List<Object[]> params = new ArrayList<>();
    // HTTP
    ConnectorProvider http = (server, acceptors, selectors) -> new ServerConnector(server, acceptors, selectors);
    ClientSocketProvider httpClient = (host, port) -> new Socket(host, port);
    params.add(new Object[] { "http", http, httpClient });
    // HTTPS/SSL/TLS
    ConnectorProvider https = (server, acceptors, selectors) -> {
        Path keystorePath = MavenTestingUtils.getTestResourcePath("keystore");
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(keystorePath.toString());
        sslContextFactory.setKeyStorePassword("storepwd");
        sslContextFactory.setKeyManagerPassword("keypwd");
        sslContextFactory.setTrustStorePath(keystorePath.toString());
        sslContextFactory.setTrustStorePassword("storepwd");
        ByteBufferPool pool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
        HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory();
        ServerConnector connector = new ServerConnector(server, (Executor) null, (Scheduler) null, pool, acceptors, selectors, AbstractConnectionFactory.getFactories(sslContextFactory, httpConnectionFactory));
        SecureRequestCustomizer secureRequestCustomer = new SecureRequestCustomizer();
        secureRequestCustomer.setSslSessionAttribute("SSL_SESSION");
        httpConnectionFactory.getHttpConfiguration().addCustomizer(secureRequestCustomer);
        return connector;
    };
    ClientSocketProvider httpsClient = new ClientSocketProvider() {

        private SSLContext sslContext;

        {
            try {
                HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
                sslContext = SSLContext.getInstance("TLS");
                sslContext.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
                HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }

        @Override
        public Socket newSocket(String host, int port) throws IOException {
            return sslContext.getSocketFactory().createSocket(host, port);
        }
    };
    params.add(new Object[] { "https/ssl/tls", https, httpsClient });
    return params;
}
Also used : Socket(java.net.Socket) Arrays(java.util.Arrays) SSLContext(javax.net.ssl.SSLContext) ServletException(javax.servlet.ServletException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) MavenTestingUtils(org.eclipse.jetty.toolchain.test.MavenTestingUtils) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Scheduler(org.eclipse.jetty.util.thread.Scheduler) RunWith(org.junit.runner.RunWith) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) Assert.assertThat(org.junit.Assert.assertThat) Future(java.util.concurrent.Future) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) After(org.junit.After) HttpStatus(org.eclipse.jetty.http.HttpStatus) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Parameterized(org.junit.runners.Parameterized) OutputStream(java.io.OutputStream) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Executor(java.util.concurrent.Executor) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) TestTracker(org.eclipse.jetty.toolchain.test.TestTracker) Test(org.junit.Test) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) IO(org.eclipse.jetty.util.IO) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Rule(org.junit.Rule) DispatcherType(javax.servlet.DispatcherType) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Path(java.nio.file.Path) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) Scheduler(org.eclipse.jetty.util.thread.Scheduler) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ArrayList(java.util.ArrayList) SSLContext(javax.net.ssl.SSLContext) Matchers.containsString(org.hamcrest.Matchers.containsString) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Executor(java.util.concurrent.Executor) Socket(java.net.Socket)

Example 5 with LeakTrackingByteBufferPool

use of org.eclipse.jetty.io.LeakTrackingByteBufferPool in project jetty.project by eclipse.

the class SelectChannelServerSslTest method init.

@Before
public void init() throws Exception {
    String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystorePath);
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    sslContextFactory.setTrustStorePath(keystorePath);
    sslContextFactory.setTrustStorePassword("storepwd");
    ByteBufferPool pool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory();
    ServerConnector connector = new ServerConnector(_server, (Executor) null, (Scheduler) null, pool, 1, 1, AbstractConnectionFactory.getFactories(sslContextFactory, httpConnectionFactory));
    SecureRequestCustomizer secureRequestCustomer = new SecureRequestCustomizer();
    secureRequestCustomer.setSslSessionAttribute("SSL_SESSION");
    httpConnectionFactory.getHttpConfiguration().addCustomizer(secureRequestCustomer);
    startServer(connector);
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream stream = sslContextFactory.getKeyStoreResource().getInputStream()) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    __sslContext = SSLContext.getInstance("TLS");
    __sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
    try {
        HttpsURLConnection.setDefaultHostnameVerifier(__hostnameverifier);
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) InputStream(java.io.InputStream) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) ServletException(javax.servlet.ServletException) SocketException(java.net.SocketException) IOException(java.io.IOException) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) Before(org.junit.Before)

Aggregations

LeakTrackingByteBufferPool (org.eclipse.jetty.io.LeakTrackingByteBufferPool)8 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)6 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)6 ServerConnector (org.eclipse.jetty.server.ServerConnector)5 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)4 Test (org.junit.Test)4 InputStream (java.io.InputStream)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 ArrayByteBufferPool (org.eclipse.jetty.io.ArrayByteBufferPool)3 Server (org.eclipse.jetty.server.Server)3 ByteBuffer (java.nio.ByteBuffer)2 KeyStore (java.security.KeyStore)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 SSLContext (javax.net.ssl.SSLContext)2 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)2 HttpClient (org.eclipse.jetty.client.HttpClient)2