[C#] Does a GRPC server block while the server implementation handles the call?

212 views
Skip to first unread message

lcm...@gmail.com

unread,
Sep 5, 2017, 8:51:40 PM9/5/17
to grpc.io
When multiple clients concurrently make the same call to a GRPC server, does the server answere these calls asynchronously? I'm using C#. In case I want the server to handle the calls synchronously should I use some sort of locking like SemaphoreSlim?

Additionally, I've read that creating a connection to a GRPC server is time consuming and I'm supposed to share a connection/channel. Is the chanel thread-safe?

Thank you in advance.

Jan Tattermusch

unread,
Sep 14, 2017, 8:17:09 AM9/14/17
to grpc.io
C# server handles responses "asynchronously" in the sense that the method stubs you need to implement are meant to be implemented as async methods. So you can write "synchronous code", but you shouldn't really block in your code (although starting from v1.6.0 this will work too).

Multiple request can be handled at once (and you don't need any sychronization to make that safe) and your handlers' code will run on a threadpool. You might of course need synchronization in your business logic, but that's a different question.

Channels are definitely thread safe are there are meant to be used to invoke muliple calls (channel creation is expensive compared to  call creation).
Reply all
Reply to author
Forward
0 new messages