I build a huge graph in JVM (Scala) which I want to use repeatedly, tweaking algorithms. I'd rather not reload it each time from disk. Is there a way to have it sit in one JVM while connecting from another, where the algorithms are being developed?
One java app can run the other via Runtime. exec() and control it (communicate) using the input stream. One could use JNI and a OS specific feature like named pipes or shared memory. You can also use java RMI to communicate between two applications, one calling methods of the other.
You can share class data between Java™ Virtual Machines (JVMs) by storing it in a cache in shared memory. Sharing reduces the overall virtual storage consumption when more than one JVM shares a cache. Sharing also reduces the startup time for a JVM after the cache has been created.
A shared memory connection allows both the client and the database to share the same memory on their host machine. This shared memory is temporary, and it is backed up by virtual memory. Shared memory connections are automatically used by Java applications running on the same machine as an InterSystems IRIS instance.
The IBM® Java™ Virtual Machine (JVM) version 5 and higher allows you to share bootstrap and application classes between JVMs by storing them in a cache in shared memory.
Save your graph to disk, then map it into memory with MappedByteBuffer. Both processes should use the same memory, which will be shared with the page cache.
Two JVMs sounds more complicated than it needs to be. Have you considered doing a kind of "hot deploy" setup, where your main program loads up the graph, displays the UI, and then asks for (or automatically looks for) a jar/class file to load that contains your actual algorithm code? That way your algorithm code would be running in the same jvm as your graph, but you wouldn't have to reload the graph just to reload a new algorithm implementation.
UPDATE to address OP's question in comment:
Here's how you could structure your code so that your algorithms would be swappable. It doesn't matter what the various algorithms do, so long as they are operating on the same input data. Just define an interface like the following, and have your graph algorithms implement it.
public interface GraphAlgorithm {
public void doStuff(Map<whatever> myBigGraph)
}
If your algorithms are displaying results to some kind of widget, you could pass that in as well, or have doStuff() return some kind of results object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With