Search code examples
graph-databasesjungjgrapht

Saving in-memory graph representation in database


I have a dynamic graph changing over time and I am using Jgrapht library to store each instance of the graph in memory using
UndirectedGraph<Node, DefaultEdge> timeGraph = new SimpleGraph<Node, DefaultEdge>(DefaultEdge.class);

As it is intensive to hold multiple huge graphs in-memory, I wanted to know if there is a way to store each instance of the timeGraph as it is in a database like MongoDB (Neo4j or anyother) and import a particular graph to memory whenever necessary; instead of building the nodes and relationships again in the graph database.

P.S. I have tried exporting to graphML file format and importing each time, but it doesn't seem to help (due to my additional requirements of subgraph storing). customGraphMLImporter.GraphMLImport(i_timestep);

Looking for inputs so I can try out the options. Thanks.


Solution

  • You have few options here:

    1. To use 3rd party graph-oriented database (like Neo4J), MongoDB is document oriented and isn't optimized for graph operations)
    2. Serialize your graph to file and store this files on a disk

    Which option to choose is up to you, in case if you need all graph in memory of your application - I'd suggest to store it by yourself in plain files. (Because you can directly read all your graph into memory and use it without database overhead), if you need only part of your graph, I'd suggest using Neo4J with its API for graph traversal.