hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Perman <...@permans.com>
Subject Re: question on idle connections
Date Sat, 22 Nov 2014 11:30:19 GMT
We're using 'EntityUtils.toString()' to consume the response on each
request. Is that not sufficient?

thanks
sam


On Saturday, November 22, 2014, Oleg Kalnichevski <olegk@apache.org> wrote:

> On Fri, 2014-11-21 at 21:00 +0000, Jaikit Savla wrote:
> > Closing Idle and Expired connection is application only when stream
> associated with Connection is closed, otherwise connections are not
> considered idle. Looks like there is leak in connections at your side.
> Below code snippet shows one example on how to close the stream in a
> guaranteed fashion.
> >         HttpResponse response = httpClient.execute(httpGet);
> HttpEntity entity = response.getEntity();        String jsonString = null;
>       try {            InputStream instream = entity.getContent();
> >             /* do your processing with the stream */        } finally {
>           EntityUtils.consumeQuietly(entity);        }
> > Jaikit
> >
> >      On Friday, November 21, 2014 12:48 PM, Sam Perman <sam@permans.com
> <javascript:;>> wrote:
> >
> >
>
> Jaikit is absolutely right. This section of the HttpClient tutorial may
> also be of help:
>
>
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e145
>
> Oleg
>
> >  Hello
> >
> > We have had a persistent issue in production where after a few days our
> > PoolingClientConnectionManager becomes unusable because there are no
> > available connections. It turns out all of the available connections are
> > “leased” (according to the PoolStats).
> >
> > I thought I was doing the right thing by writing an
> > IdleConnectionManagerThread as recommended in the docs. This thread will
> > call “closeExpiredConnections” and “closeIdleConnections” on a regular
> > interval.
> >
> > Looking at the implementation of AbstractConnPool.closeExpired and
> > AbstractConnPool.closeIdle I don’t understand how they work. In our case,
> > all of our connections are “leased”… but these methods only ever iterate
> > and close connections that are “available”. How do I clean up leased
> > connections?
> >
> >             Iterator<E> it = this.*available*.iterator();
> >             while (it.hasNext()) {
> >                 E entry = it.next();
> >                 if (entry.getUpdated() <= deadline) {
> >                     entry.close();
> >                     RouteSpecificPool<T, C, E> pool =
> getPool(entry.getRoute());
> >                     pool.remove(entry);
> >                     it.remove();
> >                     notifyPending(pool);
> >                 }
> >             }
> >
> > thanks
> > sam
> > ​
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> <javascript:;>
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> <javascript:;>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message