Ashika Umanga Umagiliya
Ashika Umanga Umagiliya

Reputation: 9158

Java to C++ Inter Process Communication

enter image description here

My application comprised of two components running on the same machine:

1) A thin Java module which handles simple tasks work like DB persistance,process requests..etc
2) C++ module which does heavy computing using OpenCV and CUDA

Say both of the components startup independently.

Step 1: init() method of Java Layer calls the init() method of C++ module which will read thousands of images from S3, do some image processing and keep the results in GPU memory.init() is only called once and this data is kept unchanged in GPU memory.

Step 2: Consecutive calls to calc() in Java layer invoke the calc() method in C++ module which does some processing using passed arguments utilizing data on GPU memory and the result is sent to the Java layer.

My question is how to achieve this IPC between Java and C++ process with less overhead?

One obvious way is to use TCP sockets (maybe use GRPC)

Is it possible to use JNI (or SWIG) for this kind of IPC communication?

Upvotes: 2

Views: 1190

Answers (1)

darune
darune

Reputation: 10962

Im going to assume that the application, etc. is not extremely critical. Then a framework for RPC, like Apache Thrift may be an ideal candidate because it simplifies the RPC task (basicly uses a TCP connection for the communication). Sending the result image back over a local TCP connection doens't sound like it will cause any issues. https://thrift.apache.org/

The least overhead would be some shared memory or perhaps a memory mapped file. But AFAIK it will require (alot) more work on your part to pull off.

Upvotes: 3

Related Questions