Select() + UDP 导致打开的文件太多 [英] Select() + UDP resulting in too many open files

查看:64
本文介绍了Select() + UDP 导致打开的文件太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前配置了一个 select() 语句来跟踪两个 UDP 套接字.我在一个通用数据套接字上每秒发送 10 到 20 条消息,这正如我所期望的那样解释.

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.

但是,一旦我收到大约 1024 条消息,我就会收到通知:

However, once I hit around 1024 messages, I get the notice:

talker:socket:打开的文件太多talker: 绑定套接字失败

talker: socket: Too many open files talker: failed to bind socket

这对我来说是合乎逻辑的,因为 ulimit -n 显示该用户最多打开 1024 个文件.但是,为什么会有所有这些打开的文件?使用 UDP,没有建立连接,所以我认为我不需要每次都关闭一个套接字(尽管我可能错了).

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.

推荐答案

我认为在这种情况下打开的文件太多"实际上意味着您已达到文件描述符限制;网络套接字计入此限制.你确定没有其他东西 - 在 routehelper 中说 - 这会创建更多的套接字吗?

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?

你在什么平台上运行?如果 Linux,lsof 或在 /proc/<pid>/fd 中徘徊 - 在它运行时,在达到限制之前 - 可能会说明所有 fd 的去向.

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.

提示:不要依赖 socket_udp_inboundALL 在数值上大于 socket_udp_inboundRC - 最好至少明确比较它们的值一次.

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.

这篇关于Select() + UDP 导致打开的文件太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