Each HTTP request uses a separate TCP connection.

Remarks:

  • JBoss runs my web application.

  • Each user click generates> 5 HTTP requests due to images, etc.

  • Running netstat on the server shows that a new TCP connection is opened for each individual HTTP request (basically I look at the total number of TCP connections from the client IP address on port 80).

Facts:

  • The JBoss HTTP protocol is set to 1.1.

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

  • I have two test environments: one runs on Windows7, and the other on CentOS. I see the same behavior in both.

What am i trying to accomplish

  • Permanent TCP connection, because we hope that: a) improves user experience and b) reduces server load

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

ps This thread seemed promising from the name TCP connection is not reused for HTTP requests with HttpURLConnection , but it mainly concerns the client side.

+4
source share
1 answer

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

Part 1: I used the HttpFox plugin in Firefox to view the response headers. Because Philip suspected that the Connection header was set to close.

Part 2: Adding a line of code to my own filter to change the response header did not help. So I downloaded and added jbossWebService.jar to the WEB-INF / lib directory to use the org.jboss.web.tomcat.filters.ReplyHeaderFilter class. (Prior to JBoss 7, apparently this package was included in JBoss by default.) The following was added to 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 - I'm not sure about the reason for this number, because every single click generates> = 7 HTTP requests. But all subsequent clicks, if they are performed during the ttl period (15 s), do not generate additional TCP connections. I think that a more thorough investigation, as Philip suggested, will reveal something. But now I have to move on. So, while I mark this question as an answer. If necessary in the future, I will open it again.

+1
source

Source: https://habr.com/ru/post/1416401/


All Articles