Search in sources :

Example 1 with Metrics

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);
        }
    }
}
Also used : Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) ScanMetrics(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)

Example 2 with Metrics

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");
    }
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) JanusGraphAssert.getStepMetrics(org.janusgraph.testutil.JanusGraphAssert.getStepMetrics) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Metrics

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());
}
Also used : Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics)

Example 4 with Metrics

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());
}
Also used : JanusGraphAssert.getStepMetrics(org.janusgraph.testutil.JanusGraphAssert.getStepMetrics) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) HashMap(java.util.HashMap) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) PropertyKey(org.janusgraph.core.PropertyKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 5 with Metrics

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);
        }
    }
}
Also used : Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics)

Aggregations

Metrics (org.apache.tinkerpop.gremlin.process.traversal.util.Metrics)10 TraversalMetrics (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics)10 ScanMetrics (org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics)6 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)5 JanusGraphAssert.getStepMetrics (org.janusgraph.testutil.JanusGraphAssert.getStepMetrics)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 HashMap (java.util.HashMap)4 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)4 PropertyKey (org.janusgraph.core.PropertyKey)4 Test (org.junit.jupiter.api.Test)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 NotImplementedException (org.apache.commons.lang.NotImplementedException)2 Direction (org.apache.tinkerpop.gremlin.structure.Direction)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)2 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)2 AbstractEdge (org.janusgraph.graphdb.relations.AbstractEdge)2 CacheVertex (org.janusgraph.graphdb.vertices.CacheVertex)2 Preconditions (com.google.common.base.Preconditions)1