当集群接收的入站操作数量超过其资源可处理的数量时,就会发生负载过载,这可能会导致集群完全或接近完全的服务中断。负载削减是 智能工作负载管理 (IWM) 的一项功能,允许 Atlas 在长时间过载期间拒绝操作。要为集群配置负载卸载,请参阅 配置智能工作负载管理。
当负载削减 (Load Shedding) 拒绝某项操作时,您的应用程序可能会看到该操作出现一个带有 SystemOverloadedError 标签的新错误。此错误表明您的集群已过载并正在削减操作。
If you use a backpressure-aware client library, the client library recognizes these errors and retries the ones that are safe to retry. Your application still controls how long to keep retrying and when to shed load. To learn more, see Handle Overload Errors.
SystemOverloadedError 标签单独存在时,并不意味着该操作可以安全地重试。要确定负载错误是否可重试,请检查以下标签:
RetryableError- 操作未执行,可以安全地重试NoWritesPerformed- 服务器在执行任何写入操作之前拒绝了该操作
以下示例展示了当负载削减(Load Shedding)拒绝操作时 Atlas 返回的过载错误:
{ "ok": 0.0, "errmsg": "Request rejected: ingress operation rate limit exceeded", "code": 463, "codeName": "IngressOperationRateLimitExceeded", "errorLabels": ["SystemOverloadedError", "RetryableError", "NoWritesPerformed"] }
重要
如果过载错误不包含 RetryableError 标签,请确保操作是幂等的,并在重试前等待,以避免加剧过载。在重试逻辑中使用指数退避和抖动。
反压感知客户端库版本
反压感知型驱动程序和其他客户端端库会自动识别带有 SystemOverloadedError 标签的过载错误,并将其视为过载信号。如果错误具有导致重试的标签(包括 RetryableError 标签),则反压感知客户端端库会自动使用指数退避和抖动重试操作。
下表列出了具有反压感知功能的最早客户端库版本:
客户端库 | 最早的背压感知版本 |
|---|---|
C 驱动程序 | 2.5 |
C++ 驱动程序 | 4.6 |
.NET/C# 驱动程序 | 3.11 |
Go 驱动程序 | 2.9 |
Java (Sync) 驱动程序 | 5.12 |
Java Reactive Streams 驱动程序 | 5.12 |
Kotlin Coroutine 驱动程序 | 5.12 |
Kotlin Sync 驱动程序 | 5.12 |
Node.js 驱动程序 | 7.6 |
PHP库 | 2.5;需要 |
pymongo | 4.18 |
Scala 驱动程序 | 5.12 |
Ruby | 2.26 |
Rust | 3.9 |
处理过载错误
Handle overload errors in your application even if you use a backpressure-aware client library. Backpressure-aware client libraries retry operations labeled as retryable, but your application decides how long to keep retrying and when to shed load by abandoning operations that the cluster continues to reject. If you are not using a backpressure-aware client library, also implement the error detection and retry logic yourself.
请参阅以下过程,了解如何实现错误检测和带有指数退避的重试逻辑的示例,以处理标记为可重试的过载错误: