选择() + UDP 导致打开文件过多
我目前有一个 select() 语句配置为跟踪两个 UDP socker。我在一个通用数据套接字上每秒可能发送 10 - 20 条消息,这正如我所期望的那样。
然而,当我收到大约 1024 条消息时,我收到通知:
talker:套接字:打开的文件太多 talker:绑定套接字失败
这对我来说是合乎逻辑的,因为 ulimit -n 显示该用户最多打开 1024 个文件。但是,为什么会有所有这些打开的文件呢?使用UDP,没有建立连接,所以我不认为我需要每次都关闭套接字(尽管也许我错了)。
有什么想法吗?提前致谢。
I currently have a select() statement configured to keep track of two UDP sockers. I send perhaps 10 - 20 messages a second at one general data socket, which is this interpreted as I expected.
However, once I hit around 1024 messages, I get the notice:
talker: socket: Too many open files
talker: failed to bind socket
This is logical to me, since ulimit -n shows a max of 1024 open files for this user. However, why are there all of these open files? With UDP, there is no connection made, so I do not believe I need to be closing a socket each time (although perhaps I'm wrong).
Any ideas? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为在这种情况下“打开的文件太多”实际上意味着您已经达到了文件描述符限制;网络套接字计入此限制。您确定没有其他东西(例如在
routehelper
中)创建更多套接字吗?你在什么平台上运行?如果 Linux,
lsof
或在/proc//fd
中摸索 - 当它运行时,在达到限制之前 - 可能会说明所有 fd 的去向。提示:不要依赖
socket_udp_inboundALL
在数值上大于socket_udp_inboundRC
- 最好至少显式比较它们的值一次。I think in this case "Too many open files" really means you've hit the file descriptor limit; network sockets count towards this limit. Are you sure that there's nothing else - say in
routehelper
- that's creating further sockets?What platform are you running on? If Linux,
lsof
or grobbling around in/proc/<pid>/fd
- while it's running, before it hits the limit - might illustrate where all the fds are going.Tip: Don't rely on
socket_udp_inboundALL
being numerically larger thansocket_udp_inboundRC
- it's better to explicitly compare their values at least once.如果您使用的是 Linux,请执行
strace(1)
在客户端上检查socket(2)
和open(2)
与close(2)
系统调用(尝试- e trace=socket,open,close
选项)。这是此时平衡文件描述符计数的最简单方法。If you are on Linux do an
strace(1)
on the client to check for thesocket(2)
andopen(2)
vsclose(2)
system calls (try-e trace=socket,open,close
option). This is the easiest way to balance the file descriptor count at this point.