/**
-
漏斗限流算法
-
@author dhc
-
@date 2020/5/22
*/
public class FunnelRateLimiter {
private Map<String, Funnel> funnelMap = new ConcurrentHashMap<>();/**
-
假设 设定漏斗的容量为5 限定每30秒 能访问5次 超过5次 就失败
-
@param args
-
@throws InterruptedException
/
public static void main(String[] args) throws InterruptedException {
Long start=System.currentTimeMillis();
FunnelRateLimiter limiter = new FunnelRateLimiter();
int testAccessCount = 30;
/*- 容量
/
int capacity = 5;
/* - 允许量
/
int allowQuota = 5;
/* - 时间
/
int perSecond = 30;
int allowCount = 0;
int denyCount = 0;
for (int i = 0; i < testAccessCount; i++) {
boolean isAllow = limiter.isActionAllowed(“dadiyang”, “doSomething”, 5, 5, 30);
if (isAllow) {
allowCount++;
} e
- 容量
-