简体   繁体   中英

Java socket accept queue length

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.

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.

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

要限制拒绝的连接,请确保在执行该轮询的任何发送/接收处理之前,为每个选择轮询处理所有的连接请求。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM