-
Notifications
You must be signed in to change notification settings - Fork 37
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
Separate add_rx from Bus #24
Comments
I've been doing some research today; I don't mess around with lock-free code very often so it's an interesting learning experience! I quickly found out that making |
Hehe, yes, I ran into this a while back too, and had the same realization you had that making that change isn't as straightforward as I first thought. It might be that the solution here is to add a lock that is only taken to add readers, and on every call to |
That's one idea to try. Another would be to send "add" messages via a channel, similar to the way that it currently handles dropped readers. That way the broadcaster can be notified where each new reader starts, resolving the issue of figuring out whether the new reader was started on the tail of the queue before or after the broadcast takes place. |
Okay, the lock implementation is in a working state, here are the benchmarks on my machine:
|
A slight increase is to be expected I think. I wonder if with this lock, we can now also get rid of the additional thread that does dropping? That might bring back some savings. You could also try |
With
The only thread I found was for unparking, which should be unrelated. Do you mean removing the |
Ah, you're right, there isn't a drop thread, I was just getting things mixed up in my head. But yes, I wonder whether we can get rid of the |
I have encountered the same issue. |
After also coming across the same issue, I settled upon using this fork which seems to work perfectly. I completely agree with @romainreignier, having this merged into the main crate would be very useful as it is a fairly vital feature for a lot of use-cases. I know I'm a bit late to the party but again any chance of this being merged @agausmann, perhaps as an optional feature? |
@jonhoo @agausmann Running into a similar issue and was wondering if merging this in to the main crate would be possibel? |
Yep, I think it does make sense to merge this! Per my last comment though, I'd still like to see it also get rid of the |
Been a while since I used this, but I may be able to finish that this week. |
Hey, any updates? |
This might be related to or a duplicate of #19 , but it's not clear based on the wording of the original issue.
The problem with
add_rx
being tied toBus
occurs in my use case where I want to:Bus
to a separate "dispatch" thread.Once the
Bus
has been moved to the dispatch thread, it can't be used on the main thread to create more receivers, thus fixing the number that I can create. It is technically possible to send messages to create more and send them back via channels, but I have another idea I'd like to pursue to see if it's any better.What I propose is creating a secondary interface (let's call it
ReadHandle
for now), which could be created by a method onBus
and would also implementadd_rx
.Internally, it would only involve taking clones of
Bus.state
and the sendersBus.leaving.0
,Bus.waiting.0
when constructed, so it would be mostly zero-cost. The one major change would be makingBus.readers
atomic and moving it toBusInner
, but we can at least try it and see how it affects benchmarks.The text was updated successfully, but these errors were encountered: