Reputation: 4772
We have one program in Java and one in Python, and need to get them taking together in a ping-pong manner, each time exchanging an integer array of length 100,000, and taking ~ 0.1 - 1 second to do their work:
Note that
I am more familiar with Java, and understand that a shared memory backed file approach is likely to be the fastest. This seems relevant for the Java side, but how would I get each program to wait/block for the other to complete its work and update the shared memory before the other starts reading? I've heard of something called 'semaphore', but can't figure it out.
These are my fallback ideas, but perhaps they are better?
Upvotes: 5
Views: 3421
Reputation: 381
You could try combining java and python in the same process using jep. The latest release added support for sharing memory between python and java using numpy ndarrays and java direct buffers. This would let you share the data without any copying which should give the best performance possible.
Upvotes: 2
Reputation: 38899
Go for a fast intermediary data server to assist in communication between them. Redis would do the trick. You'll need two data structures there:
my_project:list
for reference.Then have the following interaction:
my_project:list
, then it sets the lock to the other program's turn.Upvotes: 1