Fork me on GitHub

Is there a way to apply backpressure to the WebSocket handler in Aleph? I have a network server, and one kind of network messages it serves is bottlenecked on a shared resource. I'd like to make sure the producers of WebSocket messages are paused somehow when the server is not keeping up with the demand.


The protocol is "fire-and-forget", and I can't change it, so there is not much possibility to do a backpressure on protocol level, so it has to be something lower-level, e.g. TCP backpressure.


I don't care about proxies, as it's a server-to-server communication with no proxies in between.


@dottedmag, taking Aleph out of the equation, what is your expected outcome in the client-server interaction when the server can’t handle the load? What does fire-and-forget mean - does the client not wait for any response?


@dm3 The expected outcome is that clients slow down until the server can handle the load. Clients do not wait for a WebSocket-level response, but every client uses only one WebSocket connection for communication.


If I were starting from scratch, I'd do something like this: a bounded small queue, one thread reading from it and working on a shared resource, request handlers in a pool submitting jobs to this queue synchronously. If a queue is full, request handlers block, and no data is read from the network sockets.


However I'd like to have other kinds of requests, not bottlenecked on this shared resource, to proceed.


I’m afraid I don’t know enough about Aleph to help here. I’d try to separate the handlers serving the two types of clients (bottlenecked/non-bottlenecked) though so that you don’t have to solve this problem generically.


I can do that once the connection is established – the first message carries the kind of connection. But I don't think I have an option to say to Aleph "from now on use this pool to handle the WebSocket messages from this connection"


All right, I'll go dig into source code a little.


on the Manifold side you have stream/onto which will put all of the callbacks onto the specified pool


however that’s probably not what you are looking for


Actually it might be the thing I'm looking for.


@dm3 Thanks, I'll give it a try.