The duration of queries executed through the Neo4j driver is noticeably longer compared to executing them directly from the Neo4j browser.
Let's consider an example involving the creation of two nodes and a relationship. Please note that the insights presented here are applicable to all Neo4j drivers, with Python being used as an illustrative example.
Neo4j browser:
When the query is executed from the Neo4j browser, it takes approximately 82 milliseconds to complete.
Neo4j Python driver, utilizing the provided "create friendship" code from the connection instructions example available here:
In the case of the Python driver, the same operation takes slightly over 3 seconds to execute.
Several factors contribute to the disparity in query execution time:
-
The completion time displayed in the Neo4j browser solely represents the time taken for the query to execute on the Neo4j server without accounting for any additional overhead.
- The code will introduce additional overhead due to tasks such as resource management, object initialization, and method invocation.
-
In the Python code, the measured time includes the round-trips required for transaction management, which inherently introduces some delays.
-
Network latencies also play a significant role in the discrepancy, and they tend to increase with the geographic distance between the client and the Aura instance's region.
To clarify, the time displayed in the Neo4j browser solely pertains to the query execution time on the server itself.
In contrast, the time recorded while executing the query using a driver encompasses the following components:
- Query execution time on the server.
- The cumulative effect of round-trips required for transaction management.
- The time spent on streaming results.
- Additionally, there will be some overhead for resource management, object initialization, and method invocation introduced by the code.
If you wish to understand the 'Query execution time on the server' for your queries, you can get the query logs from the Aura console and inspect the elapsedTimeMs field - How To Download Query Log from Aura Instances
If the execution time of your driver is considerably high, it is advisable to run your applications from a server that is located as close as possible to the Aura instance's region. This approach will help minimize network latency.
Additionally, it is worth considering rewriting your application's logic to consume query results only when necessary, which may further optimize performance.
For more comprehensive guidance on enhancing query performance, we recommend reviewing our article on Performance tuning with Neo4j AuraDB, which provides general query optimization techniques.
Comments
0 comments
Please sign in to leave a comment.