socket.io Every emit action create new virtual file

流过昼夜 提交于 2019-12-08 08:04:04

问题


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

 Error: accept EMFILE

and

 warn error raised error listen eaddrinuse

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);

create new virtual files.

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?

EDIT: 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]

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.

EDIT2: 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.


回答1:


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/



来源:https://stackoverflow.com/questions/18377311/socket-io-every-emit-action-create-new-virtual-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!