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

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

问题描述

我在一所学校项目的工作,我必须写一个多线程服务器,而现在我被反对它运行一些测试比较它的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()插座上。我曾尝试使用关机()功能为好,但似乎没有任何帮助。解决这个办法?

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.

在外壳的水平,这将告诉你,你的个人极限:

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.

不过,如果你正确地关闭您的插座,你不应该,除非你打开了很多simulataneous连接收到此。这听起来像的东西是$ P $被关闭适当的pventing插座。我想确认他们正在妥善处理。

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天全站免登陆