Nikhil Kuriakose
Nikhil Kuriakose

Reputation: 1201

Inserting a huge set to neo4j graph database

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?

Upvotes: 0

Views: 166

Answers (1)

Sumeet Sharma
Sumeet Sharma

Reputation: 2583

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

Upvotes: 1

Related Questions