Skip to content

Commit

Permalink
Flattening profile metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroecheler committed May 19, 2015
1 parent 90d1018 commit 9737d31
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public QueryProfiler getProfiler() {
@Override
public void observeWith(QueryProfiler parentProfiler) {
Preconditions.checkArgument(parentProfiler!=null);
this.profiler = parentProfiler.addNested("OR-query");
this.profiler = parentProfiler.addNested(QueryProfiler.OR_QUERY);
profiler.setAnnotation(QueryProfiler.FITTED_ANNOTATION,isFitted);
profiler.setAnnotation(QueryProfiler.ORDERED_ANNOTATION,isSorted);
profiler.setAnnotation(QueryProfiler.QUERY_ANNOTATION,backendQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private Subquery(IndexType index, BackendQuery query) {
}

public void observeWith(QueryProfiler prof) {
this.profiler = prof.addNested("AND-query");
this.profiler = prof.addNested(QueryProfiler.AND_QUERY);
profiler.setAnnotation(QueryProfiler.QUERY_ANNOTATION,query);
profiler.setAnnotation(QueryProfiler.INDEX_ANNOTATION,index.getName());
if (index.isMixedIndex()) profiler.setAnnotation(QueryProfiler.INDEX_ANNOTATION+"_impl",index.getBackingIndexName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public interface QueryProfiler {
public static final String FULLSCAN_ANNOTATION = "fullscan";
public static final String INDEX_ANNOTATION = "index";

public static final String OR_QUERY = "OR-query";
public static final String AND_QUERY = "AND-query";

public static final QueryProfiler NO_OP = new QueryProfiler() {
@Override
public QueryProfiler addNested(String groupName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public TP3ProfileWrapper(MutableMetrics metrics) {

@Override
public QueryProfiler addNested(String groupName) {
//Flatten out AND/OR nesting
if (groupName.equals(AND_QUERY) || groupName.equals(OR_QUERY)) return this;

int nextId = (subMetricCounter++);
MutableMetrics nested = new MutableMetrics(metrics.getId()+"."+groupName+"_"+nextId,groupName);
metrics.addNested(nested);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3374,6 +3374,8 @@ public void testTinkerPopOptimizationStrategies() {
}
}

Traversal t;
TraversalMetrics metrics;
GraphTraversalSource gts = graph.traversal();

assertNumStep(numV / 5, 1, gts.V(sv[0]).outE("knows").has("weight", 1), TitanVertexStep.class);
Expand All @@ -3383,9 +3385,9 @@ public void testTinkerPopOptimizationStrategies() {
assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").range(10, 20)), LocalStep.class);
assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").order().by("weight", decr), TitanVertexStep.class, OrderGlobalStep.class);
assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").order().by("weight", decr).limit(10)), TitanVertexStep.class);
assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight").has("weight", 1).order().by("weight", incr), TitanVertexStep.class, OrderGlobalStep.class);
assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").has("weight").has("weight", 1).order().by("weight", incr).limit(10)), TitanVertexStep.class);
assertNumStep(5, 1, gts.V(sv[0]).local(__.outE("knows").has("weight").has("weight", 1).order().by("weight", incr).range(10, 15)), LocalStep.class);
assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight", 1).order().by("weight", incr), TitanVertexStep.class, OrderGlobalStep.class);
assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).order().by("weight", incr).limit(10)), TitanVertexStep.class);
assertNumStep(5, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).has("weight", 1).order().by("weight", incr).range(10, 15)), LocalStep.class);

//Global graph queries
assertNumStep(1, 1, gts.V().has("id", numV / 5), TitanGraphStep.class);
Expand Down Expand Up @@ -3413,15 +3415,13 @@ public void testTinkerPopOptimizationStrategies() {
assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)), TitanGraphStep.class, TitanVertexStep.class);

Traversal t;
TraversalMetrics metrics;
//Verify traversal metrics when all reads are from cache (i.e. no backend queries)
t = gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)).profile();
assertCount(superV * 10, t);
metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
System.out.println(metrics);
verifyMetrics(metrics.getMetrics(0), 0, true);
verifyMetrics(metrics.getMetrics(1), 0, true);
// System.out.println(metrics);

clopen(option(USE_MULTIQUERY), true);
gts = graph.traversal();
Expand All @@ -3430,9 +3430,9 @@ public void testTinkerPopOptimizationStrategies() {
t = gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)).profile();
assertCount(superV * 10, t);
metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
// System.out.println(metrics);
verifyMetrics(metrics.getMetrics(0), 0, false);
verifyMetrics(metrics.getMetrics(1), 0, false);
// System.out.println(metrics);

}

Expand All @@ -3442,9 +3442,10 @@ private static void assertNumStep(int expectedResults, int expectedSteps, GraphT
traversal.next();
num++;
}
// System.out.println(traversal);
assertEquals(expectedResults, num);

// traversal.getStrategies().apply(TraversalEngine.STANDARD);
//Verify that steps line up with what is expected after Titan's optimizations are applied
List<Step> steps = traversal.asAdmin().getSteps();
Set<Class<? extends Step>> expSteps = Sets.newHashSet(expectedStepTypes);
int numSteps = 0;
Expand Down

0 comments on commit 9737d31

Please sign in to comment.