More ratelimit optimizations
This commit is contained in:
+8
-7
@@ -5,11 +5,7 @@ void uc_ratelimit_init(struct RateLimit *r, long tickets, long period, long curr
|
||||
{
|
||||
r->tickets = tickets;
|
||||
|
||||
if (tickets > period) {
|
||||
r->ticket_cost = tickets * period;
|
||||
} else {
|
||||
r->ticket_cost = period;
|
||||
}
|
||||
r->ticket_cost = period;
|
||||
|
||||
r->period = period;
|
||||
r->funds = r->ticket_cost * tickets;
|
||||
@@ -48,8 +44,13 @@ int uc_ratelimit_allow(struct RateLimit *r, long current_ts)
|
||||
|
||||
//Calculate the cost of tickets that became available since
|
||||
//the last time.
|
||||
r->funds += diff_period *
|
||||
((r->tickets * r->ticket_cost) / r->period);
|
||||
r->funds += diff_period * r->tickets;
|
||||
|
||||
//the below is the real algorithm, with ticket_cost =
|
||||
//tickets * period.
|
||||
//we have optimized this to the expression used above
|
||||
//r->funds += diff_period *
|
||||
// ((r->tickets * r->ticket_cost) / r->period);
|
||||
|
||||
//throttle handing out tickets
|
||||
if (r->funds > r->ticket_cost * r->tickets) {
|
||||
|
||||
Reference in New Issue
Block a user