-
Notifications
You must be signed in to change notification settings - Fork 17
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
Avoid dropping elements on consume (idea) #93
Comments
Thanks for reaching out!
That's what I would do. And that's what I've actually done for some time. I've created a data type that, when dropped, sends itself (or rather its contents) back over a secondary queue, where it can be re-used: But later I changed that to avoid the heap-allocated type.
I'm open for improvements, but I think it's also OK to have multiple implementations with different properties and therefore different strengths and weaknesses. And different APIs.
I'm not sure how widely it's actually used. You can also check out https://github.com/agerasev/ringbuf, which seems to be more popular. And your
I wouldn't want to force this requirement onto all users. I think that's a good reason to have a separate project.
I'm sure this has its uses, but some users might actually want to have move semantics, e.g. when the items are managing some kind of resource. Of course one could always use an
Yes, I've thought about it, and this sounds really interesting, but I didn't want to be too platform-specific. I'm also not sure about the performance implications, but I'd hope that the mmap trick is faster. The API would be completely different, so there wouldn't be much left from the original It would be interesting if the two approaches (and maybe even more?) can share some code. I'm not sure though, since the mmap approach uses a different (simpler) internal logic, as you mentioned. Another aspect: I'm playing with the thought of putting all the memory into a single allocation, which I've implemented in #75. This is supposed to remove one indirection, but I don't know yet if that's worthwhile. |
All good points, thanks for taking a look! I think we can conclude that the two projects are sufficiently different that there is no point of sharing code - only ideas. (I can't say I really understand #75, but fwiw, depending on how you count allocations, the "dynamic" part of cueue resides in a single allocation, and the Reader and Writer reference that) |
I agree.
Yes, I've just looked at that, but there is an additional allocation created by However, you seem to have an additional In In the end I would really only make a single dynamic allocation, which holds two atomic indices for head/tail (with cacheline padding), an atomic So far, I couldn't see convincing performance improvements, so I'm not sure if it is worth the additional code. In your BTW, I'm wondering about your |
Good point, now I understand what you mean much better. I retained
Where's 128 coming from? I understand the alignment must be less than pagesize (and power2), that is 4096 or 4*4096 on systems I have access to - never heard of a use-case for a larger alignment. |
From https://github.com/erenon/cueue/blob/f536ef748cd36f72888ee9c1ac4f5b69d6575129/src/lib.rs#L251 I thought your items follow immediately after the two padded indices, but now I've seen that you are using an offset of In #75 I was using |
Hi, thanks for the great library!
Here's my use-case: This is a low latency application. Thread A sends elements over a spsc channel to Thread B. The elements contain heap-allocations, e.g: String. (I know, this is funny to have both "low latency" and "heap allocated elems" in the same system, but that's it)
With any popular queue solution, including rtrb, popping takes ownership of the elem, making the consumer eventually Drop it (unless it does not send the consumed elem back using a different channel). This makes Thread A continuously allocated, and Thread B continuously deallocate, eventually making them contending for the same lock. This has measurable effects.
To solve this issue, I ported my C++ queue to rust: https://github.com/erenon/cueue
This has the following differences compared to rtrb:
Perhaps some ideas can be salvaged to make rtrb even better? (I would prefer the widely used rtrb over my tiny lib, if it was possible) Thanks!
The text was updated successfully, but these errors were encountered: