WANG 5 年之前
父節點
當前提交
b7db7a0d22
共有 1 個文件被更改,包括 6 次插入3 次删除
  1. 6 3
      src/main/java/cn/com/qmth/examcloud/web/interceptor/ApiFlowLimitedInterceptor.java

+ 6 - 3
src/main/java/cn/com/qmth/examcloud/web/interceptor/ApiFlowLimitedInterceptor.java

@@ -42,7 +42,9 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
 
 	private static final RateLimiter rateLimiter;
 
-	private static boolean enable;
+	private static boolean enable = true;
+
+	private static int allowedRate = 0;
 
 	private static Properties props = new Properties();
 
@@ -52,6 +54,7 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
 		rateLimiter = RateLimiter.create(permitsPerSecond);
 
 		enable = PropertyHolder.getBoolean("examcloud.api.flowLimited.enable", true);
+		allowedRate = PropertyHolder.getInt("examcloud.api.flowLimited.allowedRate", 5);
 
 		new Thread(new Runnable() {
 			@Override
@@ -135,9 +138,9 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
 		}
 		if (limited) {
 
-			// 允许10%的请求
+			// 限流后放行率
 			int random = RandomUtils.nextInt(100);
-			if (random <= 10) {
+			if (random <= allowedRate) {
 				return true;
 			}