0

I am trying to insert a relative huge set of nodes to a neo4j database. I have around One million nodes.

The initial 100,000 nodes were inserted rather fast. However, the speed gradually came down. After around 300,000 nodes, it takes more than a minute for each node to be inserted.

public void writeXmlElements(List<XmlElement> elements){
    GraphDatabaseService graphDb = Neo4jDatabaseHandler.getGraphDatabase();
    int count = 0;
    try ( Transaction tx = graphDb.beginTx() )
    {
        for (XmlElement element : elements) {   
            count++;
            LOGGER.info("Processing "+count+" out of "+elements.size());
            Node node = graphDb.createNode();
            node.setProperty(XmlElements.NAME.getValue(), element.getTagName());
            node.setProperty(XmlElements.VALUE.getValue(), element.getTagValue());             
            tx.success();
        }
    }

}

I am doing it pretty straightforward, iterating through the list of 1 Million items.

Any clue how I can make it to run faster?

Nikhil Kuriakose
  • 1,101
  • 2
  • 10
  • 22

1 Answers1

1

If you want to insert a big dataset better use Batch Insertion. Refer here

Some more info : here and here

Also you would have to tune your neo4j server configuration for better performance. Refer : here

Community
  • 1
  • 1
Sumeet Sharma
  • 2,573
  • 1
  • 12
  • 24