Skip to content

Commit

Permalink
Defer buildling of plan description until retrieve time...
Browse files Browse the repository at this point in the history
As the query collector always collects queries (and therefore builds
the plan description), we defer building it until the queries are
retrieved, instead of rebuilding it on every query invocation.
  • Loading branch information
fickludd committed May 23, 2019
1 parent b7553aa commit c78749f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Expand Up @@ -114,7 +114,7 @@ public void endSuccess( ExecutingQuery query )
QuerySnapshot snapshot = query.snapshot(); QuerySnapshot snapshot = query.snapshot();
queries.produce( queries.produce(
new TruncatedQuerySnapshot( snapshot.queryText(), new TruncatedQuerySnapshot( snapshot.queryText(),
snapshot.queryPlan(), snapshot.queryPlanSupplier(),
snapshot.queryParameters(), snapshot.queryParameters(),
snapshot.elapsedTimeMicros(), snapshot.elapsedTimeMicros(),
snapshot.compilationTimeMicros(), snapshot.compilationTimeMicros(),
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/ */
package org.neo4j.internal.collector; package org.neo4j.internal.collector;


import java.util.function.Supplier;

import org.neo4j.graphdb.ExecutionPlanDescription; import org.neo4j.graphdb.ExecutionPlanDescription;
import org.neo4j.values.AnyValue; import org.neo4j.values.AnyValue;
import org.neo4j.values.SequenceValue; import org.neo4j.values.SequenceValue;
Expand Down Expand Up @@ -51,14 +53,14 @@ class TruncatedQuerySnapshot
{ {
final int fullQueryTextHash; final int fullQueryTextHash;
final String queryText; final String queryText;
final ExecutionPlanDescription queryPlan; final Supplier<ExecutionPlanDescription> queryPlanSupplier;
final MapValue queryParameters; final MapValue queryParameters;
final Long elapsedTimeMicros; final Long elapsedTimeMicros;
final Long compilationTimeMicros; final Long compilationTimeMicros;
final Long startTimestampMillis; final Long startTimestampMillis;


TruncatedQuerySnapshot( String fullQueryText, TruncatedQuerySnapshot( String fullQueryText,
ExecutionPlanDescription queryPlan, Supplier<ExecutionPlanDescription> queryPlanSupplier,
MapValue queryParameters, MapValue queryParameters,
Long elapsedTimeMicros, Long elapsedTimeMicros,
Long compilationTimeMicros, Long compilationTimeMicros,
Expand All @@ -67,7 +69,7 @@ class TruncatedQuerySnapshot
{ {
this.fullQueryTextHash = fullQueryText.hashCode(); this.fullQueryTextHash = fullQueryText.hashCode();
this.queryText = truncateQueryText( fullQueryText, maxQueryTextLength ); this.queryText = truncateQueryText( fullQueryText, maxQueryTextLength );
this.queryPlan = queryPlan; this.queryPlanSupplier = queryPlanSupplier;
this.queryParameters = truncateParameters( queryParameters ); this.queryParameters = truncateParameters( queryParameters );
this.elapsedTimeMicros = elapsedTimeMicros; this.elapsedTimeMicros = elapsedTimeMicros;
this.compilationTimeMicros = compilationTimeMicros; this.compilationTimeMicros = compilationTimeMicros;
Expand Down
Expand Up @@ -60,7 +60,8 @@ object QueriesSection {
val snapshot = querySnapshots.next() val snapshot = querySnapshots.next()
val queryString = snapshot.queryText val queryString = snapshot.queryText
if (QUERY_FILTER.findFirstMatchIn(queryString).isEmpty) { if (QUERY_FILTER.findFirstMatchIn(queryString).isEmpty) {
val snapshotList = queries.getOrElseUpdate(QueryKey(queryString, snapshot.fullQueryTextHash, snapshot.queryPlan), new QueryData()) val queryKey = QueryKey(queryString, snapshot.fullQueryTextHash, snapshot.queryPlanSupplier.get())
val snapshotList = queries.getOrElseUpdate(queryKey, new QueryData())
snapshotList.invocations += SingleInvocation(snapshot.queryParameters, snapshotList.invocations += SingleInvocation(snapshot.queryParameters,
snapshot.elapsedTimeMicros, snapshot.elapsedTimeMicros,
snapshot.compilationTimeMicros, snapshot.compilationTimeMicros,
Expand Down
Expand Up @@ -252,9 +252,9 @@ public String queryText()
return queryText; return queryText;
} }


public ExecutionPlanDescription planDescription() public Supplier<ExecutionPlanDescription> planDescriptionSupplier()
{ {
return planDescriptionSupplier.get(); return planDescriptionSupplier;
} }


public MapValue queryParameters() public MapValue queryParameters()
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;


import org.neo4j.graphdb.ExecutionPlanDescription; import org.neo4j.graphdb.ExecutionPlanDescription;
Expand Down Expand Up @@ -72,9 +73,9 @@ public String queryText()
return query.queryText(); return query.queryText();
} }


public ExecutionPlanDescription queryPlan() public Supplier<ExecutionPlanDescription> queryPlanSupplier()
{ {
return query.planDescription(); return query.planDescriptionSupplier();
} }


public MapValue queryParameters() public MapValue queryParameters()
Expand Down

0 comments on commit c78749f

Please sign in to comment.