-
Notifications
You must be signed in to change notification settings - Fork 388
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
Sharing a pool of gRPC threads/connections with N topics for Pub/Sub? #13707
Comments
While not the Pub/Sub expert, let me jump in and confirm a few of your suspicions.
Yes.
So there are two things here:
For 1, the thread pool servicing the For 2, the pool of gRPC channels cannot be reused by For the sake of completeness, I should point out that the Of course, you would be using a blocking API. Maybe that is not good enough for your use case. |
Solid reply, thanks as usual @dbolduc. I think an easy workaround for now would be
I'll go with that for now, but what do you think about this?
Perhaps that could be discussed among maintainers for a future release? |
Definitely. I will start the brainstorming of ways for the fancy Option A : Override the topic via a call optionAt some point we decided not to add per-call options for the Publisher. #7689 (comment) We could add the equivalent of Note that Option B: offer a way to provide a channel pool to
|
auto channel = CreateGrpcChannel(*auth, options, id); |
The stub factory would look for the presence of the GrpcChannelPoolOption
and use the channels therein if the option is present instead of creating new channels.
Both sound reasonable in my opinion. When I first started fiddling with the API, I expected something like Option B (since the nuances around Option A are unclear to me too). |
This document covers some of the questions here: https://cloud.google.com/cpp/docs/background-threads (if nothing else it may help the search engines find it in the future). On the channels: keep in mind that gRPC shares sockets under the hood, that is, different channels use the same socket if (1) the use the same endpoint, (2) they use the same authentication / credentials, (3) the have the same channel attributes, and (4) they are configured to use the global pool of sockets (I may have forgotten some other condition, but you get the idea). There are some tradeoffs. The last condition requires some synchronization overhead. |
I was looking for something like this and couldn't find it. Appreciate this! |
In case it helps, I ended up going with something like this in the interim:
Where I'm maintaining a map of publisher connections per topic in order to keep using the async API. |
@scotthart as I no longer define the roadmap on this project. |
We'll take this feature request into consideration in our upcoming planning, but I cannot commit to any time frame at present. If/when we decide to work on this feature, we'll update this issue accordingly. |
What component of
google-cloud-cpp
is this feature request for?Pub/Sub
Is your feature request related to a problem? Please describe.
Thanks for a great product. I've been looking at your samples for using the Pub/Sub publisher class. There is one example in particular where it shows you how to pass in your own thread pool:
https://cloud.google.com/cpp/docs/reference/pubsub/latest/classgoogle_1_1cloud_1_1pubsub_1_1Publisher#thread-safety
I had some suspicions about gRPC connections and the like, so I dug into the source code.
Each call of
MakePublisherConnection
is still tied to a topic. It is unclear if can use the same thread pool for multiple calls toMakePublisherConnection
or not. InsideMakePublisherConnection
I see gRPC channels being connected per thread, so I'm assuming that it's not expected to use the same thread pool across multiple topics?That leaves me to my point of confusion. What is the expected usage for a scenario that I would assume is common:
Describe the solution you'd like
I would like a sample to document that, or even have this issue be the documentation.
Describe alternatives you've considered
I am currently iterating on ways I can play with the API to do what I expect, but it isn't ideal.
The text was updated successfully, but these errors were encountered: