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
New Annotation to combine different Annotations #643
Comments
Hi,
But then we thought, if a user needs the flexibility he could just implemented it without annotations:
Would you like to create a PR for a new annotation and a Spring Boot aspect? |
ok, give me some time to prepare it |
After your nice Bulkhead PR. Would you like to implement this issue as well? |
Yes, I'm starting to work on this. |
I understand every one is ok with this change? If any one has concerns then please make them known now. I would like to avoid getting feedback about conceptual issues after spending hours of implementing it. I'll implement in a backwards compatible manner, one will still be able to use those annotations without One question as for naming: Should we have a |
Yes, we are ok with this change. But the old usage style should not be deprecated. The user just has two options. But the new option allows better control of the order of the decorators. |
I think that having two options in this case will create more confusion then benefits. Using my approach adds very little complexity. By keeping both ways you will have to explain that in one way of doing annotations their order is respected and you can have like two rate limiter but in the other aproach it is not and you cannot. You will also need to document both approaches. The final decision is up to you but I just wanted to make my opinion known. |
Ok, the feature to allow multiple RateLimiters on one method is new to me. I didn't notice it. You want to limit the rate per second to protect against overload. That's clear to me. |
I think in order to configure the number of permits (weight) you don't need to create a new RateLimiter instance.
and on another method you could use
|
See this method from my initial example:
This is a real world use case from the Binance cryptocurrency exchanges API. When placing orders it imposes the following limits:
|
In a more broader view: some cryptocurrency exchanges I'm working with impose these type of limits on a per user basis and some on a per IP basis. In the Xchange library I solve this problem by having either static resilience4j registries per exchange or by having an independent registry for each authenticated instance of an exchange client. |
Just to be 100% clear. You are a Client of the Binance API and not the developer of the API Implementation, correct? |
The current RateLimiter was more designed to limit the rate on backends which are under your control and not elastic scalable and you want to protect them from overload. That's why we are implementing an AdaptiveBulkead which can adapt itself. See concept -> #201 |
Yes, I'm the client. I'm working on this library: knowm/XChange#3231 On Binance I can download their limits from their API. On other exchanges I have to mantain my configuration on my part. What I cannot do is to exceed those limit to far because they will block my IP then. And in a multi threaded application even if I will halt all my threads when I get the first error indicating I'm over the limit I still can get a ban because there are many concurrent request in the middle of execution. |
Ok, I understand. |
A new traffic shaping component would be nice. A combination of a ThreadPoolBulkhead and RateLimiter. The Bulkhead has a queue and threadpool and when the rate limit is exceeded, the threadpool stops processing tasks from the queue for a certain time (until the next rate limit window starts). Our current RateLimiter is not an implementation of a leaky bucket algorithm which leaks out at a constant rate. It uses a fixed window algorithm which can have burst effects at time window boundaries. The burst effects at time window boundaries can also lead to a situation where your client is sending to many request to the Binance servers. |
I don't need constant rates. Burst effects are fine for me. All I want in my project it to respect the limits imposed by cryptocurrency exchanges. Every API of such that I know has a rate limit policy defined in the same way your RateLimiter works - its a perfect fit. Applications in a clustered environment that want to use Xchange will have a problem if the limits are not IP bound but user account bound but that is something that the users of our library will have to handle in their applications code. Many exchanges will block their API keys if they see calls from multiple IPs to the same account at once. Making a client session stick with one server / IP is probably the best solution in this use case. Organizing work loads in such a manner is out side the scope of both resilience4j and Xchange. |
@walec51 Are you still working on this topic? |
Yes, it took a lot of work to prepare an initial PR with basic support for the annotations I proposed. Please take a look if the direction this is heading is good. Unfortunately I had to break compatibility for I've also refactored the code so that common code to handle
and
is encapsulated in a Despite doing that I still think that we should pick one way of doing annotations instead of supporting the old way and my new approach. I literary don't want to be the person that will have to explain in our documentation why this respects the annotations ordering:
and this does NOT:
I think that not deprecating the old way of doing annotations will give us more confusion then convenience in the long run. |
@RobWin could you have a look at my PR, it was a lot of work and I would like to know if there is anything controversial there |
It would be great to have this functionality and have the PR merged! |
+1, LTAGTM. I've been following this for a while. Multiple rate limiters (and placing fully responsibility on the client to implement them) are a fact of life, and being able to implement these as aspects would really simplify development in cases like the ones @walec51 mentions. |
Any update on this issue? This would be a great value addition. Thanks. |
my pull request #744 died on a review comment written by @RobWin which would break my working implementation @RobWin did not respond to my explanation why his proposal was impossible to implement without breaking the order in which decorators would be applied, he just closed the pull request without responding |
Hi @walec51, I really want to look at this PR/feature again and see if we can support multiple decorators/annotation per method. I still like this feature very much. |
Problems with current annotations:
Proposal for new annotations:
Usage examples on a JAX-RS interface for a REST Proxy Client framework like retrofit or si.mazi.rescu:
This also showcases the "weight" feature for RateLimiter I'm proposing at: #642
If you would like to see a working implementation of these annotations then take a look at: knowm/XChange#3231
The text was updated successfully, but these errors were encountered: