The in-memory graph snapshots stored in compact data structures by PGX are the foundation of many cool graph analytics and powerful graph queries (PGQL). In this post, I am going to share with you a couple of tips on sharing in-memory graphs and cleaning up resources used by in-memory graphs.
1. To share an existing in-memory graph snapshot G, one needs to use the same graph config as that used to load the graph G. Assume G was loaded with graphConfig, then the following command will reuse the same in-memory graph snapshot.
pgxGraph = pgxSession.readGraphWithProperties(graphConfig);
This technique is used in Oracle's support for Cytoscape visualization of property graph.
2. To clean up an existing in-memory graph snapshot G, one can invoke pgxGraph.close() API. Note that it does not immediately free up the resources taken by G. Rather, it simply denotes the current session will not use G anymore.
There is a periodically scheduled task in PGX which goes through all shareable graphs and cleans them up if:
- The overall memory consumption is above a certain threshold. By default, clean up if more than 85% of total memory (a sum of on- and off- heap) is used, and
- The graph G doesn't have any references from any sessions.
The default period for the memory cleanup is 600 seconds, and can be configured using the config parameter "memory_cleanup_interval" (unit in seconds). The default cleanup threshold is 85% and can be changed using the config parameter "release_memory_threshold".
Acknowledgement: thanks Alexander Weld for his input on this blog post!