对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

智能工作负载管理

注意

本页面同时适用于 Atlas Infinite 和 Atlas Core。

即使在流量激增和昂贵的查询消耗的资源超出预期时,现代应用程序也必须保持可用。智能工作负载管理 (IWM) 是 MongoDB Atlas 托管的可用性功能,即使在过载情况下,也能让您的集群保持响应和可预测。

当集群接收的操作超过其资源所能处理的范围时,就会发生过载。过载的发展速度可能快于基础设施的扩展速度。即使启用了 自动伸缩,Atlas 也需要时间来预配额外的容量。如果集群以相同的方式处理所有操作,这会打开一个窗口,在此期间集群可能会变得不稳定。IWM 通过实时监控和响应工作负载峰值和资源压力来关闭该窗口。

IWM 是 Atlas 应用于所有运行 MongoDB 9.0 或更高版本的专用集群的过载保护系统。IWM 包括以下保护措施:

  • Always-on protections queue, slow down, and prioritize operations to prevent them from overwhelming the cluster. These protections form a baseline of defense against overload. To learn more, see Always-On Protections.

  • Load Shedding is an optional protection that rejects incoming database operations in response to sustained overload. To learn more, see Load Shedding.

Atlas applies a subset of these protections to each cluster, based on the cluster's tier, topology, MongoDB version, and Load Shedding configuration. To learn more, see Cluster and Version Requirements.

Always-on protections are the baseline set of IWM protections that Atlas applies to absorb overload and maintain availability. These protections run at all times, even when Load Shedding is disabled, and you can't turn them off. To learn which of these protections apply to your cluster, see Cluster and Version Requirements.

  • Ingress queueing: Atlas runs an ingress request rate limiter on each mongod process in your cluster, which determines how quickly each process admits operations for execution. When a traffic spike outlasts your cluster's reserved capacity, the rate limiter adds excess incoming operations to an ingress queue instead of letting them compete for resources with running operations. If resource use stays high, the rate limiter admits operations at a slower rate, so more operations wait in the queue. The rate limiter rejects operations only if you enable Load Shedding on your cluster.

    如果您的集群上启用了响应式自动伸缩,Atlas 会使用排队操作的速率来确定何时扩展您的集群。Atlas 在 Atlas 指标中将此速率报告为操作速率限制:排队操作。要了解更多信息,请参阅Atlas 如何扩展集群层。

  • 执行控制优先级:在过载期间,Atlas 可以通过降低背景任务和长时间运行操作的优先级,帮助短时间读取和写入继续进行。长时间运行的查询可能会耗时更长,无论其业务重要性如何。在负载较高时,Atlas 会首先减慢耗费、长时间运行或低优先级的操作。

  • 缓存驱逐和内存调优:Atlas 会调整集群使用内存和驱逐缓存数据的方式。当内存不足时,集群会以受控方式减慢速度,而不是耗尽内存或反复清除其最需要的数据。

  • 连接速率限制:在连接风暴期间,Atlas 以安全速率接纳新的客户端连接,并拒绝多余的连接请求,同时保留现有连接。要了解更多,请参阅 连接速率限制。

  • Write-blocking: On Atlas Core clusters, if the primary node runs critically low on free disk space, Atlas blocks write operations on the replica set. Atlas continues to serve reads while writes are blocked. Blocked write operations include delete operations, because deleting documents can temporarily increase used disk space. On sharded clusters, Atlas blocks only writes routed to the affected shard.

    节点的总磁盘大小决定了 Atlas 应用的阈值。下表列出了每个磁盘大小范围的阈值:

    磁盘总大小
    阈值

    8 GiB 到 20 GiB

    Atlas 将阻止写入,当可用硬盘空间低于 600 MiB 时。Atlas 在可用硬盘空间超过 900 MiB 时解除写入阻塞。

    20 GiB 到 1.25 TiB

    当可用磁盘空间降至总磁盘大小的 4% 以下时,Atlas 会阻塞写入。当可用磁盘空间超过总磁盘大小的 6% 时,Atlas 会解除对写入的阻塞。

    1.257600 TiB 或更大

    当可用磁盘空间删除 50 GiB 时,Atlas 会阻止写入。当可用磁盘空间超过 75 GiB 时,Atlas 会解除写入限制。

    要回收磁盘空间,请增加集群存储或启用存储自动伸缩。

    当 Atlas 阻止写入时,Atlas 日志会返回一个 MongoServerError,指示写入被阻止。错误代码和原因取决于集群的特征兼容性版本 (特征兼容性版本):

    • 对于 特征兼容性版本 为 9.0 或更高版本的集群,日志会返回类似于以下内容的 MongoServerError:Replica set writes blocked, reason: InsufficientDiskSpace。

    • 对于特征兼容性版本早于 9.0 的集群,日志会返回类似于以下内容的 MongoServerError:User writes blocked, reason: DiskUseThresholdExceeded。

    在 Atlas Infinite 集群上,当副本集上的逻辑数据大小接近集群的最大存储限制时,Atlas 会阻止写入。要了解有关 Atlas Infinite 集群存储限制的更多信息,请参阅管理 Atlas Infinite 集群上的存储。

