Article DetailsDetailsHelp DetailsThe duration of queries executed through the Neo4j driver is noticeably longer than executing them directly from the Neo4j browser. Query Execution time displayed in the Neo4j BrowserQuery Execution time using a Neo4j driverContributing factorsWhat is the approximate latency expected while using a Neo4j driver?Best practices to reduce response times Query Execution time displayed in the Neo4j Browser Let's consider an example involving the creation of two nodes and a relationship. Please note that the insights presented here apply 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. Query Execution time using a Neo4j driver 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 represents the time the query takes to execute on the Neo4j server without accounting for any additional overhead. The code will introduce additional overhead due to resource management, object initialization, and method invocation tasks. 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, the code will introduce some overhead for resource management, object initialization, and method invocation. What is the approximate latency expected while using a Neo4j driver? Since query execution and network latency are major contributing factors, we can estimate them using the following approach: Get the Query Execution time and call it queryExecTime. You can get this from your query logs or use the execution time displayed by the Neo4j Browser.Use netcat to check network time for a one-way trip: From the client environment nc -zv <dbid>.databases.neo4j.io 7687 Or ncat -zv <dbid>.databases.neo4j.io 7687 roundTripTime = one-way X 2 (times 2)Overall response times we can expect: Ideal conditions, connection already established - 1 x roundTripTime + queryExecTimeNew connection, database name specified - 3 x roundTripTime + queryExecTimeNew connection, database name unspecified - 4 x roundTripTime + queryExecTime(extra round trip for database discovery) The above estimates consider only network times and do not include other factors (object creation, consuming results, etc.,). Best practices to reduce response times Specify the database name (always 'neo4j' for Aura) in the session object. This will reduce one round trip for database discovery in new connections.Use traceroute to Identify the route and any additional, unexpected hops. traceroute <dbid>.databases.neo4j.io If the one-way trip time for your driver is considerably high, it is advisable to run your applications from a server as close as possible to the Aura instance's region.This approach will help minimize network latency.It is worth rewriting your application's logic to consume query results only when necessary, which may further optimize performance.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 InstancesFor more comprehensive guidance on enhancing query performance, we recommend reviewing our article on Performance tuning with Neo4j AuraDB , which provides general query optimization techniques.In a multi-node Aura Cluster, use Transaction Functions and mark read queries explicitly to avoid overwhelming the leader with READ queriesInformationTitleQuery execution takes significantly more time while using Neo4j driversArticle Created Date3/15/2024, 10:56 PMURL Name16739301184403-Query-execution-takes-significantly-more-time-while-using-Neo4j-driversLast Modified Date10/22/2024, 12:01 PM