use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project titan by thinkaurelius.
the class TitanGraphTest method verifyMetrics.
private static void verifyMetrics(Metrics metric, boolean fromCache, boolean multiQuery) {
assertTrue(metric.getDuration(TimeUnit.MICROSECONDS) > 0);
assertTrue(metric.getCount(TraversalMetrics.ELEMENT_COUNT_ID) > 0);
String hasMultiQuery = (String) metric.getAnnotation(QueryProfiler.MULTIQUERY_ANNOTATION);
assertTrue(multiQuery ? hasMultiQuery.equalsIgnoreCase("true") : hasMultiQuery == null);
for (Metrics submetric : metric.getNested()) {
assertTrue(submetric.getDuration(TimeUnit.MICROSECONDS) > 0);
switch(submetric.getName()) {
case "optimization":
assertNull(submetric.getCount(TraversalMetrics.ELEMENT_COUNT_ID));
break;
case "backend-query":
if (fromCache)
assertFalse("Should not execute backend-queries when cached", true);
assertTrue(submetric.getCount(TraversalMetrics.ELEMENT_COUNT_ID) > 0);
break;
default:
assertFalse("Unrecognized nested query: " + submetric.getName(), true);
}
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphTest method testBatchPropertiesPrefetching.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 10, 15, Integer.MAX_VALUE })
public void testBatchPropertiesPrefetching(int txCacheSize) {
boolean inmemoryBackend = getConfig().get(STORAGE_BACKEND).equals("inmemory");
int numV = 10;
int expectedVerticesPrefetch = Math.min(txCacheSize, numV);
JanusGraphVertex mainVertex = graph.addVertex("id", 0);
for (int i = 1; i <= numV; i++) {
JanusGraphVertex adjacentVertex = graph.addVertex("id", i);
mainVertex.addEdge("knows", adjacentVertex);
}
graph.tx().commit();
if (!inmemoryBackend) {
clopen(option(BATCH_PROPERTY_PREFETCHING), true, option(TX_CACHE_SIZE), txCacheSize);
}
GraphTraversalSource gts = graph.traversal();
TraversalMetrics traversalMetrics = gts.V().has("id", 0).out("knows").has("id", P.within(4, 5, 6, 7)).values("id").profile().next();
Metrics janusGraphVertexStepMetrics = getStepMetrics(traversalMetrics, JanusGraphVertexStep.class);
assertNotNull(janusGraphVertexStepMetrics);
if (expectedVerticesPrefetch > 1 && !inmemoryBackend) {
assertContains(janusGraphVertexStepMetrics, "multiPreFetch", "true");
assertContains(janusGraphVertexStepMetrics, "vertices", expectedVerticesPrefetch);
} else {
assertNotContains(janusGraphVertexStepMetrics, "multiPreFetch", "true");
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method checkMixedIndexCountProfiling.
private void checkMixedIndexCountProfiling(TraversalMetrics profile, Map<String, String> annotations) {
Metrics metrics = profile.getMetrics(0);
assertTrue(metrics.getDuration(TimeUnit.MICROSECONDS) > 0);
assertTrue(metrics.getName().contains(JanusGraphMixedIndexCountStep.class.getSimpleName()));
Metrics nested = (Metrics) metrics.getNested().toArray()[0];
assertEquals(QueryProfiler.MIXED_INEX_COUNT_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(annotations, nested.getAnnotations());
}
use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphTest method testVertexCentricQueryProfiling.
@Test
public void testVertexCentricQueryProfiling() {
final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
final EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.SIMPLE).make();
mgmt.buildEdgeIndex(friend, "byTime", OUT, desc, time);
finishSchema();
JanusGraphVertex v = tx.addVertex();
JanusGraphVertex o = tx.addVertex();
v.addEdge("friend", o, "time", 100);
v.addEdge("friend-no-index", o, "time", 100);
tx.commit();
// satisfied by a single vertex-centric query which is satisfied by one edge query
newTx();
Metrics mSingleLabel = tx.traversal().V(v).outE("friend").has("time", P.lt(10)).profile().next().getMetrics(1);
assertEquals("JanusGraphVertexStep([time.lt(10)])", mSingleLabel.getName());
assertTrue(mSingleLabel.getDuration(TimeUnit.MICROSECONDS) > 0);
Map<String, String> annotations = new HashMap() {
{
put("condition", "(time < 10 AND type[friend])");
put("orders", "[]");
put("vertices", 1);
put("isFitted", "true");
put("isOrdered", "true");
put("query", "2069:byTime:SliceQuery[0xB0E0FF7FFFFFF6,0xB0E1)");
}
};
mSingleLabel.getAnnotations().remove("percentDur");
assertEquals(annotations, mSingleLabel.getAnnotations());
// satisfied by a single vertex-centric query which is satisfied by union of two edge queries
newTx();
Metrics mMultiLabels = tx.traversal().V(v).outE("friend", "friend-no-index").has("time", 100).profile().next().getMetrics(1);
assertEquals("JanusGraphVertexStep([time.eq(100)])", mMultiLabels.getName());
assertTrue(mMultiLabels.getDuration(TimeUnit.MICROSECONDS) > 0);
annotations = new HashMap() {
{
put("condition", "(time = 100 AND (type[friend] OR type[friend-no-index]))");
put("orders", "[]");
put("vertices", 1);
}
};
mMultiLabels.getAnnotations().remove("percentDur");
assertEquals(annotations, mMultiLabels.getAnnotations());
assertEquals(3, mMultiLabels.getNested().size());
Metrics friendMetrics = (Metrics) mMultiLabels.getNested().toArray()[1];
assertEquals("OR-query", friendMetrics.getName());
// FIXME: assertTrue(friendMetrics.getDuration(TimeUnit.MICROSECONDS) > 0);
annotations = new HashMap() {
{
put("isFitted", "true");
put("isOrdered", "true");
// vertex-centric index utilized
put("query", "2069:byTime:SliceQuery[0xB0E0FF7FFFFF9B,0xB0E0FF7FFFFF9C)");
}
};
assertEquals(annotations, friendMetrics.getAnnotations());
Metrics friendNoIndexMetrics = (Metrics) mMultiLabels.getNested().toArray()[2];
assertEquals("OR-query", friendNoIndexMetrics.getName());
// FIXME: assertTrue(friendNoIndexMetrics.getDuration(TimeUnit.MICROSECONDS) > 0);
annotations = new HashMap() {
{
put("isFitted", "false");
put("isOrdered", "true");
// no vertex-centric index found
put("query", "friend-no-index:SliceQuery[0x7180,0x7181)");
}
};
assertEquals(annotations, friendNoIndexMetrics.getAnnotations());
}
use of org.apache.tinkerpop.gremlin.process.traversal.util.Metrics in project janusgraph by JanusGraph.
the class JanusGraphTest method verifyMetrics.
private static void verifyMetrics(Metrics metric, boolean fromCache, boolean multiQuery) {
assertTrue(metric.getDuration(TimeUnit.MICROSECONDS) > 0);
assertTrue(metric.getCount(TraversalMetrics.ELEMENT_COUNT_ID) > 0);
String hasMultiQuery = (String) metric.getAnnotation(QueryProfiler.MULTIQUERY_ANNOTATION);
assertTrue(multiQuery ? hasMultiQuery.equalsIgnoreCase("true") : hasMultiQuery == null);
for (Metrics subMetric : metric.getNested()) {
assertTrue(subMetric.getDuration(TimeUnit.MICROSECONDS) > 0);
switch(subMetric.getName()) {
case "optimization":
assertNull(subMetric.getCount(TraversalMetrics.ELEMENT_COUNT_ID));
break;
case "backend-query":
if (fromCache)
assertFalse("Should not execute backend-queries when cached", true);
assertTrue(subMetric.getCount(TraversalMetrics.ELEMENT_COUNT_ID) > 0);
break;
default:
assertFalse("Unrecognized nested query: " + subMetric.getName(), true);
}
}
}
Aggregations