1

Even though i am properly terminating everything when i check existing HTTP connections i see they are not terminated

For example when i open 200 concurrent connections by starting different tasks

I see

158 Established HTTP connections
927 TimeWait
95 SynSent
24 LastAck
6 CloseWait
34 FinWait

The worse part is, the number of TimeWait keep increasing each minute

So how can i prevent such issue to happen?

After a while the windows become unable to make any new requests

This problem occurs when i use webproxies : Too many proxy connection kills window's resolving hosts ability

Here when i use 200 connections with different proxies

enter image description here

Community
  • 1
  • 1
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342

1 Answers1

1

Connections in TimeWait state can generate a performance problem.

First, take a look at TCP State diagram,

https://en.wikipedia.org/wiki/File:Tcp_state_diagram_fixed_new.svg

This is a state of a TCP connection after a machine’s TCP has sent the ACK segment in response to a FIN segment received from its peer (details in RFC 793 defining TCP back in 1981 http://www.ietf.org/rfc/rfc793.txt). During this state the socket resources, including the TCB (TCP Control Block) and the port of course, are not released to the OS. After a timeout expires, socket resources are released to the OS. The original reason is to deal with the Two Generals problem that can happen between peers in an unreliable medium. The connection will be in TimeWait until a configurable timeout which has a default value that is dependent on the operating system.

These links can help you to set the TcpTimedWaitDelay parameter in Windows:

https://technet.microsoft.com/en-us/library/cc938217.aspx http://msdn.microsoft.com/en-us/library/ee377084%28v=bts.10%29.aspx

It says the default value is 240 seconds but I'm my tests I experienced lower times (between 60 and 120).

Anyway, today networks are more reliable and web services requiring high performance and throughput should reduce this value. I would suggest set it just to 5 seconds. If you want to be more conservative, set it to 30 seconds.

Other parameter that could be useful for you is the max number of ephemeral ports Windows allows a client to open. Windows Server by default limits the maximum number of ephemeral TCP ports. In some Windows, this value could be 5000. You can change this behavior by setting the value MaxUserPort in the registry.

rodolk
  • 5,606
  • 3
  • 28
  • 34
  • Ty very much. Can you tell me exact registry names to set both values? Number of maximum TCP connections and changing default wait value of TimeWait? for windows 8.1 – Furkan Gözükara Mar 20 '17 at 18:49
  • @MonsterMMORPG, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort and TcpTimedWaitDelay. It's in the link, I believe they are the same for Windows 8.1 . If they don't exist you have to add them. – rodolk Mar 20 '17 at 18:55
  • yes i think it should add. anyway that i can verify they are working? i mean like some cmd commands etc? – Furkan Gözükara Mar 20 '17 at 18:57
  • @MonsterMMORPG, this is the only way I found: for TimeWait state, you can measure it with your watch. Just open and close five connections and see how the number of sockets in TimeWait change. It's easy to distinguish. The MaxUserPort, first try to open 1K or 10K connections and you will get an error. Then change the parameter and try again. – rodolk Mar 20 '17 at 19:10