Errno 24:打开的文件太多.但是我没有打开文件吗? [英] Errno 24: Too many open files. But I am not opening files?

查看:65
本文介绍了Errno 24:打开的文件太多.但是我没有打开文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用treq( https://github.com/twisted/treq )查询一些我的网络服务中的其他api.今天,当我对自己的服务进行压力测试时,它显示了一个错误

I am using treq (https://github.com/twisted/treq) to query some other api from my web service. Today when I was doing stress testing of my own services, It shows an error

twisted.internet.error.DNSLookupError:DNS查找失败:未找到地址"api.abc.com":[错误24]打开的文件太多.

但是问题是,我的整个代码没有打开任何文件.我怀疑这可能是因为我的查询失败或阻止了我(api.abc.com)所导致的api,因为我的压力测试可能像ddos一样达到了终点.不过,在那种情况下,那不应该是拒绝连接吗?我不知道为什么会有打开文件太多错误.还是这是由于创建过多的线程查询引起的?

But the problem is, my entire code I didn't open any file. I suspect it could be caused by the api I query goes down or blocked me (the api.abc.com) since my stress testing could be like a ddos to that end point. Still, in that case shouldn't that be something like refuse connection? I don't know why it will have that Too many open files error. Or is that caused by creating too much thread query?

推荐答案

文件"包括网络套接字,这是基于Unix的系统上的一种文件.可以使用 ulimit -n

"Files" include network sockets, which are a type of file on Unix-based systems. The maximum number of open files is configurable with ulimit -n

# Check current limit
$ ulimit -n
256

# Raise limit to 2048
$ ulimit -n 2048

用完文件句柄并提高限制也就不足为奇了.但是,如果限制已经很高,则可能是文件句柄泄漏(没有足够快地关闭它们).在像Python这样的垃圾收集语言中,终结器不一定总是以足够快的速度关闭文件,这就是为什么在完成操作后应谨慎使用 with 块或其他系统来关闭文件的原因.他们.

It is not surprising to run out of file handles and have to raise the limit. But if the limit is already high, you may be leaking file handles (not closing them quickly enough). In garbage-collected languages like Python, the finalizer does not always close files fast enough, which is why you should be careful to use with blocks or other systems to close the files as soon as you are done with them.

这篇关于Errno 24:打开的文件太多.但是我没有打开文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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