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

Use 'spawn delay' to gradually reach indicated concurrency level #14

Open
holtkamp opened this issue May 31, 2018 · 3 comments
Open

Use 'spawn delay' to gradually reach indicated concurrency level #14

holtkamp opened this issue May 31, 2018 · 3 comments

Comments

@holtkamp
Copy link
Contributor

Currently when assigning a Queue 1000 tasks with a concurrency of 50, the first 50 items in the Queue will be "pending" almost "at once". Would it be possible to add a delay between start processing these items, for example with a delay of 0.1 seconds until the concurrency level has been reached?

The idea is: eventual concurrency of 50 is ok, but the work should be started gradually instead of "all at once until maximum concurrency is reached".

@clue
Copy link
Owner

clue commented Jun 2, 2018

Thank you for bringing this up! The decision to immediate start processing is indeed by design and I think this makes sense for a large number of use cases.

That being said, I agree that there are a number of use cases where you want to throttle operations with some some kind of delay between each start. I've already toyed with the idea and I think that a https://en.wikipedia.org/wiki/Token_bucket implementation would be a nice addition to this library 👍

I'm not currently working on this, but any input is appreciated. If you want to help with developing or sponsoring development, reach out and I'm happy to help! :shipit:

@holtkamp
Copy link
Contributor Author

holtkamp commented Jun 2, 2018

Thanks for answering. The https://en.wikipedia.org/wiki/Token_bucket approach is new for me, will read it. The article refers to https://en.wikipedia.org/wiki/Leaky_bucket#As_a_meter, which I did read a few months ago, interesting stuf!

If I understand correctly this library follows the "Leaky bucket as a Queue" approach, right?

I think for now the use of a reasonable "concurrency" suffices for most use cases. At least we got this aspect now documented. Maybe someone will need it in the future

@clue
Copy link
Owner

clue commented Jun 3, 2018

If I understand correctly this library follows the "Leaky bucket as a Queue" approach, right?

Correct 👍 The main difference is that the leaky bucket allows you to limit how many things happen at one time (limits concurrency). The token bucket allows you to control how many things are allowed to be started within a certain period of time (limits average rate with optional bursts).

Of course, both can be combined to express requirements like "start no more than 10 requests per 60s and run no more than 2 requests concurrently".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants