SO_PORT_SCALABILITY

The SO_PORT_SCALABILITY socket option enables local port scalability for a socket.

SO_PORT_SCALABILITY
0x3006

The SO_PORT_SCALABILITY socket option enables local port scalability by allowing port allocation to be maximized by allocating wildcard ports multiple times for different local address port pairs on a local machine.

Remarks

Proxy server environments have scalability issues because of limited local port availability. One way to work around this is to add more IP addresses to the machine. Another limitation is that by default, wildcard ports used with the bind function are limited to 64K on a local machine no matter the number of IP addresses on the local machine. Working around this requires the application to maintain their own port pool either with port reservation or by using some heuristics.

To avoid having every application that requires scalability from managing port pools, Windows Server 2008 provides a SO_PORT_SCALABILITY socket option that maximizes the wildcard port allocation. Port allocation is maximized by allowing an application to allocate wildcard ports for each unique local address and port pair. So if a local machine had 4 IP addresses, a potential limit of 256 KB (64 KB × 4) wildcard ports could be allocated used by wildcard bind function requests.

Using a SO_PORT_SCALABILITY socket option could unconditionally change the behavior observed by existing applications. In the past when an application binds to a wildcard port, it is implicitly guaranteed that the port that was allocated by bind is not available for use by any other application requests for wildcard binds on the local computer.

To allow for greater scalability and maintain application compatibility, Windows Server 2008 implements the SO_PORT_SCALABILITY socket option in a way designed to minimize application compatibility issues. When the SO_PORT_SCALABILITY socket option is set on a socket and a call to the bind function is made for a wildcard address and port (the name parameter is set with a wildcard address and a port of 0), Winsock will allocate a port for the wildcard address. This allocation will be based on all of the possible IP addresses and ports/per address on the local computer. This allocation will be further restricted to the degree that the wildcard port that was previously allocated can be used by only a single process. So if a wildcard port is allocated with the SO_PORT_SCALABILITY socket option, then this same port can only be allocated on the local computer to the same process (if the other request also sets the SO_PORT_SCALABILITY socket option and there are other IP addresses available on the local computer). This ensures different applications do not see this behavior change for a wildcard bind unless the application specifically requests it.

To have any effect, the SO_PORT_SCALABILITY option must be set before the bind function is called. Any example of how this would be used on a local computer with two multiple addresses is outlined below:

  • The socket function is called by a process to create a socket.
  • The setsockopt function is called to enable the SO_PORT_SCALABILITY socket option on the newly created socket.
  • The bind function is called to do a wildcard bind on the local computer and any available port. After the function call succeeds, the actual port that was used is saved for later use by the application.
  • The connect function is then called to connect to a remote IP address. The socket is used by the application as needed.
  • A socket function is called by the same process (possibly a different thread) to create a second socket.
  • The setsockopt function is called to enable the SO_PORT_SCALABILITY socket option on the newly created socket.
  • The bind function is called to bind to another wildcard bind on the local computer and any available port. Even when all ports have been previously allocated, this call succeeds if their are multiple IP addresses available on the local computer since the SO_PORT_SCALABILITY socket option was set on both sockets in the same process.
  • The connect function is then called to connect to a remote IP address. The socket is used by the application as needed.

Requirements

Minimum supported client

None supported

Minimum supported server

Windows Server 2008 [desktop apps only]

Header

Ws2def.h

See also

getsockopt
setsockopt
SOL_SOCKET Socket Options
Socket Options

 

 

Community Additions

ADD
Show:
© 2014 Microsoft