Google Compute Engine 根据队列长度自动缩放

Google Compute Engine auto scaling based on queue length

我们在 Google Compute Engine 上托管我们的基础设施,并正在研究实例组的自动缩放。我们对队列中的二进制数据进行了大量批处理。在我们的例子中,这意味着:

  1. 当工作人员处理数据时,CPU 始终是 100%
  2. 当队列为空时我们要终止所有worker
  3. 根据队列的长度,我们需要一定数量的工人

但是我发现很难想出一种在 Google Compute Engine 上自动缩放它的方法,因为它们似乎是根据 CPU 等仅实例指标进行缩放的。来自 documentation:

Not all custom metrics can be used by the autoscaler. To choose a valid custom metric, the metric must have all of the following properties:

  • The metric must be a per-instance metric.
  • The metric must be a valid utilization metric, which means that data from the metric can be used to proportionally scale up or down the number of virtual machines.

如果我正确阅读了文档,这会导致很难在全局队列长度上使用自动缩放吗?

备份方案

  1. 使用 Google Cloud API 编写一个简单的自动缩放处理程序,以使用 Instances API
  2. 创建或销毁新的 worker
  3. 使用实例组编写一个简单的自动缩放处理程序,然后使用 InstanceGroups: insert
  4. 手动 insert/remove 个实例
  5. 使用 InstangeGroupManagers: resize
  6. 编写一个简单的自动缩放处理程序
  7. 创建一个自定义的每个实例指标,该指标衡量 len(queue)/len(workers) 所有工作人员

据我了解,这尚未实施(截至 2016 年 1 月)。目前,自动缩放仅针对 Web 服务场景,您希望从您的机器提供 Web pages/other Web 服务并为峰值保留一些合理的余量(例如 CPU 或其他指标)交通。然后系统会调整instances/VMs的数量来匹配你的目标。

您正在为批处理场景寻找自动缩放,目前不满足此要求。

截至 2018 年 2 月(测试版),这可以通过 stackdriver 中的 "Per-group metrics" 实现。

Per-group metrics allow autoscaling with a standard or custom metric that does not export per-instance utilization data. Instead, the group scales based on a value that applies to the whole group and corresponds to how much work is available for the group or how busy the group is. The group scales based on the fluctuation of that group metric value and the configuration that you define.

更多信息请见https://cloud.google.com/compute/docs/autoscaler/scaling-stackdriver-monitoring-metrics#per_group_metrics

此处的操作方法太长 post。