Another Windows Socket Limitation Fix

I have a secret project that I’m putting through non functional testing at the moment. Its ftping around 600,000 files in the space of a few hours – which means its violating the 4000 sockets in 4 minutes limitation in windows.

File #4902 System.Net.Sockets.SocketException: 
Only one usage of each socket address (protocol/network address/port) is normally permitted

I don’t want to have to run my application at about 1% of its available capacity.

Luckily the solution corresponds with the usual registry tweaks for windows to make it scale.

  1. Ensure that all sockets use the “keep-alive” (So windows can work out faster if the socket is closed)
  2. Push this HKLMSystemCurrentControlSetServicesTcpipParametersMaxUserPort to 65534
  3. Reduce the time wait HKLMSystemCurrentControlSetServicesTcpipParametersTCPTimedWaitDelay to 30 seconds

This means I can ftp 120000 files in one minute – which is much more like it.

Update #1

This seems to be part of the puzzle too.

And this and this

Update #2

8/6/2007 7:49:38 PM LOG Made 32450 in 22 minutes (927 connections per second)

With all of the above tweaks I managed this on a windows XP machine – it threw no “Only one usage” errors




About James McParlane

CTO Massive Interactive. Ex Computer Whiz Kid - Now Grumpy Old Guru.
This entry was posted in C#. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s