扩展 Google 云拉订阅者
Scaling Google Cloud Pull subscribers
我正在考虑 Google 云 Pub/Sub 并试图确定我是否会选择 Pull or Push 订阅者模型。
值得注意的是,拉模型能够处理更大的吞吐量
Large volume of messages (many more than 1/second)
Efficiency and throughput of message processing is critical.
但是,推送模型可以位于 HTTP 负载平衡器之后,因此能够在排队消息的数量超过单个订阅者节点的容量时自动扩展订阅者节点。
拉模型也更安全,因为它不需要在 HTTP 端点中公开敏感操作。
问题是我们如何在拉模型中扩展订阅者节点? GCP 中有针对这种情况的东西吗?
拉取订阅时,您需要连接到订阅。对于最低延迟,需要全时连接。所以,你可以用计算引擎来做到这一点。
您的计算机拉取您的队列并使用消息。在大量消息的情况下,计算引擎资源(CPU 和内存)将增加。您可以将此计算放入 manage instance group (MIG) 并设置可伸缩性阈值,例如 CPU 使用的数量。
当然,消息拉取在网络带宽和协议握手方面效率更高。但是,它需要一个计算全职,并且可扩展性速度很慢。
如果考虑Push订阅,当然HTTPS协议占用带宽多,效率不高,但可以将消息推送到Cloud 运行或Cloud Functions。可伸缩性非常有弹性,并且基于流量(推送的消息数量)而不是 CPU 使用率。
此外,您可以将 pubsub 消息安全地推送到 CLoud Functions 和 Cloud 运行 by using the correct identification in your pubsub subscription
通过拉取订阅者有多种自动缩放选项:
- 使用 GKE 并设置 Autoscaling Deployments with Cloud Monitoring Metrics. This allows you to scale the number of instances based on the num_undelivered_messages metric。
- 使用 GCE 托管实例组和 scale based the num_undelivered_messages metric。
- 使用Dataflow to process messages from Pub/Sub and set up autoscaling.
我正在考虑 Google 云 Pub/Sub 并试图确定我是否会选择 Pull or Push 订阅者模型。
值得注意的是,拉模型能够处理更大的吞吐量
Large volume of messages (many more than 1/second)
Efficiency and throughput of message processing is critical.
但是,推送模型可以位于 HTTP 负载平衡器之后,因此能够在排队消息的数量超过单个订阅者节点的容量时自动扩展订阅者节点。
拉模型也更安全,因为它不需要在 HTTP 端点中公开敏感操作。
问题是我们如何在拉模型中扩展订阅者节点? GCP 中有针对这种情况的东西吗?
拉取订阅时,您需要连接到订阅。对于最低延迟,需要全时连接。所以,你可以用计算引擎来做到这一点。
您的计算机拉取您的队列并使用消息。在大量消息的情况下,计算引擎资源(CPU 和内存)将增加。您可以将此计算放入 manage instance group (MIG) 并设置可伸缩性阈值,例如 CPU 使用的数量。
当然,消息拉取在网络带宽和协议握手方面效率更高。但是,它需要一个计算全职,并且可扩展性速度很慢。
如果考虑Push订阅,当然HTTPS协议占用带宽多,效率不高,但可以将消息推送到Cloud 运行或Cloud Functions。可伸缩性非常有弹性,并且基于流量(推送的消息数量)而不是 CPU 使用率。
此外,您可以将 pubsub 消息安全地推送到 CLoud Functions 和 Cloud 运行 by using the correct identification in your pubsub subscription
通过拉取订阅者有多种自动缩放选项:
- 使用 GKE 并设置 Autoscaling Deployments with Cloud Monitoring Metrics. This allows you to scale the number of instances based on the num_undelivered_messages metric。
- 使用 GCE 托管实例组和 scale based the num_undelivered_messages metric。
- 使用Dataflow to process messages from Pub/Sub and set up autoscaling.