速率限制
🌐 Rate limiting
QUIC 端点内置了速率限制,以防止拒绝服务攻击。它有两个防御层:
🌐 QUIC endpoints include built-in rate limiting to protect against denial-of-service attacks. There are two layers of defense:
全局速率限制 会限制端点发送无状态响应的总速率,无论来源地址如何。这可以防止来自伪造源 IP 地址的洪水攻击,也就是攻击者通过轮换许多假的源地址来绕过每主机限制。有四种类型的无状态响应会被独立地限制速率:
- 重试数据包——在建立连接时发送,用于验证客户端地址。可通过
endpointOptions.retryRate和endpointOptions.retryBurst配置。 - 无状态重置数据包——当端点收到未知会话的数据包时发送。可以通过
endpointOptions.statelessResetRate和endpointOptions.statelessResetBurst配置。 - 版本协商数据包 — 当客户端使用不支持的 QUIC 版本时发送。可以通过
endpointOptions.versionNegotiationRate和endpointOptions.versionNegotiationBurst配置。 - 立即连接关闭数据包 — 当服务器繁忙或令牌无效时发送。可以通过
endpointOptions.immediateCloseRate和endpointOptions.immediateCloseBurst配置。
每个速率限制都使用令牌桶:端点可以瞬间发送最多突发容量的请求,令牌会以配置的每秒速率重新填充。当桶为空时,该类型的额外响应会被静默丢弃。默认值(每秒100个,突发200个)适用于大多数部署。
🌐 Each rate limit uses a token bucket: the endpoint can send up to the burst capacity instantly, and tokens refill at the configured rate per second. When the bucket is empty, additional responses of that type are silently dropped. The defaults (100 per second, burst of 200) are suitable for most deployments.
每主机会话创建速率限制限制了单个远程地址创建新会话的速度。这是按经过验证的远程地址进行跟踪的,可以防止单个客户端通过频繁连接和断开快速耗尽服务器资源。可以通过endpointOptions.sessionCreationRate和endpointOptions.sessionCreationBurst进行配置。默认值(每秒50次,突发100次)对于正常流量模式已经足够宽松。如果在基准测试场景中流量来自单一源,可以提高这些值。
除了速率限制之外,该端点还通过 maxConnectionsPerHost 和 maxConnectionsTotal 支持并发连接限制,并且通过 endpoint.busy 提供忙碌模式,会拒绝所有新连接。
🌐 In addition to rate limiting, the endpoint supports concurrent connection
limits via maxConnectionsPerHost and maxConnectionsTotal, and a
busy mode via endpoint.busy that rejects all new connections.
可以通过端点的统计对象监控速率限制活动。每个速率限制器都有一个对应的计数器(例如 endpoint.stats.retryRateLimited、endpoint.stats.sessionCreationRateLimited),用来跟踪有多少响应被丢弃。非零值表示速率限制器正在积极保护端点。
🌐 Rate limiting activity can be monitored through the endpoint's statistics
object. Each rate limiter has a corresponding counter
(e.g., endpoint.stats.retryRateLimited,
endpoint.stats.sessionCreationRateLimited) that tracks how many responses
were dropped. A non-zero value indicates the rate limiter is actively
protecting the endpoint.