gRPC Multiple service instances on same port

844 views
Skip to first unread message

Cosmin

unread,
Jul 20, 2021, 10:51:13 AM7/20/21
to grpc.io
Hello all,

I have the following processes communicating on the same PC:


Example.jpg

P1, P2, P3.... all have the same service interface -> just different instances of the same service.
Client and server communicate on localhost port 10000 for example. Base on some information received from the client the server will start a new process P1. or P2, or P3..or how many it needs ( P1 - is actually a server that will start listening on localhost port 10001 for example )
Then the client will discuss directly with P1, P2, P3, ... depending on it's needs

The problem with this is that P1, P2, P3... beeing the same service, I cannot start them on the same localhost port, and because I might have a lot of these processes I will use a large amount of ports -> not a good practice.

Is there a better practice for this using gRPC? At the moment I couldn't find a solution for it or at least I didn't know what to search for.

The language: C++, the environment: Windows

Thank you!

Cosmin

pixel...@gmail.com

unread,
Jul 21, 2021, 1:50:36 PM7/21/21
to grpc.io
Unfortunately, there's currently no support for this on Windows. There is currently support for SO_REUSEPORT on Linux however.

Cosmin

unread,
Jul 22, 2021, 7:38:32 AM7/22/21
to grpc.io
Thank you for the info. Does anybody know if something like this will be possible in the future on windows?

Radosław Korzeniewski

unread,
Jul 26, 2021, 6:13:26 AM7/26/21
to Cosmin, grpc.io
Hello,

wt., 20 lip 2021 o 16:51 Cosmin <cosmin.co...@gmail.com> napisał(a):
Hello all,

I have the following processes communicating on the same PC:


Example.jpg

P1, P2, P3.... all have the same service interface -> just different instances of the same service.
Client and server communicate on localhost port 10000 for example. Base on some information received from the client the server will start a new process P1. or P2, or P3..or how many it needs ( P1 - is actually a server that will start listening on localhost port 10001 for example )
Then the client will discuss directly with P1, P2, P3, ... depending on it's needs

The problem with this is that P1, P2, P3... beeing the same service, I cannot start them on the same localhost port, and because I might have a lot of these processes I will use a large amount of ports -> not a good practice.

What exactly do you want to achieve in this setup? If all P1, P2 and P3 are the exact same service (same binary) and you want to get a better concurrency by spawning multiple processes then the best solution would be to use a single process but multiple threads. In this case you can share the single service tcp port with multiple threads without a problem.

best regards
--
Radosław Korzeniewski
rado...@korzeniewski.net

Kumar Rajan

unread,
Jul 15, 2022, 11:09:28 AM7/15/22
to grpc.io
Cosmin,
Were you able to solve this issue? We have a similar situation and looking for info on how you solved this.
Thanks
KR

Ahmed

unread,
Oct 19, 2022, 12:38:05 AM10/19/22
to grpc.io
@Radoslaw that is not the case for NUMA machines where, ultimately, multiple instances of the the same service (one per NUMA node) would be the way to go. 
Reply all
Reply to author
Forward
0 new messages