0

i am try to create nodes and relationship to database by using python but it takes very too much time. I use official neo4j-driver library and connect to database by Bolt protocal.

from neo4j import GraphDatabase

driver = GraphDatabase.driver('bolt://localhost:7687', auth=(user, pass))

i write the program to create about 13,000 nodes and 642,000 relationship and it takes time about 12 hour.

session = driver.session()
def createNode(props):
    Label = 'SINGLE_NODE'
    return session.run("CREATE (a:"+Label+" {props}) "
                       "RETURN id(a)",  {'props':props}).single().value()

def createRelation(n1,n2,props):
    Label = 'SINGLE_NODE'
    return session.run("MATCH (a:"+Label+"),(b:"+Label+") 
                        WHERE id(a) = {n1} AND id(b) = {n2} "
                       "CREATE (a)-[rel:IS_CONNECTED {props}]->(b) 
    RETURN rel",  {'n1':n1,'n2':n2,'props':props}).single().value()  

before i using neo4j-driver i use to use py2neo but it a little more slower than neo4j-driver. So are there any suggestion to making program processing faster. thank you

Kaow
  • 483
  • 2
  • 9
  • 22
  • 1
    If you're executing a transaction per node to be created, that's inefficient, try [batching your node creation instead](https://www.google.com/search?q=michael+hunger+batch+neo4j&oq=michael+hunger+batch+neo4j&aqs=chrome..69i57.4553j0j7&sourceid=chrome&ie=UTF-8) – InverseFalcon Aug 06 '19 at 15:49
  • Have you done a PROFILE of any of the queries? Make sure that the node lookup being performed by the planner is doing what you expect. – InverseFalcon Aug 06 '19 at 15:49
  • @InverseFalcon thank you for response, i will looking on it. – Kaow Aug 07 '19 at 05:11
  • @InverseFalcon could you please show me example of batching node insert in python. – Kaow Aug 07 '19 at 06:57
  • The link I posted should help. You need to take some limited subset of a list of elements to process, send that list as a parameter into the query, let the query UNWIND the list and process all elements of that list as a batch, then repeat with the next subset of the list. – InverseFalcon Aug 07 '19 at 18:41

0 Answers0