Atlas使用自动伸缩进行集群计算,通过调整集群层来帮助您优化资源利用率和费用。Atlas使用存储自动伸缩来帮助您自动增加集群存储容量。
在本节中,您可以学习;了解:
集群层自动伸缩
Atlas对集群层使用响应式和预测式自动伸缩。Atlas会根据集群的类型、层级和工作负载模式选择自动伸缩机制。
Reactive auto-scaling. Atlas uses thresholds, and not prediction, to trigger scaling events based on current resource usage. Reactive auto-scaling occurs after sustained high or low resource usage. To learn more, see Reactive Auto-Scaling for Cluster Tier.
预测性自动伸缩。Atlas使用机器学习根据历史使用模式预测未来的扩展需求,并尝试在预测的工作负载峰值到来之前trigger扩展事件。
预测性自动伸缩是集群层自动伸缩的扩展,可以回退到反应式自动伸缩。Atlas继续依靠响应式自动伸缩来管理非周期性或不可预测的意外工作负载峰值。Atlas对符合条件的集群使用预测性自动伸缩。要学习;了解更多信息,请参阅集群层的预测性自动伸缩。
集群层的响应式自动伸缩
您可以配置 Atlas 使用的集群层范围,以根据集群使用情况自动扩展集群层和/或存储容量。
为了优化资源利用率并改善费用状况,Atlas反应式自动伸缩可检测持续较高的需求和短期峰值流量,并根据实时资源使用情况调整集群层。
为了帮助控制成本,您可以指定集群可自动伸缩到的最大和最小集群大小范围。
响应式自动伸缩以滚动方式运行,并且该进程不会导致任何停机。在此进程中, Atlas会维护一个主节点 (primary node in the replica set)节点,但节点会逐个升级,并且在升级时不可用。
要学习;了解可扩展性的建议,包括在使用具有响应式自动伸缩的基础架构即代码工具时避免资源漂移,请参阅Atlas架构中心的Atlas可扩展性建议。
符合条件的响应式自动伸缩集群
Atlas 集群层级响应式自动伸缩适用于 General 和 Low-CPU 集群类下的所有专用集群层。
Atlas 如何扩展集群层
注意
层可用性
响应式自动伸缩适用于 General 和 Low-CPU 类中的集群层,但 不 适用于 Local NVMe SSD 类中的集群。
Atlas依赖托管网络探测(ping)数据来做出自动扩展决策。无论是否启用了自动伸缩,专用集群数据节点都会持续将此网络探测(ping)数据发送到控制平面。启用自动伸缩后,如果满足扩展条件, Atlas可以立即使用这些历史数据进行扩展。
Atlas分析以下集群指标,以确定何时对集群进行响应式扩展,以及是扩展还是缩减集群层:
规范化系统 CPU 利用率
系统内存利用率
Atlas 会根据可用节点内存和总内存来计算系统内存利用率,如下所示:
(memoryTotal - (memoryFree + memoryBuffers + memoryCached)) / (memoryTotal) * 100
在前面的计算中,memoryFree、memoryBuffers 和 memoryCached 是 Atlas 可以回收用于其他目的的可用内存量。要了解更多信息,请参阅查看可用指标中的 System Memory(系统内存)部分。
注意
Atlas用于自动伸缩决策的 System Memory Utilization 值可能与Atlas指标面板中显示的值略有不同。
如果新的集群层超出指定的 Minimum 和 Maximum Cluster Size 范围,Atlas 不会扩展您的集群层。
Atlas 可将您的集群扩展到同一类中的其他层。例如,Atlas 可将 General 集群扩展到其他 General 集群类型,但不会将 General 集群扩展到 Low-CPU 集群类型。
为了确保适当的集群资源利用率,确切的响应式自动伸缩标准可能会发生变化。
重要
迁移期间,如果待恢复的快照大于目标集群的存储容量,则集群不会自动扩展。
响应式扩展集群层
为了管理应用程序的动态工作负载,Atlas会在本节描述的条件下扩展集群中的节点。
为了帮助您解释这些条件, Atlas使用以下 CPU 利用率概念:
基准 CPU 利用率:云提供商保证为您的实例提供完整 CPU 的比例,对于可突发实例类型,通常为 20%–50%。在Atlas指标中不可见。
绝对系统 CPU 利用率:所有内核的 CPU 总使用率的总和。在Atlas指标中显示为 System CPU。Atlas不会直接使用此值来制定自动伸缩决策。
Relative System CPU Utilization: The value Atlas uses for autoscaling decisions on
M10andM20clusters. Calculated as the Normalized System CPU value divided by the baseline CPU utilization. This value is not directly visible in Atlas metrics, and the baseline CPU percentage is not exposed in the metrics panel. To estimate it, divide your Normalized System CPU reading by a baseline value in the 20%–50% range typical of burstable instance types. Atlas caps this value at 100% even when the calculation exceeds it.
If the next cluster tier is within your Maximum Cluster Size range, Atlas scales operational nodes in your cluster up to the next tier if at least one of the following criteria is true for any cluster node of this type.
注意
以下列表将 CPU 相关标准分组在一起,然后是内存相关标准。在每个组中,标准按从最严格到最宽松的顺序排列,特定云提供商的标准如果存在,则优先显示。
M10和M20个集群:AWS. The average normalized Relative System CPU Utilization has exceeded 90% for the past 20 minutes and the average non-normalized Absolute System CPU Utilization for CPU steal has exceeded 30% for the past 3 minutes.
Azure. The average normalized Relative System CPU Utilization has exceeded 90% for the past 20 minutes and the average non-normalized Absolute System CPU Utilization for softIRQ has exceeded 10% for the past 3 minutes.
The average normalized Absolute System CPU Utilization has exceeded 90% of resources available to the cluster for the past 20 minutes.
The average normalized Relative System CPU Utilization has exceeded 75% of resources available to the cluster for the past one hour.
The average System Memory Utilization has exceeded 90% of resources available to the cluster for the past 10 minutes. To learn how Atlas calculates the amount of system memory utilization, see How Atlas Scales Cluster Tier.
过去一小时内,平均 System Memory Utilization 已超过集群可用资源的 75%。
注意
For
M10andM20tiers, Atlas bases CPU thresholds on the instance baseline CPU utilization rather than the standard 100% baseline. The baseline is not exposed in the Atlas metrics panel and can range from 20%–50% for burstable instance types. See the AWS burstable instances documentation for the Baseline CPU utilization per vCPU column. Using 20% as a lower-end estimate, the effective absolute CPU thresholds are at most:The 75% Relative System CPU Utilization threshold equals 15% absolute CPU (75% of 20%).
The 90% Relative System CPU Utilization threshold equals 18% absolute CPU (90% of 20%).
If a scale-up occurs when Normalized System CPU appears low, contact MongoDB Support.
M30+集群:过去 10 分钟内,平均Normalized System CPU已超过集群可用资源的 90%。
过去一小时内,平均 Normalized System CPU 已超过集群可用资源的 75%。
过去 10 分钟内,平均System Memory Utilization已超过集群可用资源的 90%。
过去一小时内,平均 System Memory Utilization 已超过集群可用资源的 75%。
这些阈值可确保集群在高负载时快速扩展,并且应用程序可以处理流量或使用量的峰值,从而保持性能和可靠性。
注意
The conditions in this section describe operational nodes. For analytics nodes on any cloud provider, Atlas scales them up to the next tier if the average Normalized System CPU or the System Memory Utilization has exceeded 75% of resources available to any cluster node for the past one hour.
例子
AWS M10 集群伸缩条件
考虑具有以下值的示例场景,看看Atlas如何评估扩展条件。基准 CPU 利用率在Atlas指标面板中不可见,对于可突发实例类型,范围可以是 20%–50%。您可以使用该范围内的任何值来估计上限和下限,此示例使用 20% 作为该范围的下限。
Normalized System CPU: 60%
CPU steal: 10%
评估条件:
Condition 1 (AWS): Requires average Relative System CPU Utilization > 90% for 20 minutes AND average CPU steal > 30% for 3 minutes.
相对 CPU:60% ÷ 20% = 300%,上限为 100%。已达到第一个阈值。
CPU 窃取为 10%,但不超过 30%。未达到第二个阈值。
结果:未满足。两个阈值都必须为 true。
条件 2:要求平均值 Normalized System CPU > 90%,持续 20 分钟。
标准化系统 CPU 为 60%,不超过 90%。
结果:未满足。
Condition 3: Requires average Relative System CPU Utilization > 75% for 1 hour.
相对 CPU:60% ÷ 20% = 300%,上限为 100%。
结果:满足。Atlas会触发自动伸缩。
为实现最佳资源利用率和成本配置,Atlas 会在以下情况下避免将集群扩展到下一个层级:
M10或M20集群在过去 20 分钟或 1 小时内已进行扩展,具体取决于阈值。M30+集群在过去 10 分钟或 1 小时内已进行扩展,具体取决于阈值。
例如,如果自 12:00 以来集群层没有发生变化,则当集群的当前标准化系统 CPU 利用率大于 90% 时,Atlas 将在 12:10 扩展 M30+ 集群。
重要
工作负载突然激增
扩展至更大的集群层需要足够的时间来准备后备资源。当集群接收到大量活动(如批量插入)时,可能不会进行自动伸缩。为了降低资源耗尽的风险,请计划在批量插入和其他工作负载高峰之前扩展集群。
注意
在模拟区域服务中断期间, Atlas不会trigger集群层自动伸缩。如果集群没有足够的健康节点来支持扩展操作,则在实际区域服务中断期间也可能会出现此行为。
响应式缩减集群层扩展
为了优化费用,Atlas会在本节描述的条件下以被动方式缩减集群中的节点。
如果下一个最低的集群层在 Minimum Cluster Size 范围内,并且指定集群类型的所有节点都满足以下所有条件,则 Atlas 会将集群中的节点缩减到下一个最低层:
注意
Atlas从启用缩减的那一刻起就开始检查这些条件,而不是追溯检查。即使您的集群在启用缩减之前满足这些条件, Atlas不会扩展,直到启用该功能后经过了所需的时间窗口。
所有节点:
Atlas 在过去的 24 小时内没有缩小集群(无论是手动还是自动)。
在过去 24 小时内,Atlas 没有预配或恢复集群的运行。
Atlas在过去 12 小时内未停止和重新启动任何集群节点。
至少在过去 10 分钟 和 过去 4 小时内,平均 Normalized System CPU 低于集群可用资源的 45%。Atlas使用“4 小时平均值”检查点来指示 CPU 负载已稳定在观察到的水平上。Atlas使用“10 分钟平均”检查点作为指标,表明最近没有发生任何 CPU 峰值,而Atlas未使用“4 小时平均”检查点捕获。
注意
For
M10andM20tiers, Atlas applies the 45% CPU threshold relative to the instance baseline CPU utilization rather than the standard 100% baseline. Using 20% as a lower-end estimate, the effective absolute CPU threshold for scale-down is approximately 9% (45% of 20%).The average WiredTiger cache usage is below 90% of the maximum WiredTiger cache size for at least the last 10 minutes AND the last 4 hours at the current cluster tier size. This indicates to Atlas that the current cluster isn't overloaded.
在新的较低集群层水平,预计总系统内存利用率在至少过去 10 分钟和过去 4 小时内低于 60%。Atlas 按如下方式计算前面语句中提到的预计总内存使用量。
Atlas measures the current memory usage and replaces the current WiredTiger cache usage size with 80% of the WiredTiger cache size on the new lower tier cluster.
接下来,Atlas 会检查在新的层级大小水平上,预计总内存使用量是否至少在过去 4 小时和 10 分钟内低于 60%。
注意
Atlas在其内存计算中包含WiredTiger缓存,以使缓存已满但流量较低的集群更有可能扩展。此检查应用两个阈值:
90%:当前层级的WiredTiger缓存使用率必须低于其最大大小的 90%。如果超过此限制, Atlas将不会扩展。
60%:新的较低层级上的预计总内存必须低于 60%。为了计算此投影, Atlas假设新层级上的WiredTiger缓存使用率为该层最大缓存大小的 80%。
这些条件可确保 Atlas 缩减集群中的操作节点,防止出现高利用率状态。
注意
Atlas evaluates memory-based scaling using a projected metric that differs from the System Memory Utilization shown in the Atlas UI. If a scale-down does not occur when System Memory Utilization appears low, contact MongoDB Support.
- 过去 24 小时的平均 Normalized System CPU 和 System Memory Utilization 低于集群可用资源的 50%。
注意
M10和M20集群使用较低的阈值来考虑云提供商在突发周期后设置的 CPU 使用上限。这些阈值因您的云提供商和集群层而异。
扩展分片集群
Atlas 使用与副本集相同的条件自动伸缩分片集群的集群层。Atlas 会应用以下规则:
默认下,为具有自动伸缩的分片的集群启用独立分片扩展。启用独立分片扩展后, Atlas中的自动伸缩功能会独立评估和扩展每个分片。独立分片扩展要求最小分片大小不小于最大分片以下的两个集群层,以保持可用性和性能。如果Atlas为此类集群触发自动伸缩,并扩展最大的分片,它还会在必要时扩展较小的分片,以确保一致的可用性和性能。
如果分片内的操作或分析节点满足自动伸缩的条件,则只有该特定分片上的操作或分析节点会更改层级。
The Config server replica set doesn't auto-scale. However, a Config Shard does auto-scale.
Scaling a Gen2 Dedicated Cluster
Atlas auto-scales the cluster tier for Gen2 Dedicated clusters using the same criteria as replica sets. Atlas applies the following rules:
Your cluster's current tier, minimum auto-scaling bound, and maximum auto-scaling bound must all be within the same generation.
M10和M20集群与代际无关。Atlas 可以将M10或M20集群自动伸缩为 Gen1 或 Gen2 集群。For example, if the maximum auto-scaling bound is a Gen1 cluster tier, Atlas auto-scales the cluster into Gen1. If the maximum auto-scaling bound is a Gen2 cluster tier, Atlas auto-scales the cluster into Gen2. You can also use
M10orM20as the minimum auto-scaling bound for both Gen1 and Gen2 clusters.
如果您尝试执行以下任一操作,Atlas Administration API 将返回 INVALID_ATTRIBUTE 错误:
将集群的代际更改为与该集群自动伸缩边界的代际不同的代际。
将集群的自动伸缩边界设置为一个属于不同代际的
M30+层级集群。
注意
Switching Cluster Generation for GCP-hosted Clusters
Clusters hosted on Google Cloud use different disk types depending on their cluster generation:
Gen1,
M10, andM20clusters use Persistent Disk storage.Gen2 clusters use Hyperdisk storage.
To learn more, see Storage Options in the Google documentation.
Autoscaling a Google Cloud-hosted cluster from an M10 or M20 cluster to a Gen2 cluster or vice versa requires Atlas to move your data across these disk types. This may take longer than autoscaling an M10 or M20 cluster to and from a Gen1 cluster.
集群层的预测性自动伸缩
预测性自动伸缩是自动伸缩的扩展。
Atlas使用需求预测来预测托管资源利用率,并先发制人地扩展集群计算,以确保实现最佳资源利用率。通过预测性自动伸缩,Atlas尝试在周期性工作负载峰值之前主动扩展集群。
预测性自动伸缩由...提供支持基于历史模式的机器学习模型提供支持。Atlas分析主节点 (primary node in the replica set)节点上的资源利用率以做出扩展决策。该模型根据历史使用模式预测资源利用率何时较高,如果模型预测资源利用率较高,则Atlas会扩展集群。MongoDB不断更新模型及其标准,以优化Atlas性能。
该模型分析滚动的 4 周输入窗口,以确定周期性模式。可以捕获在此窗口内可观察到的任何模式,示例每小时、每天、每周或每两周一次的周期。周期较长的模式(例如月度或季度周期)位于 4 周窗口之外,因此无法检测到。
注意
对于接近窗口上限的模式,精度可能会降低,因为窗口内出现的完整周期较少。
预测性自动伸缩对于具有预测性、周期性工作负载的集群具有以下好处:
在 4 周的输入窗口内针对周期性工作负载模式自动扩展集群。
在可预测的高需求期间保持一致的性能和可用性。
让Atlas托管容量增加,从而减少手动扩展任务或计划脚本。
当集群工作负载的变更超出可预测模式且非周期性或不可预测时,无缝回退到响应式自动伸缩。
要触发预测性自动伸缩,您的集群必须连续维护活动日志两周。一旦满足此标准,系统就会启用预测性自动伸缩。
注意
如果暂停集群,则预测性自动伸缩需要连续两周的活动才能恢复。
预测性自动伸缩的行为
以下声明描述了预测性自动伸缩的工作原理:
Atlas会尝试在预测负载到达之前扩展集群实例大小。
当Atlas根据预测指标对集群进行预测性扩展时,它一次最多可以扩展两个层级。
预测性自动伸缩仅应用于计算,不应用于存储。
预测性自动伸缩遵循现有自动伸缩的最小和最大实例大小。
当Atlas无法使用预测性自动伸缩来扩展集群时,它会转而使用响应式自动伸缩。
预测性自动伸缩仅支持升级。不存在预测性扩展缩减。Atlas使用响应式自动伸缩,在工作负载减少时自动扩展集群规模。
如果预测性扩展计划在下一个 1 小时内进行,Atlas会跳过被动式下行扩展。
如果您使用独立分片扩展,并在集群上启用并激活预测性自动伸缩后添加一个或多个分片,则这些新分片不会进行预测性自动伸缩,直到两周后,即确定其工作负载模式。同时,这些分片在Atlas中使用响应式自动伸缩行为。
符合预测性自动伸缩条件的集群
Atlas对符合条件的集群使用预测性自动伸缩。符合预测性自动伸缩的集群必须满足以下所有条件:
属于 General 和 Low-CPU集群类。
具有
M30或更高的层级。启用自动伸缩。如果启用缩减,自动伸缩的最小实例大小应等于或大于
M30。已活跃至少两周。
不使用NVMe 存储或不属于 Local NVMe SSD集群类。
Not be a Gen2 Dedicated Cluster.
此外,以下条件会影响Atlas是否对符合条件的集群使用预测性自动伸缩:
预测性自动伸缩仅应用于可选节点和只读节点。Atlas 不会对搜索或分析节点使用预测性自动伸缩。
预测性自动伸缩可能无法预测任何符合条件的集群中的非周期性和高度动态的工作负载峰值。在这些情况下,Atlas依赖于响应式自动伸缩。
Atlas 如何扩展集群存储
Atlas 默认启用集群存储自动扩展。当集群中任何节点的磁盘空间使用率达到 90% 时,Atlas 会自动增加集群存储。
要选择退出集群存储扩展,请取消选中 Auto-scale(存储扩展)部分中的 Storage Scaling(存储扩展)复选框。
以下注意事项适用:
Atlas仅自动伸缩向上集群存储。您可以在“编辑集群”页面中手动减少集群存储。
On AWS, Azure, and GCP clusters, Atlas increases cluster storage capacity to achieve 70% disk space used. To learn more, see Change Storage Capacity or IOPS on AWS, Change Storage Capacity and IOPS on Azure, and Change Storage Capacity on Google Cloud.
如果您计划扩展集群,请避免高速写入活动。将集群扩展到更大的存储容量需要足够时间来准备数据并将其复制到新磁盘。如果集群突然出现高速写入活动(如批量插入),由于磁盘存储容量暂时激增,可能无法进行自动扩展。为了降低磁盘存储空间不足的风险,请计划在批量插入和其他高速写入活动实例之前扩展集群。
Atlas disables disk auto-scaling if you specify one cluster tier class for the base nodes and another, different cluster tier class for the analytics nodes. For example, if you specify a General cluster class for operational nodes in the Base Tier, and a Low-CPU cluster class for analytics nodes in the Analytics Tier, Atlas disables disk auto-scaling with the following error message:
Disk auto-scaling is not yet available for clusters with mixed instance classes.触发磁盘自动伸缩后,后续的磁盘自动伸缩和手动磁盘扩展可能在几个小时内不可用。
集群层和集群存储可以并行伸缩
作为自动伸缩的一部分,当Atlas尝试自动扩展集群存储容量时,它可能需要将存储扩展到当前集群层支持的范围之外。为了帮助确保您的集群不会出现任何停机,Atlas会扩展您的集群层(除了集群存储之外)以适应新的存储容量。
注意
在自动伸缩事件中,如果当前层级没有所需的存储容量,Atlas 即使禁用 Cluster Tier Scaling,也可能会提高集群层。
On Azure, if you enable auto-scaling on a cluster deployed in one of the regions that support Extended Storage/IOPS, and the current IOPS is lower than the default IOPS for the auto-scaled disk size, Atlas increases the alloted number of IOPS in the IOPS slider and notifies you in the UI. To learn more, see Configure Extended Storage/IOPS on Azure.
例子
The maximum storage capacity for an M30 cluster is 480 GB. If you have an M30 cluster with the maximum storage allocated and your disk space used reaches 90%, a storage auto-scaling event requires raising your storage capacity to 600 GB. In this case, Atlas scales your cluster tier up to M40 because this is the lowest cluster tier that can support the new required storage capacity. On Azure, if you deployed the cluster in one of the regions that support Extended Storage/IOPS, Atlas also automatically increases IOPS to match the IOPS level for that tier's cluster. To learn more, see Configure Extended Storage/IOPS on Azure.
如果您指定的最大群集层无法支持新的存储容量,Atlas 会:
将最大集群层提升到可容纳新存储容量的下一个最低层。
将集群层扩展至新的最高层。
注意
当Atlas覆盖您的最大集群层时,它还会为您的集群禁用自动扩展。要重新启用向下自动伸缩,请在集群设置中进行配置。另请参阅集群层向下扩展的注意事项。
如果 Atlas 尝试缩减您的集群层,而目标层无法支持您当前的磁盘容量和/或预配的 IOPS,则 Atlas 不会缩减您的集群。在这种情况下,Atlas 会根据当前集群层与配置的最大集群层之间的关系来更新您的自动伸缩设置:
如果集群当前处于配置的最大集群层,Atlas 会禁止集群自动缩小规模,因为所有较小的层将无法容纳必要的存储设置。如果要重新启用向下自动伸缩,则必须在群集设置中手动执行此操作。
如果集群当前未处于配置的最大集群层,Atlas 会将最小集群层提升至当前集群层。在这种情况下,Atlas 不会禁用向下自动伸缩。
当存储设置与工作负载不匹配时,这种自动扩展逻辑可减少停机时间。
Oplog 注意事项
Atlas 会根据最小 oplog 保留窗口或 oplog 大小来管理 oplog 条目,具体取决于您是否选择使用存储自动伸缩。要了解详情,请参阅 Oplog 大小行为。Atlas 默认启用存储自动伸缩。
集群层扩展缩减的注意事项
您可以在“编辑集群”页面中手动减少集群层。手动扩展集群层时,应用以下事项:
估算部署的工作负载范围,然后将 Minimum Cluster Size 的值设置为具有足够容量来处理部署工作负载的集群层。请考虑集群活动中任何可能的峰值或低谷。
您无法扩展到小于
M10的集群层。您选择的最低集群层不能低于集群的当前磁盘配置。如果您的存储增加超出了最低集群层支持的范围,并且Atlas增加的集群存储配置超出了最低集群层支持的范围,则Atlas会自动将您的最低集群层调整到支持集群当前存储要求的层级。
例子
您已将自动伸缩边界设立为
M20-M60,当前集群层为M40,磁盘容量为 200 GB。Atlas 会触发磁盘自动伸缩事件,将容量增加到 320 GB ,因为当前磁盘使用量超过 180 GB,即超过 200 GB容量的 90%。Atlas采取以下行动:
将集群层级下限提升到可容纳新存储容量的下一个最低层级
M30。M20支持的最大存储容量为 256GB,因此它不再是有效的自动伸缩限制。确定当前实例大小
M40支持新的磁盘配置。磁盘自动伸缩事件成功。
配置自动伸缩选项
在创建或修改集群时,您可以配置自动伸缩选项。对于新集群,Atlas 会自动启用集群层自动伸缩和存储自动伸缩。
您可以执行下列操作之一:
查看并调整 Atlas 在自动扩展集群时应使用的集群层上限和下限,或者
选择退出,不使用自动缩放。
Atlas 会在集群构建器的 Auto-scale 部分显示 General 和 Low-CPU 层集群的自动伸缩选项。
默认启用自动伸缩
创建新集群时,Atlas会为集群层和集群存储启用自动伸缩(预测性和响应性)。(预测性自动伸缩仅影响集群层,不影响存储。)您无需显式启用自动伸缩。如果您愿意,可以 选择退出 集群层和集群存储。
注意
Atlas enables cluster tier auto-scaling by default when you create clusters in the Atlas UI. If you create clusters with the API cluster auto-scaling isn't selected by default and you must explicitly enable it, using the options in the autoScaling object of the Update One Cluster in One Project endpoint.
启用自动伸缩后,您的集群可以自动执行以下操作:
根据集群和工作负载负载资格,使用反应性或预测性自动伸缩,通过更高的集群层进行扩展以增加功能。
使用 响应式自动伸缩将当前集群层降低到较低的集群层。
在Auto-scale选项的Cluster tier部分中,您可以指定集群可自动扩展到的Maximum Cluster Size和Minimum Cluster Size值。Atlas 会按以下方式设置这些值:
已将Maximum Cluster Size设为当前集群层的上一层级。
已将 Minimum Cluster Size(最小集群大小)设为当前集群层。
此外,如果您的集群符合条件并且其工作负载是周期性且可预测的,Atlas可能会使用预测性自动伸缩。
使用 Atlas CLI 和 Atlas 管理 API 启用自动伸缩。
在使用 Atlas CLI 或 Atlas 管理 API 创建或更新集群时,您可以为计算和存储启用自动伸缩。以下示例展示了如何为可选举节点和分析节点启用自动伸缩。将集群层和业务设置替换为您需要的设置。
要使用 Atlas CLI 配置自动伸缩,请创建包含自动伸缩配置的 JSON 文件,然后根据 atlas api clusters updateCluster 命令的说明指定该配置。
使用 atlas api clusters updateCluster 命令直接调用 API 并在现有集群上启用自动伸缩设置。要在创建新集群时启用自动伸缩,请使用 atlas api clusters createCluster 命令。
创建有效载荷文件。
创建一个包含以下内容的 payload.json 文件。将占位符值替换为您的特定集群配置:
{ "replicationSpecs": [ { "regionConfigs": [ { "providerName": "{CLOUD-PROVIDER}", "regionName": "{REGION-NAME}", "priority": 7, "electableSpecs": { "instanceSize": "{INSTANCE-SIZE}", "nodeCount": 3 }, "analyticsSpecs": { "instanceSize": "{ANALYTICS-INSTANCE-SIZE}", "nodeCount": 1 }, "autoScaling": { "compute": { "enabled": true, "scaleDownEnabled": true, "minInstanceSize": "{MIN-INSTANCE-SIZE}", "maxInstanceSize": "{MAX-INSTANCE-SIZE}" }, "diskGB": { "enabled": true } }, "analyticsAutoScaling": { "compute": { "enabled": true, "scaleDownEnabled": true, "minInstanceSize": "{MIN-ANALYTICS-INSTANCE-SIZE}", "maxInstanceSize": "{MAX-ANALYTICS-INSTANCE-SIZE}" }, "diskGB": { "enabled": true } } } ] } ] }
您可以使用 Atlas 管理 API,通过在请求正文中指定自动伸缩配置来启用自动伸缩。
Use the Update One Cluster in One Project endpoint to enable auto-scaling by including the autoScaling object.
注意
This curl command uses a service account access token (OAuth 2.0) to authenticate instead of API keys. To learn more, see Get Started with the Atlas Administration API.
curl --header "Authorization: Bearer {ACCESS-TOKEN}" \ --header "Accept: application/vnd.atlas.2025-03-12+json" \ --header "Content-Type: application/json" \ --include \ --request PATCH "https://cloud.mongodb.com/api/atlas/v2/groups/{GROUP-ID}/clusters/{CLUSTER-NAME}" \ --data '{ "replicationSpecs": [ { "regionConfigs": [ { "providerName": "{CLOUD-PROVIDER}", "regionName": "{REGION-NAME}", "priority": 7, "electableSpecs": { "instanceSize": "{INSTANCE-SIZE}", "nodeCount": 3 }, "autoScaling": { "compute": { "enabled": true, "scaleDownEnabled": true, "minInstanceSize": "{MIN-INSTANCE-SIZE}", "maxInstanceSize": "{MAX-INSTANCE-SIZE}" }, "diskGB": { "enabled": true } }, "analyticsSpecs": { "instanceSize": "{ANALYTICS-INSTANCE-SIZE}", "nodeCount": 1 }, "analyticsAutoScaling": { "compute": { "enabled": true, "scaleDownEnabled": true, "minInstanceSize": "{MIN-ANALYTICS-INSTANCE-SIZE}", "maxInstanceSize": "{MAX-ANALYTICS-INSTANCE-SIZE}" }, "diskGB": { "enabled": true } } } ] } ] }'
查看集群层自动伸缩选项
要查看已为集群层和存储启用的自动伸缩选项,请执行以下操作:
选择退出集群层自动伸缩
要选择退出集群自动伸缩(增加集群层),请在创建新集群时导航到 Cluster Tier(集群层)菜单,然后取消选中 Auto-scale(自动伸缩)部分中的 Cluster Tier Scaling(集群层伸缩)复选框。
要选择禁用集群自动缩放(降低集群层),请在创建新集群时导航至 Cluster Tier(集群层)菜单,然后取消选中 Auto-scale(自动伸缩)部分的 Allow cluster to be scaled down(允许集群缩减)复选框。
查看自动伸缩活动提要
您可以查看操作日志,以查看每个Atlas项目的事件。发生任何自动伸缩事件时,Atlas都会将该事件日志在项目Activity Feed中。
Atlas使用以下Atlas 审核自动伸缩事件。
操作日志中的每个自动伸缩事件都包含有关触发扩展动作的原因的详细信息,包括:
触发自动伸缩事件的特定指标(例如 CPU 利用率、内存使用量或磁盘空间)。
超过的阈值。
扩展是由反应式自动伸缩(响应当前资源使用情况)还是预测性自动伸缩(预期预测需求)触发的。
要仅查看或下载自动扩展事件,请执行以下操作:
在 Atlas 中,前往 Project Activity Feed 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含所需项目的组织。
如果尚未显示,请从导航栏的Projects菜单中选择所需的项目。
在侧边栏中,单击 Security 标题下的 Activity Feed。
显示项目操作日志页面。
使用 Terraform 中的有效字段增强自动伸缩
注意
此功能仅适用于 M10层级及以上的专用集群,Flex 集群不支持此功能。
在集群上启用自动伸缩后, Atlas会根据工作负载自动调整实例大小和存储容量。
如果使用MongoDB和 HashiCorp Terraform进行集群实例大小调整和存储配置,则可以为集群大小调整值的子集指定有效字段。我们建议采用这种方法:
规范属性与您在 Terraform 配置中定义的完全相同。
默认值和自动伸缩值在有效规范中可单独使用(示例
effectiveElectableSpecs),并且当Atlas自动伸缩集群时,不会发生资源漂移。您的配置保持简洁并代表您的意图,而有效的规范则显示Atlas所预配的内容的实际情况。
有效字段仅忽略对由特定类型的自动伸缩托管的字段的更改。下表详细说明了启用有效字段和特定类型的自动伸缩时忽略的字段:
已启用的自动伸缩类型 | specs | 忽略的字段 | 节点类型 |
|---|---|---|---|
计算或存储 |
|
| |
计算或存储 |
|
| |
分析 |
|
|
You cannot use effective fields for search nodes.
启用有效字段
要启用有效字段,请在API请求中包含以下标头:
--header "Use-Effective-Instance-Fields: true"
在集群的资源定义中将 use_effective_fields 参数设置为 true,如以下示例所示:
resource "mongodbatlas_advanced_cluster" "this" { project_id = mongodbatlas_project.this.id name = var.cluster_name cluster_type = var.cluster_type use_effective_fields = true replication_specs = var.replication_specs tags = var.tags }
要学习;了解更多信息,请参阅有效字段模块示例。
重要
如果不启用有效字段,则必须手动配置 lifecycle.ignore_changes区块,以防止发生自动伸缩时出现资源漂移。我们不建议使用这种方法。要学习;了解更多信息,请参阅 Terraform 文档中的自动伸缩。
有效字段的行为
总体而言,有效字段行为属于以下三种情况之一:
注意
我们建议最佳实践是启用有效字段。
{ "replicationSpecs": [ { "regionConfigs": [ { "analyticsAutoScaling": { "compute": { "maxInstanceSize": "M30", "minInstanceSize": "M10", "enabled": true, "scaleDownEnabled": true }, "diskGB": { "enabled": true } }, "autoScaling": { "compute": { "maxInstanceSize": "M30", "minInstanceSize": "M10", "enabled": true, "scaleDownEnabled": true }, "diskGB": { "enabled": true } }, "effectiveAnalyticsSpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 0 }, "effectiveElectableSpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 3 }, "effectiveReadOnlySpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 0 }, "electableSpecs": { "instanceSize": "M20", "diskSizeGB": 50.0, "nodeCount": 3 }, "priority": 7, "providerName": "AWS", "regionName": "US_EAST_1" } ], "zoneId": "6924a70c67695449ba5625ce", "zoneName": "Zone 1" } ] }
注意
我们建议最佳实践是启用有效字段。
{ "replicationSpecs": [ { "regionConfigs": [ { "effectiveAnalyticsSpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 0 }, "effectiveElectableSpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 3 }, "effectiveReadOnlySpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 0 }, "electableSpecs": { "instanceSize": "M30", "diskSizeGB": 100.0, "nodeCount": 3 }, "priority": 7, "providerName": "AWS", "regionName": "US_EAST_1" } ], "zoneId": "6924a70c67695449ba5625ce", "zoneName": "Zone 1" } ] }
重要
如果不启用有效字段,则必须手动配置 lifecycle.ignore_changes区块,以防止发生自动伸缩时出现资源漂移。我们不建议使用这种方法。要学习;了解更多信息,请参阅 Terraform 文档中的自动伸缩。
{ "replicationSpecs": [ { "regionConfigs": [ { "analyticsAutoScaling": { "compute": { "maxInstanceSize": "M30", "minInstanceSize": "M10", "enabled": true, "scaleDownEnabled": true }, "diskGB": { "enabled": true } }, "autoScaling": { "compute": { "maxInstanceSize": "M30", "minInstanceSize": "M10", "enabled": true, "scaleDownEnabled": true }, "diskGB": { "enabled": true } }, "effectiveAnalyticsSpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 0 }, "effectiveElectableSpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 3 }, "effectiveReadOnlySpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 0 }, "analyticsSpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 0 }, "electableSpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 3 }, "readOnlySpecs": { "instanceSize": "M30", "diskIOPS": 3000, "diskSizeGB": 100.0, "ebsVolumeType": "STANDARD", "nodeCount": 0 }, "priority": 7, "providerName": "AWS", "regionName": "US_EAST_1" } ], "zoneId": "6924a70c67695449ba5625ce", "zoneName": "Zone 1" } ] }
使用有效字段调整自动伸缩范围
If you enable effective fields, Atlas validates any new auto-scaling range against the cluster's current effective instance size. Atlas rejects a request that sets a range that doesn't contain the current effective instance size. This behavior applies to operational nodes and analytics nodes that use auto-scaling.
在以下任何一种情况下,请求将因验证错误而失败:
新的最小实例大小大于有效实例大小。
新的最大实例大小小于有效实例大小。
如果新范围仍然包含当前有效实例大小,则可以在单个请求中更改界限。
如果当前有效实例大小超出新范围,请在更改边界之前使用以下过程将其移入新范围。如果您在范围更改时在同一请求中更新实例大小,则在使用有效字段启用自动伸缩时, Atlas不会应用新的实例大小,因此请求仍然会失败。
To adjust the auto-scaling range with Terraform, see Adjusting the Auto-Scaling Range with use_effective_fields in the Terraform provider documentation.
配置自动扩展事件警报
重要
在 2024 年 8 月初,Atlas 使用可配置的自动扩展事件替换了旧版自动扩展通知电子邮件。默认情况下,Atlas 会继续向项目所有者发送所有警报通知。您可以自定义自动扩展警报分配以更改警报接收者或分配方法。
自动伸缩活动是 Atlas 警报的子集。
每次Atlas触发任何自动伸缩事件时,您都会收到默认的Atlas警报。
您可以在项目级别选择退出或更改部分或全部自动扩展事件的警报配置。
重要
自动伸缩警报应用于项目中的所有集群。您无法将警报范围限定为特定集群。警报通知通过集群名称和ID识别哪个集群触发了事件。
要修改警报配置,请在 Category 部分中选择 Atlas Auto Scaling,然后从列表中选择 Condition/Metric。然后,您可以修改警报接收者的角色,更改通知方法(例如电子邮件或短信)以及添加通知程序,例如Slack。要学习;了解更多信息,请参阅配置自动伸缩警报。
MongoDB对Atlas自动伸缩的支持
如果您有任何问题或顾虑,联系支持。