Cypher使用Neo4j java驱动程序查询执行时间

我试图用java驱动程序找出我的Cypher查询的执行时间。

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" ); 

但我无法在StatementResult或ResultSummary中找到它,它由StatementResult.consume(query)返回。

我可以在ResultSummaryProfiledPlan访问db命中,但是没有关于时间的信息。

有什么办法可以使用neo4j java驱动程序访问Cypher查询执行时间吗?

从Neo4j Java驱动程序版本1.1.0开始,有:

 /** * 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 ); 

它为您提供了两种时间:

  1. 到第一个字节的时间
  2. 完整执行时间,包括从服务器消耗数据

方法在org.neo4j.driver.v1.summary.ResultSummary接口上进行了org.neo4j.driver.v1.summary.ResultSummary