使用文件描述符传递时现有连接的状态?
我正在使用一个网络服务器,使用unix套接字和sendmsg/recvmsg将套接字文件描述符传递给新的服务器进程,而不会丢失任何请求。在使用 ab 进行测试时,我发现客户端连接会持续存在,并且 apachebench (ab) 将显示错误:“apr_poll:指定的超时已过期 (70007)”。
我怀疑文件描述符的地址发生了变化,这会使打开的连接变得无用,但是确保在每个请求结束时关闭连接并没有什么区别,有几个请求会失败。
套接字级别是否有一些额外的奇怪现象,或者 ab 只是很奇怪?还有什么我应该考虑的吗?
编辑:使用 PHP 作为客户端发出请求也会在周期期间停止。
I'm playing around with a webserver, using a unix socket and sendmsg / recvmsg to pass the socket file descriptor to a new server process without losing any requests. While testing it with ab I found that client connections would linger, and apachebench (ab) would show the error: "apr_poll: The timeout specified has expired (70007)".
I suspected that there was a change to the address of the file descriptor that would render open connections useless, however making sure the connections were closed at the end of every request didn't make a difference, a couple of the requests would fail.
Is there some extra oddity at the socket level or is ab just being weird? Is there anything else I should take into account?
Edit: Using PHP as a client to make requests also stalls during the cycle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有一个正在侦听套接字(接受传入连接)的主服务器并且您有多个工作进程,那么它确实有意义。
您可以选择一个合适的/空闲的worker(例如,基于每个worker正在使用的TCP连接数)并将传入连接的描述符从master传递到worker。当多个工作人员在公共端点上侦听时,这有助于避免“惊群”。
It does make sense if you have a master server which is listening on a socket (accepting incoming connections) and you have multiple worker processes.
You can select a suitable/free worker (for example, based on the number of TCP connections every worker is using) and pass the descriptor of the incoming connection from the master to the worker. This helps to avoid the "thundering herd" when multiple workers listen on the common endpoint.
这相当于尝试通过电话线发送电话。这没有任何意义。套接字 fd 标识连接的端点。如果另一个主机想要连接,它必须建立自己的连接。你不能给它你的之一。
That's equivalent to trying to send a telephone over a telephone line. It doesn't make any sense. A socket fd identifies the endpoint of a connection. If another host wants a connection it will have to mke its own. You can't give it one of yours.