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

Feature request: Set as pool / random sampling #320

Open
the8472 opened this issue Jan 27, 2025 · 0 comments
Open

Feature request: Set as pool / random sampling #320

the8472 opened this issue Jan 27, 2025 · 0 comments

Comments

@the8472
Copy link

the8472 commented Jan 27, 2025

I have a large map of IDs -> items, some fraction of those items is in a ready state. I'm using a set of IDs to pick the next ready item and remove it from the ready-set.

Having a way to extract a random item from a set would be useful and likely faster.

  • Random sampling would avoid the multi-step, non-atomic approach of first iterating to find an ID, copying it, then removing it from the set, it could instead remove an item under a single write lock.
    When multiple threads try this concurrently they'll collide on trying to remove the same ID (since the iterators always start at shard 0) and the other threads will have to retry
  • Random sampling could optimistically attempt try-locking some shards before blocking since the order doesn't matter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant