Java套接字接受队列长度
根据Sun关于ServerSocket的文档:
传入连接指示(连接请求)的最大队列长度设置为 50。如果在队列已满时连接指示到达,则连接将被拒绝。
如何增加队列长度?这是我服务器的瓶颈。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 ServerSocket带有
backlog
参数的构造函数。您可能还想考虑使用线程池(或者实际上是 ExecutorService)来分派传入请求。根据您的架构方式,这通常会带来更好的吞吐量。
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.
使用构造函数的
backlog
参数 (Javadoc)。但请记住,您将无法将队列增加到超过操作系统限制。这是为了防止 SYN 攻击 - 请参阅这篇文章了解更多信息。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.ServerSocket 还有另一个构造函数。
其中 backlog 是您想要的连接队列大小。最大 50 仅适用于采用
int port
的默认构造函数There is another constructor for ServerSocket.
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.