Prajesh Bhattacharya
Prajesh Bhattacharya

Reputation: 111

Every HTTP request uses a separate TCP connection

Observations:

Facts:

What I am trying to accomplish

At this point, I am not sure what code, configuration details or log I should attach to the question, but if you let me know, I will provide it. Any kind of help is appreciated.

p.s. This thread seemed promising from the title TCP connection is not reused for HTTP requests with HttpURLConnection, but it deals mainly with the client side.

Upvotes: 7

Views: 6239

Answers (1)

Prajesh Bhattacharya
Prajesh Bhattacharya

Reputation: 111

I think I have found a solution to this. Thanks for the pointers and the suggestions. They really helped.

Part 1: I used the HttpFox plugin in Firefox to look at the response headers. As Philippe suspected the Connection header had a value of "close".

Part 2: Adding a line of code in my own filter to change the response header did not help. So I downloaded and added jbossWebService.jar to the WEB-INF/lib directory in order to use the org.jboss.web.tomcat.filters.ReplyHeaderFilter class. (Prior to JBoss 7, apparently this package used to be included in JBoss by default.) Added the following in my web.xml:

<filter>

<filter-name>CommonHeadersFilter</filter-name>

<filter-class>

org.jboss.web.tomcat.filters.ReplyHeaderFilter</filter-class>

<init-param>

     <param-name>Connection</param-name>

     <param-value>keep-alive</param-value>

</init-param>

</filter>

This did the trick (well, almost). Now, the first "click" from the browser generates about 4 TCP connections - not sure about the reason for that number, because every single click generates >=7 http requests. But all subsequent clicks, if performed within the ttl period (15 s), do not generate additional TCP connections. I guess a more thorough investigation, as suggested by Philippe, would reveal something. But at this point I have to move on. So, for the time being I will mark this question as answered. If needed in the future, I will re-open it.

Upvotes: 1

Related Questions