0

I have a remote webserver listening on port 80, which serves a page which loads 100 individual .png files (from the same server and hostname) via 100 <img /> tags. On that remote server I do watch -n 1 "netstat -na | fgrep ":80 " | fgrep 123.123.123.123" (where 123.123.123.123 is the external IP of my client computer) and when I visit that page I usually see around 5-6 connections made to the server from my client computer. I use chrome or firefox to do that page request and by inspecting any of those requests (either of the page or of any of the png files) using the F12 dev tools I see the request header Connection:keep-alive. I also confirm via looking at the webserver logs that all of those requests are done using HTTP/1.1 which I think uses keep alive by default.

All the above facts and observations mean that the 101 requests (1 page + 100 pngs) go through 5-6 connections, and not through 101 connections.

My question is, how can I disable keep alive in chrome or firefox?

In firefox I tried setting the following in about:config but it didn't change anything in this behavior:

network.http.keep-alive.timeout;0
network.http.tcp_keepalive.long_lived_connections;false
network.http.tcp_keepalive.long_lived_idle_time;0
network.http.tcp_keepalive.short_lived_connections;false
network.http.tcp_keepalive.short_lived_idle_time;0
network.http.tcp_keepalive.short_lived_time;0
network.tcp.keepalive.enabled;false
network.tcp.keepalive.idle_time;0
network.tcp.keepalive.retry_interval;0

I'd be OK if I had to do something on O/S level (windows or linux) to disable keep alive, use a different (even custom) browser or even use some sort of web proxy which would cancel this behavior for me.

cherouvim
  • 744
  • 3
  • 18
  • 37

2 Answers2

2

HTTP keep-alive means that the client announces to the server that it wants to keep the TCP connection open for more requests and asks the server to not close it. The server might adhere to this wish or not. Since it looks like that the server is under your control it might be easier just to disable keep-alive at the server which thus causes keep-alive to be stopped for all browsers. It is not clear what kind of server you have but the relevant configurations for nginx are here and for apache here.

But while it makes sense to disable or limit HTTP keep-alive at the server to reduce used resources I wonder why you want to disable it in the client. While it might be interesting to just see what happens the behavior you see with one browser will not be applicable to other browsers and will not be applicable to determine server load for a specific page since even without HTTP keep-alive the browsers will still only use a limited number of parallel connections and not sent all requests in parallel. And, the exact behavior depends on browser and configuration.

Steffen Ullrich
  • 12,227
  • 24
  • 37
  • Nice answer with a slightly different perspective. Also, I like the idea of testing this with a different server-side configuration, as it doesn't get easier than that. Upvote! – Esa Jokinen Jul 19 '17 at 08:54
1

Once upon a time in Firefox, this was possible with network.http.keep-alive that doesn't exists anymore, because persistent connections are one of the most important features for HTTP/1 performance.

Your network.http.keep-alive.timeout;0 doesn't work because there won't be any idle time; the connections gets used again immediately by the browser, because there's still more files to GET.

Even without the keep-alive feature a browser would probably be polite and start individual connections after the last connection ended rather that opening 101 connections simultaneously.

As this isn't about keep-alives but the amount of simultaneus connections, with Firefox, you could test network.http.max-persistent-connections-per-server; 101. However, I'm not quite sure would it even allow to use a ridiculously high value...

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122