Search in sources :

Example 1 with PoolStats

use of org.apache.http.pool.PoolStats in project jmeter by apache.

the class JMeterPoolingClientConnectionManager method formatStats.

private String formatStats(final HttpRoute route) {
    final StringBuilder buf = new StringBuilder();
    final PoolStats totals = this.pool.getTotalStats();
    final PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
Also used : PoolStats(org.apache.http.pool.PoolStats)

Example 2 with PoolStats

use of org.apache.http.pool.PoolStats in project lucene-solr by apache.

the class HttpSolrClientConPoolTest method testLBClient.

public void testLBClient() throws IOException, SolrServerException {
    PoolingHttpClientConnectionManager pool = HttpClientUtil.createPoolingConnectionManager();
    final HttpSolrClient client1;
    int threadCount = atLeast(2);
    final ExecutorService threads = ExecutorUtil.newMDCAwareFixedThreadPool(threadCount, new SolrjNamedThreadFactory(getClass().getSimpleName() + "TestScheduler"));
    CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams(), pool);
    try {
        final LBHttpSolrClient roundRobin = new LBHttpSolrClient.Builder().withBaseSolrUrl(fooUrl).withBaseSolrUrl(barUrl).withHttpClient(httpClient).build();
        List<ConcurrentUpdateSolrClient> concurrentClients = Arrays.asList(new ConcurrentUpdateSolrClient.Builder(fooUrl).withHttpClient(httpClient).withThreadCount(threadCount).withQueueSize(10).withExecutorService(threads).build(), new ConcurrentUpdateSolrClient.Builder(barUrl).withHttpClient(httpClient).withThreadCount(threadCount).withQueueSize(10).withExecutorService(threads).build());
        for (int i = 0; i < 2; i++) {
            roundRobin.deleteByQuery("*:*");
        }
        for (int i = 0; i < 57; i++) {
            final SolrInputDocument doc = new SolrInputDocument("id", "" + i);
            if (random().nextBoolean()) {
                final ConcurrentUpdateSolrClient concurrentClient = concurrentClients.get(random().nextInt(concurrentClients.size()));
                // here we are testing that CUSC and plain clients reuse pool 
                concurrentClient.add(doc);
                concurrentClient.blockUntilFinished();
            } else {
                if (random().nextBoolean()) {
                    roundRobin.add(doc);
                } else {
                    final UpdateRequest updateRequest = new UpdateRequest();
                    // here we mimic CloudSolrClient impl
                    updateRequest.add(doc);
                    final List<String> urls = Arrays.asList(fooUrl, barUrl);
                    Collections.shuffle(urls, random());
                    LBHttpSolrClient.Req req = new LBHttpSolrClient.Req(updateRequest, urls);
                    roundRobin.request(req);
                }
            }
        }
        for (int i = 0; i < 2; i++) {
            roundRobin.commit();
        }
        int total = 0;
        for (int i = 0; i < 2; i++) {
            total += roundRobin.query(new SolrQuery("*:*")).getResults().getNumFound();
        }
        assertEquals(57, total);
        PoolStats stats = pool.getTotalStats();
        //System.out.println("\n"+stats);
        assertEquals("expected number of connections shouldn't exceed number of endpoints" + stats, 2, stats.getAvailable());
    } finally {
        threads.shutdown();
        HttpClientUtil.close(httpClient);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrQuery(org.apache.solr.client.solrj.SolrQuery) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) PoolStats(org.apache.http.pool.PoolStats) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ExecutorService(java.util.concurrent.ExecutorService) SolrjNamedThreadFactory(org.apache.solr.common.util.SolrjNamedThreadFactory)

Example 3 with PoolStats

use of org.apache.http.pool.PoolStats in project lucene-solr by apache.

the class HttpSolrClientConPoolTest method testPoolSize.

public void testPoolSize() throws SolrServerException, IOException {
    PoolingHttpClientConnectionManager pool = HttpClientUtil.createPoolingConnectionManager();
    final HttpSolrClient client1;
    final String fooUrl;
    {
        fooUrl = jetty.getBaseUrl().toString() + "/" + "collection1";
        CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams(), pool, false);
        client1 = getHttpSolrClient(fooUrl, httpClient);
        client1.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
    }
    final String barUrl = yetty.getBaseUrl().toString() + "/" + "collection1";
    {
        client1.setBaseURL(fooUrl);
        client1.deleteByQuery("*:*");
        client1.setBaseURL(barUrl);
        client1.deleteByQuery("*:*");
    }
    List<String> urls = new ArrayList<>();
    for (int i = 0; i < 17; i++) {
        urls.add(fooUrl);
    }
    for (int i = 0; i < 31; i++) {
        urls.add(barUrl);
    }
    Collections.shuffle(urls, random());
    try {
        int i = 0;
        for (String url : urls) {
            if (!client1.getBaseURL().equals(url)) {
                client1.setBaseURL(url);
            }
            client1.add(new SolrInputDocument("id", "" + (i++)));
        }
        client1.setBaseURL(fooUrl);
        client1.commit();
        assertEquals(17, client1.query(new SolrQuery("*:*")).getResults().getNumFound());
        client1.setBaseURL(barUrl);
        client1.commit();
        assertEquals(31, client1.query(new SolrQuery("*:*")).getResults().getNumFound());
        PoolStats stats = pool.getTotalStats();
        assertEquals("oh " + stats, 2, stats.getAvailable());
    } finally {
        for (HttpSolrClient c : new HttpSolrClient[] { client1 }) {
            HttpClientUtil.close(c.getHttpClient());
            c.close();
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrQuery(org.apache.solr.client.solrj.SolrQuery) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) PoolStats(org.apache.http.pool.PoolStats)

Aggregations

PoolStats (org.apache.http.pool.PoolStats)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1 SolrjNamedThreadFactory (org.apache.solr.common.util.SolrjNamedThreadFactory)1