WANG hace 5 años
padre
commit
82e3c10cc0

+ 8 - 0
src/main/java/cn/com/qmth/examcloud/web/interceptor/ApiFlowLimitedInterceptor.java

@@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang.math.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.servlet.HandlerInterceptor;
@@ -133,6 +134,13 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
 			LOG.error("fail to get value of expression. expression= " + expression, e);
 		}
 		if (limited) {
+
+			// 允许10%的请求
+			int random = RandomUtils.nextInt(100);
+			if (random <= 10) {
+				return true;
+			}
+
 			// 我也不知道这是啥玩意儿 by wangwei
 			Double mean = apiStatusInfo.getMean();
 			int sleep = mean > 1000d ? 1000 : mean.intValue();