websockets-rs / rust-websocket

A WebSocket (RFC6455) library written in Rust
http://websockets-rs.github.io/rust-websocket/
MIT License
1.55k stars 223 forks source link

How to write a non-blocking websocket server? #146

Closed Relrin closed 7 years ago

Relrin commented 7 years ago

Hi! I have a couple of questions about implementing a "reverse proxy" which is based on WebSockets. My supposed server do the following things: 1) Listening on incoming message from a client on some port. 2) A new client will make a connection with this server and send data in JSON format to it. 3) Server reads and transforms the incoming request with JSON data inside into Kafka request / message / topic and put it into the message queue. After it subscribing for getting a response from a message queue (for example, by unique identifier, that will be set per each request). 4) Wait some time (we don't know how long it can be), get the response from Kafka, extract the JSON data from it and send as-is to the client as some kind of response (the the same format, in JSON).

So, here are the raised questions about potential using of rust-websocket crate: 1) Possible blocking issue. Shall I implement thread-based (or may be use futures instead?) solution per each incoming request from the particular user? Does it will be good when this logic (that I'd described here) will be per each thread? Or perhaps wrap some piece of code into async blocks will be better? 2) Scalability on processor cores. How good this library is support it? Shall I write an additional code for balancing / switching between processor cores?