-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to add_stream() to only receive new messages #13
Comments
Yeah, your assumption about clone vs add-stream is correct. It's pretty simple to make a best-effort attempt to create a new reader at the current write position, but this will either:
On the unbounded queue: Multiqueue is never going to be unbounded. For the things that I intended it for (high throughput+low latency messaging) unboundedness would incur some pretty undesirable performance costs. |
The problem is, even with this workaround, it only works if a new client connects before the receiver queue is full (since if gets emptied when a client connects in line 37). Otherwise it crashes. |
There are ways to deal with this outside of crashing on a full queue, but with a bounded queue you fundamentally have this issue. What happens if the UI thread can't communicate back to the main thread? It should deal with that instead of crashing or just piling up messages. A prototyping way to deal with this would be to spin on send. I'm going to add a proper blocking api and the futures api already supports blocking send.
I've been thinking of a way to do this without requiring an existing reader. Using an existing reader provides a rudimentary 'pin' of sorts so that writers can't overrun the index of the existing reader. I think I've figured out a way around this though, but I'm not sure if it works. |
Is your solution available somewhere on a branch? |
I'm not even sure if the solution is correct, it only exists in my head up till this point. If you want to send without crashing, for now you can spin until the send works. I've got a whole lot on my plate and probably won't be able to look at this in depth until the weekend |
By spin do you mean trying to send in a loop? Then it won't crash, but the problem is, the receiver (the one that gets cloned to pass to the threads) only gets emptied when a new client connects. |
I'm going to make an api change that would support such behavior in a best-effort sense, as I've realized the other way leads to some edge-case race conditions |
@schets Any update on this? :) |
I'm using multiqueue::broadcast_queue in a situation where I spawn a new thread for each websocket client and call add_stream() for each before spawning the thread, so it gets moved into the thread. (Sending msgs from my main thread to the browser clients).
The problem is, a thread receives old messages that were sent before calling .add_stream(), I think it would be useful to have a way to add a stream such that the new stream only receives new messages.
E.g. this is an example of such a scenario:
http://dpaste.com/1CRPJYN
In line 37 I'm emptying the receiver before I call add_stream(), as a workaround, so it doesn't get old messages.
Also it would be useful to have an queue with unbounded capacity.
Btw, my assumption is that I should use add_stream() when I want messages to be sent to both receivers, and clone() when I want both receivers to compete for dispatching the messages (the first one that asks for a message gets it, the other one doesn't). Is this assumption correct?
The text was updated successfully, but these errors were encountered: