Is what I'm doing even what uWebSockets is designed for? #1468
-
So I'm just using this personal project of mine to really learn about network scalability but now I'm questioning if it's the right solution. The simple premise is that users/clients send their "state" 3-5 times a second, and the server averages all the "states" and sends back the average to each client (each client would have some customization to the state though). But I was considering how to write my code assuming there could be thousands of active clients at the same time, so I want my code to be asynchronous.
The above app works fine, the issue comes from me sending back the message, I learned the hard way that if you try to send data in another thread, crashes will happen.
However, I still want to have my message sending not tied to receiving messages from the websocket. This is when I realize I don't understand how uWebsocket even handles threading. In the above example does every *ws have its own thread? Are all websockets on the same thread? If so how well does the library scale if one app handles thousands of clients? Is what I'm doing even the right way of using websockets? And if so how should I solve the problem of periodically sending data back to the clients without tying myself to waiting for messages from said clients? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This shows one way to do that.
No. One thread can handle thousands of WebSocket connections.
They are on as many threads as you create. The documentation says "If you want to, you can simply take the previous example, put it inside of a few std::thread and listen to separate ports, or share the same port (works on Linux)" |
Beta Was this translation helpful? Give feedback.
This shows one way to do that.
No. One thread can handle thousands of WebSocket connections.
They are on as many threads as you create. The documentation says "If you want to, you can simply take the previous example, put it inside of a few std::thread and listen to separate ports, or share the same port (works on Linux)"