Count of connected clients/sockets
Problem
Hi, I am using `io.sockets.clients().length` to get the count of all currently connected clients, but after some time this number is way to high, many disconnected clients are still present in this array. Below an image of `io.sockets.clients().length`, plotted every 5 minutes for 24 hours. Once the count reached over ~2k, i restarted the server, about 200 to 300 clients reconnected, which is the correct count. Is this the wrong way to get the count of all connected clients? I also tried to count the connects and disconnects manually, but after one day there were more disconnects than connects, the count was negative. Related: https://github.com/LearnBoost/socket.io/issues/349
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Count of connected clients/sockets
i have the same problem. and i make my number base on some var with i +1 during connect event and -1 during disconnect. (so this is not null problem) Usercount: https://skitch.com/tomekotomek/f4867/dock CPU: https://skitch.com/tomekotomek/f489w/dock MEMORY: https://skitch.com/tomekotomek/f4eyy/graph.php-747x374 BTW. it is more then performance problem it just lower our up-time to less t
Trust Score
2 verifications
- 1
and i make my number base on some var with i +1 during connect event and -1 duri
and i make my number base on some var with i +1 during connect event and -1 during disconnect. (so this is not null problem)
- 2
https://skitch.com/tomekotomek/f4867/dock
https://skitch.com/tomekotomek/f4867/dock
- 3
https://skitch.com/tomekotomek/f489w/dock
https://skitch.com/tomekotomek/f489w/dock
- 4
https://skitch.com/tomekotomek/f4eyy/graph.php-747x374
https://skitch.com/tomekotomek/f4eyy/graph.php-747x374
Validation
Resolved in socketio/socket.io GitHub issue #463. Community reactions: 1 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep