套接字接受 - “打开的文件太多" [英] Socket accept - "Too many open files"

查看:30
本文介绍了套接字接受 - “打开的文件太多"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个学校项目,我必须在其中编写一个多线程服务器,现在我通过对它运行一些测试来将它与 apache 进行比较.我正在使用 autobench 来帮助解决这个问题,但是在我运行了一些测试之后,或者如果我给它的速率太高(大约 600+)来建立连接,我会收到打开的文件太多"错误.

I am working on a school project where I had to write a multi-threaded server, and now I am comparing it to apache by running some tests against it. I am using autobench to help with that, but after I run a few tests, or if I give it too high of a rate (around 600+) to make the connections, I get a "Too many open files" error.

处理完请求后,我总是在套接字上执行一个close().我也尝试使用 shutdown() 函数,但似乎没有任何帮助.有什么办法可以解决这个问题吗?

After I am done with dealing with request, I always do a close() on the socket. I have tried to use the shutdown() function as well, but nothing seems to help. Any way around this?

推荐答案

Linux 可以在多个地方限制允许打开的文件描述符数量.

There are multiple places where Linux can have limits on the number of file descriptors you are allowed to open.

您可以检查以下内容:

cat /proc/sys/fs/file-max

这将为您提供系统范围的文件描述符限制.

That will give you the system wide limits of file descriptors.

在 shell 级别,这会告诉您您的个人限制:

On the shell level, this will tell you your personal limit:

ulimit -n

这可以在/etc/security/limits.conf 中更改 - 这是 nofile 参数.

This can be changed in /etc/security/limits.conf - it's the nofile param.

但是,如果您正确关闭了套接字,则除非您同时打开大量连接,否则您不应收到此消息.听起来好像有什么东西阻止了您的套接字正确关闭.我会验证它们是否得到妥善处理.

However, if you're closing your sockets correctly, you shouldn't receive this unless you're opening a lot of simulataneous connections. It sounds like something is preventing your sockets from being closed appropriately. I would verify that they are being handled properly.

这篇关于套接字接受 - “打开的文件太多"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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