Concurrency control is an available feature in the Pub/Sub high-level client library. You can also implement your own concurrency control when you're using a low-level library.
Support for concurrency control depends on the programming language of the client library. For language implementations that support parallel threads, such as C++, Go, and Java, the client libraries make a default choice for the number of threads.
This choice might not be optimal for your application. For example, if your subscriber application is not keeping up with the incoming message volume and is not CPU-bound, you must increase the thread count. For CPU-intensive message processing operations, reducing the number of threads might be appropriate.
Concurrency control configurations
The default values for the concurrency control variables and the names of the
variables might differ across client libraries. For example, in the Java client
library, the methods to configure concurrency control are
setSystemExecutorProvider()
, setExecutorProvider()
, and setParallelPullCount()
.
setParallelPullCount() lets you decide how many streams to open. You can open more streams if your subscriber client can handle more data than that is sent on a single stream which is 10 MBps.
setExecutorProvider() lets you customize the executor provider used for processing messages. For example, you can change the executor provider to one that returns a single, shared executor with a limited number of threads across multiple subscriber clients. This configuration helps to limit the number of threads created.
setSystemExecutorProvider() lets you customize the executor provider used for lease management. Typically, you don't configure this value unless you want to use the same executor provider in
setExecutorProvider
andsetSystemExecutorProvider
. For example, you can use the same executor provider if you have a number of low-throughput subscriptions. Using the same value limits the number of threads in the client.
The total number of threads used for concurrency control depends on the executor provider passed in the client library and the parallel pull count.
Code samples for concurrency control
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.
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.
What's next
Read about the other delivery options you can configure for a subscription: