7

Observations:

  • My web app is running in JBoss.

  • Every single user-click generates >5 HTTP requests because of images etc.

  • Running netstat on the server reveals that a new TCP connection is being opened for every single HTTP request (basically I am looking at the total number of TCP connections from the client IP on port 80).

Facts:

  • JBoss HTTP protocol is set at 1.1.

  • I have checked with FF, IE9 and Chrome - and all browsers do the same.

  • I have two test environments - one running on Windows7 and the other one running on CentOS. I see the same behavior in both.

What I am trying to accomplish

  • Persistent TCP connection, because hopefully that would a) enhance user experience and b) reduce load on the server

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.

Community
  • 1
  • 1
  • Can you look at the traffic? Can you check the Connection HTTP headers that the client and server send? – Philippe Marschall Jun 06 '12 at 19:18
  • Hi Philippe, thanks for the reply. Which header items should I look at? I would probably be doing it using the HttpServletRequest and HttpServletResponse getHeader(String header) methods. If there is a quicker way to do it, I would be interested to learn about that. Thanks for the help! – Prajesh Bhattacharya Jun 06 '12 at 19:40
  • @PhilippeMarschall Request header: checked the following items 1) Cookie -> JSESSIONID=blah-blah, 2) Connection -> keep-alive, 3) Cache-Control -> null, 4) pragma -> null – Prajesh Bhattacharya Jun 06 '12 at 20:25
  • What I usually use is a combination of tcpdumpd and Wireshark and then follow the tcpstream. This allows me to see what requests are made over a tcp connection. Then I look at the Close header http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.10 both sent by the client and the server. I look for a "Connection: close" header. Does the client or server send one? – Philippe Marschall Jun 07 '12 at 08:29
  • A browser side tool like firebug, fiddler or httpwatch will also give you that data. – Nicholas Jun 07 '12 at 13:01
  • Partially, the headers are already parsed and you don't see where a tcp connection starts and where it ends. – Philippe Marschall Jun 07 '12 at 19:47

1 Answers1

1

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.

James Webster
  • 31,873
  • 11
  • 70
  • 114
  • 1
    Most modern browsers open up to 4-8 simultaneous connections per hostname, to speed up loading multiple files from the same host. You can find detailed information on the behavior of each browser on [Browserscope](http://www.browserscope.org/?category=network&v=top). – MartinodF Jun 09 '12 at 01:17
  • @MartinodF This is very informative and helpful (your comment as well as the Browserscope project)! Thank you very much! I will now consider this problem to be solved. – Prajesh Bhattacharya Jun 09 '12 at 14:44