c++ multiple stubs

51 views
Skip to first unread message

martin...@versasec.com

unread,
Nov 12, 2019, 4:18:15 PM11/12/19
to grpc.io
After hours of reading on internet and not getting an answer i will ask here. We are currently trying to replace SOAP with grpc for our client server architecture. On the client side we are using grpc c++. Now the question is what is the best approach to create stubs and channels. What i understand is that its the best to only have one channel and use it for all calls. But what about stubs. We have round about 100 functions that will call the server on different threads. Is it better to also create only one stub for all these calls or to create one stub and make asynchronous calls? And what about thread safety?

martin...@versasec.com

unread,
Nov 12, 2019, 4:22:13 PM11/12/19
to grpc.io
Sorry, i meant "Is it better to also create only one stub for all these calls or to create a stub for every function call..."

Yang Gao

unread,
Nov 12, 2019, 4:25:19 PM11/12/19
to martin...@versasec.com, grpc.io
Channels are relatively heavier weight and thus it could be a good idea to not create a lot of them (unless you hit some throughput bottleneck). Stubs are pretty cheap.
Channels and stubs are all thread-safe.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/643efd39-8d2e-45fc-9936-d6b8a10420f2%40googlegroups.com.

martin...@versasec.com

unread,
Nov 12, 2019, 4:29:41 PM11/12/19
to grpc.io
So you would say it’s ok to create for every call a new stub. But what about concurrency? Let’s say I create two stubs and they make a call at the same time on the same channel. Is one stub blocks the other one? So when you would use asynchronous calls?

Christian Rivasseau

unread,
Nov 12, 2019, 4:47:57 PM11/12/19
to martin...@versasec.com, grpc.io
2 blocking calls on the same channel do not block each other, they will execute concurrently.
The main reason to use asynchronous calls is when the caller themselves cannot block, for instance in a non blocking server (think of something
similar to nodeJS).

On Tue, Nov 12, 2019 at 10:29 PM <martin...@versasec.com> wrote:
So you would say it’s ok to create for every call a new stub. But what about concurrency? Let’s say I create two stubs and they make a call at the same time on the same channel. Is one stub blocks the other one? So when you would use asynchronous calls?

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.


--
Christian Rivasseau
Co-founder and CTO @ Lefty
+33 6 67 35 26 74
Reply all
Reply to author
Forward
0 new messages