semenbari
semenbari

Reputation: 805

is it neo4j fast to handle data? it is too slow in my case

I am checking neo4j to handle datas. But it is too slow, seeing relasted papers, neo4j could handle over billions node and edge. But just seeing below code with thousands node, it is too slow. Is there other good or proper way to use it or special setting?

Thanks!

from neo4j.v1 import GraphDatabase, basic_auth

driver = GraphDatabase.driver("bolt://192.168.0.69:6969", auth=basic_auth("c8c8", "c8c8"))
session = driver.session()



session.run("CREATE (a:Person2 {name: {name}, title: {title}})",
            {"name": "Arthur", "title": "King"})


for i in range(3000):
    tt = "CREATE (a:Person" + str(i) + " {name: {name}, title: {title}})"
    session.run(tt,
            {"name": "Arthur", "title": "King"})
    print (i)



result = session.run("MATCH (a:Person) WHERE a.name = {name} "
                     "RETURN a.name AS name, a.title AS title",
                     {"name": "Arthur"})
for record in result:
    print("%s %s" % (record["title"], record["name"]))


session.close()

Upvotes: 1

Views: 1134

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30397

There are three big things to fix here.

The first is you'll want to create an index on :Person(name) so your lookup at the end is fast.

The second is you shouldn't be using different labels in your query and the loop. :Person works just fine, no need to use :Person2 or other person labels like in your loop. If you want to have different values in your loop, then append the loop number to the name or title, not the label.

The second is that you're executing a transaction per iteration of your loop, that's going to have terrible performance.

It's better to ingest data through batching, passing a list of data that you will UNWIND within your Cypher. With only 3000 entries you actually process that in a single transaction.

Here's some suggestions on efficient batching.

Upvotes: 4

Related Questions