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

Monitor channel buffer capacity #2642

Closed
sampaioletti opened this issue Jul 4, 2020 · 1 comment · Fixed by #3690
Closed

Monitor channel buffer capacity #2642

sampaioletti opened this issue Jul 4, 2020 · 1 comment · Fixed by #3690
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Experience needed to fix: Medium / intermediate M-sync Module: tokio/sync

Comments

@sampaioletti
Copy link

Describe the solution you'd like
Provide a way to monitor the capacity of the channel buffers. i.e.

impl Sender<T>{
[...]
  pub fn buffer_len(&self)->usize{
   self.[inner-semaphore].available_permits()
  }
}

Describe alternatives you've considered
Currently using atomics to keep an accounting

Additional context
Not sure if that would be the correct way to handle it, in my case the loading on one worker thread may vary so I used the count to temporarily spawn additional works as needed.

Additionally the ability to resize the semaphore would be nice. Obviously there are ways to handle this outside of tokio, but I wasn't sure if it was basically already (nearly) possible with the semaphore api.

Thanks!

@sampaioletti sampaioletti added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jul 4, 2020
@Darksonn Darksonn added the M-sync Module: tokio/sync label Jul 4, 2020
@Darksonn Darksonn added E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Experience needed to fix: Medium / intermediate labels Jul 28, 2020
@Darksonn
Copy link
Contributor

If this is possible to add with the information already stored in the channel, then I would be happy to add this feature.

blasrodri added a commit to blasrodri/tokio that referenced this issue Aug 9, 2020
blasrodri added a commit to blasrodri/tokio that referenced this issue Aug 9, 2020
blasrodri added a commit to blasrodri/tokio that referenced this issue Aug 28, 2020
davidpdrsn added a commit that referenced this issue Apr 10, 2021
davidpdrsn added a commit that referenced this issue Apr 12, 2021
Simply exposes the number of available permits of the semaphore.

This makes some kinds of bookkeeping easier without having to manually keep counts using atomics.

Fixes #2642
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Experience needed to fix: Medium / intermediate M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants