基于 Cloud pub/sub 队列自动缩放 GCE 实例组

Autoscaling GCE Instance groups based on Cloud pub/sub queue

GCE 实例组是否可以根据 Google Cloud PubSub 队列计数或其他异步任务队列(例如 PSQ)进行扩展 up/down?

我自己没有尝试过,但查看文档,似乎可以针对 Pub/Sub 消息队列计数设置自动缩放。

此页面 [0] 介绍了如何设置自动调节器以根据云监控服务提供的标准指标进行调节。

此页面 [1] 解释了您可以将哪些指标用于自动调节器。这两个看起来很有用:

pubsub.googleapis.com/subscription/num_outstanding_messages pubsub.googleapis.com/subscription/num_undelivered_messages

[0] https://cloud.google.com/compute/docs/autoscaler/scaling-cloud-monitoring-metrics [1] https://cloud.google.com/monitoring/api/metrics

您不能为此目的使用 pubsub 指标(pubsub.googleapis.com/subscription/num_outstanding_messages 或 pubsub.googleapis.com/subscription/num_undelivered_messages)。 根据文档:

A valid utilization metric for scaling meets the following criteria:

  1. The standard metric has a label for resource_id, and value of the label for each stream is ID of an instance.

  2. The standard metric describes how busy an instance is, and the metric value increases or decreases proportionally to the number virtual machine instances in the group.

pubsub 指标不符合该标准。

但是,您可以通过两种方式使用基于 pubsub 的自动缩放:

  1. 编写您自己的自定义指标 - 您可以使用 gcloud 监控 api 获取您的 pubsub 时间序列数据。比使用它来计算您自己的自定义监控指标 - 例如 - 最后一个时间序列值除以您的 average/desired 延迟。 您可以将此方法用于您正在使用的每个异步队列解决方案。

  2. 仍处于 alpha 阶段,有一个 gcloud api 用于基于订阅者的自动缩放:https://cloud.google.com/compute/docs/autoscaler/scaling-queue-based。此解决方案仅适用于 google 云 pubsub,不能与其他异步队列解决方案一起使用。

是的!

该功能现在处于 alpha 阶段:https://cloud.google.com/compute/docs/autoscaler/scaling-queue-based