socket.io Every emit action create new virtual file
Asked Answered
B

1

1

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.

Brufsky answered 22/8, 2013 at 10:1 Comment(2)
No, broadcast/emit does not create sockets. It uses them. Sockets are created for each user that connects to server, which correspond to 1 file. 1024 is very less, the OS needs files for other things too.Refugiorefulgence
Hi, thanks for comment. I edited my question with some logs. I looks lika every action create files.Brufsky
A
0

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/

Actinal answered 22/8, 2013 at 22:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.