This document provides information about using flow control with messages published to a topic.
About flow control
A publisher client may attempt to publish messages faster than that client is capable of sending data to the Pub/Sub service. Clients are limited by many factors, including:
- Machine CPU, RAM, and network capacity
- Network settings, such as the number of outstanding requests and available bandwidth
- The latency of each publish request, largely determined by the network connections between the Pub/Sub service, the client, and Google Cloud
If the publish request rate exceeds these limits, requests accumulate in memory
until they fail with a DEADLINE_EXCEEDED
error. This is especially likely
when tens of thousands of messages are published in a loop, generating thousands
of requests in milliseconds.
You can diagnose this issue by checking the server side metrics in Monitoring. You
won't be able to see the requests that have failed with DEADLINE_EXCEEDED
, only the
successful requests. The rate of successful requests tells you the
throughput capacity of your client machines, providing a baseline for configuring flow
control.
To mitigate flow rate issues, configure your publisher client with flow control to limit the rate of publish requests. You can configure the maximum number of bytes allocated for outstanding requests, and the maximum number of outstanding messages permitted. Set these limits according to the throughput capacity of your client machines.
Before you begin
Before configuring the publish workflow, ensure you have completed the following tasks:
- Learn about topics and the publishing workflow.
- Create a topic.
Required roles
To get the permissions that you need to use flow control,
ask your administrator to grant you the
Pub/Sub Publisher (roles/pubsub.publisher
) IAM role on your topic.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
You need additional permissions to create or update topics and subscriptions.
Use flow control with messages
Publisher flow control is available using the Pub/Sub client libraries in the following languages:
C++
Before trying this sample, follow the C++ setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.