简体   繁体   中英

Neo4j > User-defined stored procedures: Would a stored procedure be faster than many cypher queries called from python?

The problem:

Each iteration of a python loop sends a cypher-query to Neo4j that returns values. This takes a considerable amount of time and is a bottleneck , as the number of loop items is 50 or more.

Environment

  • windows server 2019,
  • Neo4j Server version: 3.5.9 (community),
  • python 3.6
  • Neo4j python driver 4.2.1

Question

Would one call to a custom stored procedure be faster than repeated client requests to Neo4j?

Details

The stored procedure would be passed cypher parameters for all 50 items, and need to return results for all 50.

Well, if you can refactor your code to make one call to a stored procedure, it means you can also refactor to make one Cypher query and handle the result application side.

Maybe a stored procedure will be faster since you can leverage the JVM multithreading.

However, there are some drawbacks to using stored procedures:

  1. You need to redeploy and restart Neo4j when the code of the stored procedure changes
  2. You need to maintain it and upgrade with new Neo4j versions
  3. It implies you can write them in Java

I have rarely seen the usage of stored procedures for improving performance (it happens but it has some niche use cases).

As you stated, the bottleneck is your loop querying the db, I would try to fix that first.

Secondly, performance in Neo4j is generally handled by three major factors:

  1. Your ability to model your graph well, in order to optimise for querying
  2. Your ability to tune your Cypher queries
  3. Your index configuration is correct

In 99.99% of the problems you will have during your life with Neo4j will be solved by those 3 points above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM