Implement concurrency limit template #32
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes it is required to limit concurrency without RPS limitation.
Let's consider a situation we have a function which takes 100 ms and we want to have 3 or less calls of the function at any moment. We may use
ratelimit
template with parameters{concurrentRequests: 3, rps: 30}
.Let's consider a situation we have a function which takes 1 s and we want to have 3 or less calls of the function at any moment. We may use
ratelimit
template with parameters{concurrentRequests: 3, rps: 3}
.The problem here is that
rps
parameter depends on the time of the function's execution which is usually unknown and is not a constant.In other words if we don't want to limit RPS an interface instrumented with
ratelimit
template doesn't limit concurrency. Take a look at https://github.com/masim05/gowrap/blob/concurrency-limit-motivation/templates_tests/interface_with_ratelimit_test.go#L37 (which fails) for more details.Since the change will be backward incompatible with current implementation of
ratelimit
template (in terms of runtime behaviour) it is worth having a separate template for concurrency limitation. This PR provides the implementation.