Load Shedding is an IWM protection that rejects incoming database operations as early as possible to limit their impact on the cluster. Unlike IWM's always-on protections, Load Shedding is optional, so you can control whether Atlas applies it to your cluster. When enabled, Load Shedding engages only during sustained overload, after other protections can't relieve enough pressure.

As part of IWM's always-on protections, Atlas runs an ingress request rate limiter on each mongod process in your cluster. This rate limiter admits operations into the process at a controlled rate, and adds any operation requests that arrive faster than this rate to an ingress queue on that process.

当启用负载削减(Load Shedding)时,Atlas mongod会限制集群中每个 进程的入口队列大小。如果某个进程的队列已满时有操作到达,Atlas 会拒绝该操作并返回过载错误。这可以防止队列在持续过载期间变得过大。

When Load Shedding is disabled, Atlas doesn't bound the size of the ingress queue on any mongod process in your cluster or reject any operations that arrive faster than the rate limiter's admission rate. During sustained overload, each mongod process continues to add an unbounded number of operations to its queue, so operations take longer to complete.

如果您的集群上启用了响应式自动伸缩,Atlas 会使用负载削减拒绝的操作速率来确定何时扩展您的集群。Atlas 在 Atlas 指标的操作速率限制下将此速率报告为 Rejected Operations。要了解更多信息,请参阅Atlas 如何扩展集群层。

注意

限电与搜索限电是分开的。卸载会拒绝 mongod进程中的数据库操作。搜索减载会拒绝 mongot进程中的MongoDB搜索和MongoDB Vector Search 查询。这两种保护是独立的,因此配置其中一种保护不会影响另一种保护。要学习;了解详情,请参阅:

负载削减仅适用于运行M30+ MongoDB9.0 或更高版本的副本集集群。默认情况下,Atlas 将 负载削减设置 的值设置为 Atlas Managed,这允许 Atlas 控制集群的负载削减的有效状态。在 MongoDB 9.0 上,该省/市/自治区为 Disabled。

重要

启用后,负载削减 (Load Shedding) 可能会增加集群上的过载错误数量。要学习如何处理这些错误,请参阅 处理来自负载削减的过载错误。

要配置 Load Shedding 在您的集群上,请使用 Atlas 用户界面或 Atlas Administration API:

智能工作负载管理 (IWM) 在所有运行 MongoDB 9.0 或更高版本的专用集群上处于活动状态。IWM 不适用于免费集群或 Flex 集群。

When IWM is active on a cluster, Atlas applies a subset of IWM protections based on the cluster's tier, topology, MongoDB version, and Load Shedding configuration. The following table lists the protections that Atlas applies to each combination of cluster tier and topology on MongoDB 9.0 and later:

IWM 保护
M10 以及 M20 个集群
M30+ 副本集集群
M30+ 分片集群

入口排队

No

是

No

执行控制优先级

No

是

No

缓存逐出与内存调优

是

是

是

连接速率限制

是

是

是

写入阻塞

是

是

是

负载分载

No

Yes, when enabled

No

注意

MongoDB 9.0 的例外情况版本要求。

以下 IWM 保护在运行早于 9.0 的 MongoDB 版本的集群上启用:

  • 写入阻塞在运行 MongoDB 8.0 或更高版本的 M10+ 集群上处于活动状态。

  • 在运行 MongoDB 8.0 及更高版本的 M10+ 集群上,已启用 内存调优。

  • 缓存逐出 已在运行 MongoDB 8.3.3 或更高版本以上或 MongoDB 8.0.28 或更高版本以上的 M10+ 集群上启用。

  • 连接速率限制在运行以下 MongoDB 版本的 M10 和 M20 集群上处于活动状态:

    • 7.0.23 及更高版本 7.0.x版本

    • 8.0.12 及更高版本 8.0.x版本

    • 8.1.2 及更高版本 8.1.x版本

Atlas 提供了多个可观测性界面,用于显示 IWM 何时保护您的集群以及 Atlas 延迟或拒绝了哪些操作: