简体   繁体   English

使用Google Cloud PubSub进行服务器到服务器的多播消息传递?

[英]server-to-server multicast messaging with Google Cloud PubSub?

I have a cluster of backend servers on GCP, and they need to send messages to each other. 我在GCP上有一个后端服务器集群,它们需要相互发送消息。 All the servers need to receive every message, but I can tolerate a low error rate. 所有服务器都需要接收每条消息,但是我可以容忍较低的错误率。 I can deal with receiving the message more than once on a given server. 我可以处理在给定服务器上多次收到消息的问题。 Packet ordering doesn't matter. 数据包排序无关紧要。

I don't need much of a persistence layer. 我不需要很多持久层。 A message becomes stale within a couple of seconds after sending it. 邮件在发送后几秒钟之内就会过时。

I wired up Google Cloud PubSub and pretty quickly realized that for a given subscription, you can have any number of subscribers but only one of them is guaranteed to get the message. 我连线了Google Cloud PubSub,并很快意识到,对于给定的订阅,您可以有任意数量的订阅者,但是保证只有其中一个订阅者可以收到消息。 I considered making the subscribers all fail to ack it, but that seems like a gross hack that probably won't work well. 我考虑过让所有订阅者都无法接受它,但这似乎是一个粗暴的破解,可能效果不佳。

My server cluster is sized dynamically by an autoscaler. 我的服务器群集由自动缩放器动态调整大小。 It spins up VM instances as needed, with dynamic hostnames and IP addresses. 它根据需要使用动态主机名和IP地址启动VM实例。 There is no convenient way to map the dynamic hosts to static subscriptions, but it feels like that's my only real option: Create more subscriptions than my max server pool size, and then use some sort of paxos system (runtime config, zookeeper, whatever) to allocate servers to subscriptions. 没有方便的方法将动态主机映射到静态订阅,但这似乎是我唯一的选择:创建超出我的最大服务器池大小的订阅,然后使用某种paxos系统(运行时配置,zookeeper等)将服务器分配给订阅。

I'm starting to feel that even though my use case feels really simple ("Every server can multicast a message to every other server in my group"), it may not be a good fit for Cloud PubSub. 我开始觉得,即使我的用例非常简单(“每个服务器都可以将消息多播到组中的其他每个服务器”),但它可能并不适合Cloud PubSub。

Should I be using GCM/FCM? 我应该使用GCM / FCM吗? Or some other technology? 还是其他一些技术?

Cloud Pub/Sub may or may not be a fit for you, depending on the size of your server cluster. Cloud Pub / Sub可能不适合您,具体取决于服务器群集的大小。 Failing to ack the messages certainly won't work because you can't be sure each instance will get the message; 未能确认消息肯定是行不通的,因为您不能确定每个实例都会收到消息。 it could just be redelivered to the same instance over and over again. 它可以一次又一次地重新传递到同一实例。

You could use multiple subscriptions and have each instance create a new subscription when it starts up. 您可以使用多个订阅,并让每个实例在启动时都创建一个新的订阅。 This only works if you don't plan to scale beyond 10,000 instances in your cluster, as that is the maximum number of subscriptions per topic allowed. 仅当您不打算在集群中扩展超过10,000个实例时,此方法才有效,因为这是每个主题允许的最大预订数。 The difficulty here is in cleaning up subscriptions for instances that go down. 此处的困难在于清理发生故障的实例的订阅。 Ones that cleanly shut down could probably delete their own subscriptions, but there will always be some that don't get cleaned up. 完全关闭的用户可能会删除自己的订阅,但是总会有一些没有得到清除。 You'd need some kind of external process that can determine if the instance for each subscription is still up and running and if not, delete the subscription. 您需要某种外部流程来确定每个订阅的实例是否仍在运行中,如果不是,请删除该订阅。 You could use GCE shutdown script s to catch this most of the time, though there will still be edge cases where deletes would have to be done manually. 您仍然可以使用GCE关闭脚本来捕获大多数时间,尽管在某些极端情况下,必须手动执行删除操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM