选择() + UDP 导致打开文件过多

发布于 2024-09-07 13:19:13 字数 327 浏览 2 评论 0原文

我目前有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼角的笑意。 2024-09-14 13:19:13

我认为在这种情况下“打开的文件太多”实际上意味着您已经达到了文件描述符限制;网络套接字计入此限制。您确定没有其他东西(例如在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 than socket_udp_inboundRC - it's better to explicitly compare their values at least once.

恍梦境° 2024-09-14 13:19:13

如果您使用的是 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 the socket(2) and open(2) vs close(2) system calls (try -e trace=socket,open,close option). This is the easiest way to balance the file descriptor count at this point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文