mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 23:47:29 +00:00
fix: RateLimiter 移除 synchronized 并添加 volatile,修复事件循环阻塞
审查发现 synchronized 在 Vert.x 事件循环中会严重阻塞并发。 ConcurrentHashMap 本身已线程安全,移除 synchronized 锁。 RequestInfo 字段添加 volatile 保证多线程内存可见性。
This commit is contained in:
@@ -28,7 +28,7 @@ public class RateLimiter {
|
||||
MAX_REQUESTS, TIME_WINDOW, PATH_REG);
|
||||
}
|
||||
|
||||
synchronized public static Future<Void> checkRateLimit(HttpServerRequest request) {
|
||||
public static Future<Void> checkRateLimit(HttpServerRequest request) {
|
||||
Promise<Void> promise = Promise.promise();
|
||||
if (!request.path().matches(PATH_REG)) {
|
||||
// 如果请求路径不匹配正则,则不进行限流
|
||||
@@ -71,8 +71,8 @@ public class RateLimiter {
|
||||
}
|
||||
|
||||
private static class RequestInfo {
|
||||
int count;
|
||||
long timestamp;
|
||||
volatile int count;
|
||||
volatile long timestamp;
|
||||
|
||||
RequestInfo(int count, long time) {
|
||||
this.count = count;
|
||||
|
||||
Reference in New Issue
Block a user