socket.io每个发射动作都会创建新的虚拟文件 [英] socket.io Every emit action create new virtual file

查看:136
本文介绍了socket.io每个发射动作都会创建新的虚拟文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理node + socket.io应用程序.到目前为止,一切都很顺利.最近,我开始收到一些错误:

I'm working on node + socket.io application. So far everything went quite OK. Recently I started to receive some errors:

 Error: accept EMFILE

 warn error raised error listen eaddrinuse

搜索互联网使我想到了这个stackoverflow问题:

Searching internet brought me to this stackoverflow question: Node.js SSL server frozen, high CPU, not crashed but no connections . In answer Knskan3 wrote that:

每个套接字都会创建一个新的虚拟文件.

Each socket creates a new virtual file.

我检查了一下,看起来每个套接字都发出了动作:

I checked that and it looks like every socket emit action:

 io.sockets.in(roomName).emit('some_action', data);

创建新的虚拟文件.

现在,当我有一个非常动态的应用程序每秒发送一次数据时,那么将有一种方法可以在很短的时间内在服务器上创建许多新文件,最后服务器将达到最大文件数限制(默认值为1024).我可以增加限制,但我不认为这是解决方案,因为它确实可能会产生很多问题.我是在做错事还是真的以这种方式工作?您如何建议解决此问题?

Now, when I have very dynamic application that emits data every second then there will be way to much new files created on server in very short amount of time and finally server will reach limit of max files (default is 1024). I can increase limit but I don't think that it is solution because it really can be a lot of emits. Am I doing something wrong or emit really works that way? And how do you suggest to solve this?

在回答了一些问题之后,我将粘贴在控制台显示的内容下面:

After some answers I pasted below what console shows:

xxxx:~# ls -l /proc/11124/fd | wc -l
20
xxxx:~# ls -l /proc/11124/fd | wc -l
21
xxxx:~# ls -l /proc/11124/fd | wc -l
22
xxxx:~# ls -l /proc/11124/fd

lrwx------ 1 root root 64 08-23 08:21 0 -> socket:[7352977]
lrwx------ 1 root root 64 08-23 08:21 1 -> socket:[7352980]
lrwx------ 1 root root 64 08-23 08:23 10 -> socket:[7444235]
lrwx------ 1 root root 64 08-23 08:23 11 -> socket:[7444237]
lrwx------ 1 root root 64 08-23 08:23 12 -> socket:[7444239]
lrwx------ 1 root root 64 08-23 08:23 13 -> socket:[7444245]
lrwx------ 1 root root 64 08-23 08:23 14 -> socket:[7444243]
lrwx------ 1 root root 64 08-23 08:23 15 -> socket:[7444252]
lrwx------ 1 root root 64 08-23 08:23 16 -> socket:[7444250]
lrwx------ 1 root root 64 08-23 08:23 17 -> socket:[7444254]
lrwx------ 1 root root 64 08-23 08:23 18 -> socket:[7445919]
lrwx------ 1 root root 64 08-23 08:23 19 -> socket:[7446836]
lrwx------ 1 root root 64 08-23 08:21 2 -> socket:[7352982]
lrwx------ 1 root root 64 08-23 08:23 20 -> socket:[7447275]
lrwx------ 1 root root 64 08-23 08:21 3 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 08-23 08:21 4 -> anon_inode:[eventfd]
lr-x------ 1 root root 64 08-23 08:21 5 -> pipe:[7352986]
l-wx------ 1 root root 64 08-23 08:21 6 -> pipe:[7352986]
lrwx------ 1 root root 64 08-23 08:21 7 -> socket:[7352987]
lrwx------ 1 root root 64 08-23 08:23 8 -> socket:[7444231]
lrwx------ 1 root root 64 08-23 08:23 9 -> socket:[7444233]

在执行每个操作后,我运行了命令:ls -l /proc/11124/fd | wc -l(就像在我粘贴链接的站点中告诉的那样),并且它递增了一个.对我来说,它似乎仍会创建文件.我在互联网上看到了许多类似情况,建议解决方案是增加限制,但这不是解决方案,而是临时解决方案.

After each action I ran command: ls -l /proc/11124/fd | wc -l (like was told in site to which I pasted link) and it increment by one. For me it looks like it creates files anyway. I saw many simillar situations on the internet and suggested solutions was to increase ulimit but thats not a solution but temporarilly fix.

好的,我发现了问题.我在应用程序内存缓存中使用.当我不再需要连接时,我没有关闭连接,因此许多发射操作导致使用memcache创建新连接而不关闭它.现在一切正常.

Ok I found issue. I use in app memcache. I didn't close connection when I didn't need it anymore so many emit actions had result in creating new connections with memcache and not closing it. Now everything is ok.

推荐答案

对于增加流量的节点服务器,增加文件限制是有先例的: http://blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections/

There is past precedent for increasing the file limit for node servers that are expecting a lot of traffic: http://blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections/

这篇关于socket.io每个发射动作都会创建新的虚拟文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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