Hi,
I have a use case where I need to manage thousands of gRPC web connections to my server, specifically for server streaming. How can I efficiently handle these multiple connections using gRPC Java?
Could someone share a code snippet demonstrating how to manage these connections?
Thanks,
Abhiram.
Fundamentally the process is not that different between having one client vs many connect to a server. The gRPC server is multithreaded and will simultaneously accept connections from multiple clients.
You can quickly try this out with the hello world example. You can first run the Greeter server in the example and then start more than one client processes at the same time. They should all connect to the server and execute the server side code.
In case you are thinking of long running persistent connections, you might be interested in a streaming RPC. The basic tutorial can get you started with those.
There is an executor passed to the ServerBuilder that is used to manage the threads that handle the incoming rpcs. By default gRPC uses a static cached thread pool. There are trade offs in the type of executor being used, such as when using cached vs fixed thread pool executor. It depends on the load and requirements. You can see elaborate discussion here on the type of executor to choose.