2

I have a ajax application that makes a request every 3 seconds, the requested page sets the header to (header("Connection: Keep-Alive, close");) then performs a database query and returns the latest data.

The value for TIME_WAIT is 60 seconds, so even tough I close the connection in my requested page(i.e "Connection: Keep-Alive, close"), the connection seem to be present for the next 60 seconds (this occurs for every Ajax request that I make), so for 1 minute 20 requests are made and total TIME_WAIT for that IP seems to be around 20

Is it possible to reduce the TIME_WAIT to say 15 seconds, to reduce the overall TIME_WAITS or is it possible to force a connection close after every Ajax request

Any help will be appreciated

Thanks

Akash
  • 229
  • 3
  • 7

2 Answers2

2

You can use net.ipv4.tcp_fin_timeout kernel parameter:

# sysctl net.ipv4.tcp_fin_timeout=15

Edit /etc/sysctl.conf, add to end

net.ipv4.tcp_fin_timeout = 15

then run:

# sysctl -p
ooshro
  • 10,874
  • 1
  • 31
  • 31
1

Connection: keep-alive, close is not valid HTTP 1.1, as exactly one connection-token is allowed, so I'd expect this header to be ignored and keep-alive to be active nonetheless; in HTTP 1.0, the "Connection" tag means something completely different.

There should be no technical difference whether the connection is "recycled" or not, and you should leave that choice to the browser. Playing with FIN timeouts is almost never a good idea.

Simon Richter
  • 3,209
  • 17
  • 17