Reputation: 102
I have set up a server for a real time chat (single, group). The clients send their data in a certain interval to the server. The server sends data to the other users, also in a certain interval, to the clients.
If I add more users into chat, the performance gets worse. How can I improve the performance now?
Can I create a more stable performance by using a bigger interval?
Or do you have other ideas?
And is there a debugging tool to check which server actions slow the server down?
Is socket.io support lots of users for chat?
I am using socket.io 2.x
.
Upvotes: 4
Views: 6752
Reputation: 13
Use Socket.io’s Binary Mode Socket.io provides an end-to-end ‘binary mode’ for the WebSockets transport (and a good-enough variant for XHR Polling). All that’s needed to trigger binary mode is the use of Buffers.
Upvotes: 2
Reputation: 4180
Following up on the discussion in comments, there is not enough information to suggest anything else than to investigate the issue further.
Sending 5 bytes of data (really??) even to thousands of users should not clog the network. However, this boils down to implementation details. Perhaps you reestablish the socket connection with every message sent. Perhaps you block the thread with sending the messages. Or something like that happens
You mention a database. Have you looked into that? Perhaps the database is the bottleneck.
You can read up this post on how to implement time profiling for nodeJS. Other than that, try implementing a simple script that isolates the problem. e.g.
Measure how long it takes to send a simple message to a large number users. Does time increases significantly with more users/longer messages?
Measure how long it takes to look up related stuff in the database
Post relevant code here and ask for second pair of eyes to check for issues.
Upvotes: 2