javaneo4jcypherneo4j-java-api

Cypher query execution time with Neo4j java driver


I am trying to find out execution time of my Cypher query with java driver.

Session session = driver.session();
session.run( "CREATE (a:Person {name:'Arthur', title:'King'})" );
StatementResult result = session.run( "Profile MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" );

But I could not find it anywhere in the StatementResult or in the ResultSummary, which is returned by StatementResult.consume(query).

I could access db hits from ProfiledPlan in ResultSummary but there is no information about time.

Is there any way I can access Cypher query execution time using neo4j java driver?


Solution

  • Since Neo4j Java driver version 1.1.0 there is:

    /**
     * The time it took the server to make the result available for consumption.
     *
     * @param unit The unit of the duration.
     * @return The time it took for the server to have the result available in the provided time unit.
     */
    long resultAvailableAfter( TimeUnit unit );
    
    /**
     * The time it took the server to consume the result.
     *
     * @param unit The unit of the duration.
     * @return The time it took for the server to consume the result in the provided time unit.
     */
    long resultConsumedAfter( TimeUnit unit );
    

    It provides you with both times:

    1. Time till first byte
    2. Full execution time including consuming data from server

    Methods are localted on org.neo4j.driver.v1.summary.ResultSummary interface.