Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared memory for grpc client and server

Tags:

grpc

My project is to read an image in a server, do some processing and then pass the whole image to the client. Client takes up the image and do some more processing and returns some output values to the server. The image being used between both the server and client is of size [640x480x3].

Following are the various techniques that came in my mind to implement this problem:

  1. Pass the whole pixel values through the message from server to client
    • It takes 75ms for just sending a message from one server to one client, even if they are in the same system! (Never a good idea)
  2. Split the whole image to chunks, and then message from server to client using stream.
    • There are various answers in SO for this. I am currently working on getting this working.
  3. Assign the pixel values to a variable recognised by gRPC in both server and client. In other words have the image in a shared memory of gRPC, which could be accessed by both the server and client (assuming both server and client to be in the same system).
    • Is this mode of messaging between server and client possible? If yes, please provide some references to the doc or examples for the same.
like image 776
Anoop K. Prabhu Avatar asked Oct 30 '25 01:10

Anoop K. Prabhu


1 Answers

gRPC doesn't (at the current time) support any kind of shared-memory transport between different processes on the same system in any of the language APIs. A close variant is the in-process transport that is supported by C++ and Java. This is used for sending messages between a client and a server in the same process (for example, if you want to run a proxy in the same address space as a server that might also have a direct external interface), and the only difference between this and traditional gRPC operations is at channel creation in both languages and when building the server in Java. The Java documentation for this is at https://grpc.io/grpc-java/javadoc/io/grpc/inprocess/InProcessServerBuilder.html . For C++, you just call Server::InProcessChannel on the server rather than grpc::CreateChannel since all servers automatically have an in-process capability in C++ as long as you have their pointer.

Hope that helps!

@vjpai

like image 93
vjpai Avatar answered Oct 31 '25 21:10

vjpai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!