Loading all Neo4J db to RAM

后端 未结 1 635
遇见更好的自我
遇见更好的自我 2020-12-29 11:51

I am trying to load all my Neo4j DB to the RAM so querying will work faster. When passing the properties map to the graph creation, I do not see the process taking more spac

相关标签:
1条回答
  • 2020-12-29 12:36

    Neo4j loads all the data lazily, meaning it loads them into memory at first access. The caching option is just about the GC strategy, so when (or if) the references will be GCed. To load the whole graph into memory, your cache type must be strong and you need to traverse the whole graph once. You can do it like this:

    // untested java code
    
    import org.neo4j.helpers.collection.IteratorUtil;
    
    // ...
    
    for(Node node : graph.getAllNodes()) {
      IteratorUtil.count(node.getRelationships());
    }
    

    This way all nodes and relationships will be used once and thus loaded into the cache.

    0 讨论(0)
提交回复
热议问题