Question

According to the Sun's documentation on ServerSocket:

The maximum queue length for incoming connection indications (a request to connect) is set to 50. If a connection indication arrives when the queue is full, the connection is refused.

How can I increase the the queue length? It's my server's bottle-neck.

Thank you.

Was it helpful?

Solution

Use the ServerSocket constructor with the backlog parameter.

You may also want to consider using a Thread pool (or really an ExecutorService) to dispatch incoming requests. Depending on how you architect it, this will generally lead to better throughput.

OTHER TIPS

Use the backlog parameter of the constructor (Javadoc). Keep in mind that you won't be able to increase the queue past the operating system limits, though. This is to prevent SYN attacks - see this article for more information.

There is another constructor for ServerSocket.

public ServerSocket(int port, int backlog)

where backlog is the connection queue size you want. The max 50 only applied to the default constructor that takes int port

To limit the connection refused be sure you process all of the connect requests for each select poll before doing any of the send/receive processing for that poll.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top