-
-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to bug no #471 as AbstractCacheRateLimiter is Impacting perfo…
…rmance "in case of redis" because of synchronized keyword , as Redis is single threaded and can maintain synchronization on his own , no need for extra synchronization (#472) Fixes # suggested fix to introduce new abstract class "AbstractNonBlockCacheRateLimiter" to handle RedisRateLimiter Co-authored-by: Mohamed Fawzy <[email protected]>
- Loading branch information
1 parent
5cb01bc
commit 4517f2b
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...loud/autoconfigure/zuul/ratelimit/config/repository/AbstractNonBlockCacheRateLimiter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository; | ||
|
||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.Rate; | ||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.RateLimiter; | ||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitProperties; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* @author mohamed fawzy | ||
*/ | ||
public abstract class AbstractNonBlockCacheRateLimiter implements RateLimiter { | ||
|
||
@Override | ||
public Rate consume(RateLimitProperties.Policy policy, String key, Long requestTime) { | ||
final Duration refreshInterval = policy.getRefreshInterval(); | ||
final Long quota = policy.getQuota() != null ? policy.getQuota().toMillis() : null; | ||
final Rate rate = new Rate(key, policy.getLimit(), quota, null, null); | ||
|
||
calcRemainingLimit(policy.getLimit(), refreshInterval, requestTime, key, rate); | ||
calcRemainingQuota(quota, refreshInterval, requestTime, key, rate); | ||
|
||
return rate; | ||
} | ||
|
||
protected abstract void calcRemainingLimit(Long limit, Duration refreshInterval, Long requestTime, String key, Rate rate); | ||
|
||
protected abstract void calcRemainingQuota(Long quota, Duration refreshInterval, Long requestTime, String key, Rate rate); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters