Yes, an HTTP connection maps to a single TCP connection. You can share the
TCP connection across threads, although only one thread can use it at a
time. This is particularly useful with persistent connections, which are
the default with HTTP/1.1, and which will be very common in your use case
of connecting to a specific, local data service.

Roughly, the ThreadSafeClientConnManager grants an exclusive "lease" to a
pooled connection to one thread at a time; the thread sends a request,
receives a response, and then checks the connection back into the pool. At
that point, it can then be handed back out to another waiting thread and
reused.

So it's completely fine to multiplex multiple request handling application
threads onto a shared pool of HTTP connections; you just need to make sure
you size the pool appropriately to avoid the type of bottlenecks you're
seeing.

Jon
........
Jon Moore
Comcast Interactive Media






On 6/17/11 10:53 AM, "ChadDavis" <[email protected]> wrote:

>Thanks man!
>
>If you've got an extra minute, could you answer a couple of related
>questions.  I realized in troubleshooting this that I don't really
>understand as much as I could about the http layer of my app.
>
>1) I understand that a single HTTPConnection maps to a single TCP connect.
> Is this correct?
>
>2) Would one ever use a single HTTPConnection across threads?  From my
>reading, this seems to be a firm no!
>
>So, my conclusion is that if I see only two TCP connections via netstat, I
>can assume that my app has indeed bottlnecked at two connections to my
>data
>tier . . .
>
>Any and all insight is appreciated.
>
>
>
>On Fri, Jun 17, 2011 at 8:15 AM, Moore, Jonathan (CIM) <
>[email protected]> wrote:
>
>> Hi Chad,
>>
>> The default max connections per host is 2 in httpclient, so that's
>>almost
>> certainly what you're running into (connection pool is too small). In
>>this
>> scenario you will want to increase both the max total connections and
>>the
>> max connections per route.
>>
>> See
>> 
>>http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
>>#d
>> 4e638 for examples.
>>
>> Jon
>> ........
>> Jon Moore
>> Comcast Interactive Media
>>
>>
>>
>>
>>
>>
>> On 6/17/11 10:10 AM, "ChadDavis" <[email protected]> wrote:
>>
>> >Hey,
>> >
>> >I'm not building anything with httpclient myself, but I'm performance
>> >testing an app that I built with a 3rd party component that makes heavy
>> >use
>> >of httpclient.  I'm trying to rule out a performance bottleneck that,
>>to
>> >my
>> >untrained mind, seems like it might be coming from improper
>>configuration
>> >or
>> >use of httpclient.
>> >
>> >The Problem:
>> >
>> >I have a web app that connects to a data tier server via httpclient.
>> >When I
>> >stress my web app with concurrent users I never see more than 2 TCP
>> >connections from the web app to the data tier, and performance degrades
>> >significantly.  I've read through the httpclient docs, but haven't
>>gleaned
>> >enough myself to judge other folks use of the api.  What I'd like from
>> >someone here is to tell me whether I can take it as a sign of a
>>httpclient
>> >config or usage issue that under an increased load I still only see two
>> >TCP
>> >connections.
>> >
>> >Thanks,
>> >Chad
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to