-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
proposal: x/time/rate: add tokens apart of time #53204
Comments
cc @Sajmani |
I'm sorry but I do not understand this proposal. There is an accepted proposal to expose Tokens, but not one to change the number of tokens directly: |
@Sajmani well actually as I described above I wanted to add tokens to the bucket (limiter) apart of time which means for example If I have two threads that are using different limiters they can update each other by adding a token to their bucket (limiter). A good example is to assume you have two HTTP servers and you want to rate-limit requests. Both of them are active and exposed to the user so they should have the same value of current req/s for rate-limiting otherwise user can heat the API double than what it should be. |
Is the goal to enable balancing of rates across multiple instances of rate.Limiter (possibly in multiple processes)? |
@Sajmani Actually the goal is to replicate the rates to the multiple instances of |
Are you replicating the rates or the rate limits? SetLimit and SetBurst allow you to sync the rate limits across multiple rate limiters. |
@Sajmani I'm not going to sync the limits and bursts with the |
Ah, got it! So you have per-user rate limiters on multiple servers, and you want to deduct tokens on all servers whenever the user consumes tokens on any of the servers. |
That is correct.
@Sajmani I didn't get that clearly what you mean. If you mean to stick a user to a server, actually, for scaling and being HA I'm going to expose 3 (n) load balancers to the user so a single client (source IP) can for example do 10k req/s and is being distributed (with some DNS tricks that let's skip this part =) ) to all of my load balancers (each 3.3k req/s). Now all of my load-balancers should be aware that the client (source IP) is doing 10k req/s not (3.3k req/s - or in some scenarios 1k on one server 3k on the other and 6k on the third one). |
ping @Sajmani =) |
Any updates here? We have some use cases for getting current number of tokens for observability reasons |
Related: #68677 asks for being able to sync available tokens with external state. |
What did you do?
I'm trying to add tokens to the bucket apart of the time so this can help to have distributed rate-limiting so that another process can update tokens in the other one if the token is used there.
What did you expect to see?
There can be a function called
AddToken
that let you add tokens to the bucket apart of the time, but because the scenarios that anyone can have are different (like usingAllowN
and not waiting to fill the tokens again) there should be also a function calledTokens
to return the current tokens apart of time so based on the current tokens there can be a possibility to decrease the tokens apart of the time.The text was updated successfully, but these errors were encountered: