Skip to content
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

Topics as RwLock instead of Mutex #23

Open
Nereuxofficial opened this issue Aug 13, 2023 · 3 comments
Open

Topics as RwLock instead of Mutex #23

Nereuxofficial opened this issue Aug 13, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@Nereuxofficial
Copy link
Member

Nereuxofficial commented Aug 13, 2023

Having benchmarked the performance of the broker i examined for possible performance gains.(Also IME it's the slowest when i've been fuzzing it)

I think a tokio's RwLock may increase the performance. I'd have to look into it, since it's been a while since i've been working with the broker, however if most accesses are Reads this could increase the performance significantly.

Do you think this is worthwhile? @mfloto

Edit: subscribing to the sender only requires read access

@Nereuxofficial Nereuxofficial added the enhancement New feature or request label Aug 13, 2023
@Nereuxofficial Nereuxofficial self-assigned this Aug 13, 2023
@mfloto
Copy link
Contributor

mfloto commented Aug 14, 2023

I'd also have to look into it, but as far I can tell it would be beneficial as we only write to e.g. topics, if a subscription to a new topic is required.

@Nereuxofficial
Copy link
Member Author

Nereuxofficial commented Aug 26, 2023

I since looked into it a bit. It does not in fact look good. Since channels use Mutexes internally, we do have to have a lot of mutable accesses(both reading from a channel as well as writing, as reading may remove an element) no matter what channel we use. Cloning the channel internally is beneficial, but only as long as multiple messages are received via it. For reduced internal complexity of the channel we could probably switch to a Watch since broadcast is many-to-many instead of single-to-many which is the only thing we use...

Implementing a structure for this ourselves would be difficult but possible. We could have a Ringbuffer or Vector, but would need to track the count of subscribers and remove messages after every one of them has received a message.

A fun approach though would be to use sharding for splitting the workload and let each thread handle a channel asynchronously, eliminating the need for shared state and Mutexes if well designed.(Though we would have to think about how to distribute them)

@Nereuxofficial
Copy link
Member Author

One way this might work is by locking all channels behind a RwLock(or sharding them) and putting channels behind a Lock individually, so a lock would only have to be kept on one of the channels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants