-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow the Pubsub Publisher to work (in low-volume cases), with fewer than 20 threads #27
Comments
@JoshuaFox You can use below setting to have total control over threads from this library.
|
Do I understand correctly as follows? -- You use the same single-thread |
thats correct |
@JoshuaFox did the code snippet posted by @ajaaym resolve your issue? we are seeing similar problems with PubSub creating too many threads in a single process. |
@moadi . Yes, I tested that it indeed brings down the number of threads. |
@JoshuaFox are you able to explain the interrelationship between the two numeric 1s, its a little trickier without them being named constants specifically
and
The former obviously appears to be the key value, but if for example I wanted a pool of 10 threads across all my subcribers, do I set both numbers to 10, or just the former? |
@JoshuaFox No. That code is quite low-level, and I do not fully understand the thread design. @ajaaym who posted it is the one to ask. This again is a reason that the code setting thread counts should be inboarded to the library and exposed in the library's API. |
@wyaeld We this issue in our application which maintains ~15 publishers/subscribers suffering from ~1000 waiting GAX threads. @ajaaym I would still be interested if my interpretation is right |
I am going to mark this issue resolved, as the solution to this question is provided above. Publisher.Builder.setExecutorProvider can be used to provide a custom executor to the Pub/Sub Publisher. See our docs on publisher concurrency control for examples. A FixedExecutorProvider will return the same executor on each call to .getExecutor(), while an InstantiationExecutorProvider will construct a new executor on each call to .getExecutor(). To decrease gax thread counts, the same single-thread FixedExecutorProvider can be shared across the GrpcTransportProvider and ManagedChannelBuilder. |
See discussion with Kir Titievsky , Product Manager for Google PubSub, at GoogleGroup
My application publishes a low volume of messages (1 every few seconds at most), with no other use of PubSub. It does not subscribe. We are using simple Java code as in this sample. The Publisher object is retained for the lifetime of the process, as recommended here.
On first use, PubSub creates 60 threads that stay live permanently, like these:
Sixty is a very high default.
Moreover, if I setExecutorThreadCount to 4 (code following), I still get an extra 26 permanent threads. Setting it to 1 or 2 also gets about 20 extra threads.
Our legacy application is already thread-heavy; and it cannot tolerate more than one or two extra threads, even if these are inactive. Unfortunately, the legacy threading model cannot be changed.
Yet it does seem that a low-volume Publisher really needs only one thread.
Please offer a way to configure PubSub down to 1 or 2 threads.
The text was updated successfully, but these errors were encountered: