高效的 Google PubSub 发布

Pau*_*uca 3 google-cloud-platform google-cloud-pubsub

The docs for PubSub state that the max payload after decoding is 10MB. My question is whether or not it is advantageous to compress the payload at the publisher before publishing to increase data throughput?

This especially can be helpful if the payload has a high compression ratio like a json formatted payload.

ale*_*xel 6

如果您正在寻找 PubSub 的效率,我会首先专注于使用最好的 API,这就是 gRPC 的 API。如果正在使用客户端库,那么无论如何它使用 gRPC 的可能性很高。为什么是 gRPC?

  • gRPC 是二进制的,你的有效载荷不需要通过箍来编码
  • REST 需要对有效负载进行 base64,使其更大并具有额外的编码步骤

其次,如果可能的话,我会尝试对消息进行批处理,从而减少调用次数,消除一些延迟。

最后我会看看压缩,但这意味着你需要在订阅者处专门解压缩它。这意味着您的应用程序代码将变得更加复杂。如果您的所有工作负载都在 Google Cloud Platform 上,我就不会为压缩而烦恼。如果您的工作负载在 GCP 之外,您可能会考虑它,但测试是有意义的。

如果您的架构稳定,另一种压缩方法是考虑使用 ProtoBuf。

最后,我会:

  1. 确保您使用 gRPC
  2. 尽可能批量
  3. 仅在需要时和基准测试后进行压缩(意味着应用程序中的额外逻辑)