use of org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.HARD_MAX_LIMIT in project janusgraph by JanusGraph.
the class JanusGraphTest method testGraphCentricQueryProfilingWithLimitAdjusting.
@Test
public void testGraphCentricQueryProfilingWithLimitAdjusting() throws BackendException {
Runnable dataLoader = () -> {
final PropertyKey name = makeKey("name", String.class);
final JanusGraphIndex compositeNameIndex = mgmt.buildIndex("nameIdx", Vertex.class).addKey(name).buildCompositeIndex();
finishSchema();
newTx();
for (int i = 0; i < 3000; i++) {
tx.addVertex("name", "bob");
}
tx.commit();
};
clopen(option(ADJUST_LIMIT), false, option(HARD_MAX_LIMIT), 100000);
dataLoader.run();
newTx();
Metrics mCompSingle = tx.traversal().V().has("name", "bob").profile().next().getMetrics(0);
assertEquals(2, mCompSingle.getNested().size());
Metrics nested = (Metrics) mCompSingle.getNested().toArray()[1];
Map<String, String> nameIdxAnnotations = new HashMap() {
{
put("condition", "(name = bob)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
// 100000 is HARD_MAX_LIMIT
put("query", "multiKSQ[1]@100000");
put("index", "nameIdx");
}
};
assertEquals(nameIdxAnnotations, nested.getAnnotations());
List<Metrics> backendQueryMetrics = nested.getNested().stream().map(m -> (Metrics) m).collect(Collectors.toList());
assertEquals(1, backendQueryMetrics.size());
Map<String, String> backendAnnotations = new HashMap() {
{
put("query", "nameIdx:multiKSQ[1]@100000");
put("limit", 100000);
}
};
assertEquals(backendAnnotations, backendQueryMetrics.get(0).getAnnotations());
assertTrue(backendQueryMetrics.get(0).getDuration(TimeUnit.MICROSECONDS) > 0);
close();
JanusGraphFactory.drop(graph);
clopen(option(ADJUST_LIMIT), false, option(HARD_MAX_LIMIT), Integer.MAX_VALUE);
dataLoader.run();
newTx();
mCompSingle = tx.traversal().V().has("name", "bob").profile().next().getMetrics(0);
assertEquals(2, mCompSingle.getNested().size());
nested = (Metrics) mCompSingle.getNested().toArray()[1];
nameIdxAnnotations = new HashMap() {
{
put("condition", "(name = bob)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", "multiKSQ[1]");
put("index", "nameIdx");
}
};
assertEquals(nameIdxAnnotations, nested.getAnnotations());
backendQueryMetrics = nested.getNested().stream().map(m -> (Metrics) m).collect(Collectors.toList());
assertEquals(1, backendQueryMetrics.size());
backendAnnotations = new HashMap() {
{
put("query", "nameIdx:multiKSQ[1]");
}
};
assertEquals(backendAnnotations, backendQueryMetrics.get(0).getAnnotations());
assertTrue(backendQueryMetrics.get(0).getDuration(TimeUnit.MICROSECONDS) > 0);
close();
JanusGraphFactory.drop(graph);
clopen(option(ADJUST_LIMIT), true);
dataLoader.run();
newTx();
mCompSingle = tx.traversal().V().has("name", "bob").profile().next().getMetrics(0);
assertEquals("JanusGraphStep([],[name.eq(bob)])", mCompSingle.getName());
assertTrue(mCompSingle.getDuration(TimeUnit.MICROSECONDS) > 0);
assertEquals(2, mCompSingle.getNested().size());
nested = (Metrics) mCompSingle.getNested().toArray()[0];
assertEquals(QueryProfiler.CONSTRUCT_GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nested = (Metrics) mCompSingle.getNested().toArray()[1];
assertEquals(QueryProfiler.GRAPH_CENTRIC_QUERY, nested.getName());
assertTrue(nested.getDuration(TimeUnit.MICROSECONDS) > 0);
nameIdxAnnotations = new HashMap() {
{
put("condition", "(name = bob)");
put("orders", "[]");
put("isFitted", "true");
put("isOrdered", "true");
put("query", "multiKSQ[1]@4000");
put("index", "nameIdx");
}
};
assertEquals(nameIdxAnnotations, nested.getAnnotations());
backendQueryMetrics = nested.getNested().stream().map(m -> (Metrics) m).collect(Collectors.toList());
assertEquals(3, backendQueryMetrics.size());
int limit = 1000;
// due to LimitAdjustingIterator, there are three backend queries with limits 1000, 2000, and 4000, respectively.
for (Metrics backendQueryMetric : backendQueryMetrics) {
int queryLimit = limit;
backendAnnotations = new HashMap() {
{
put("query", "nameIdx:multiKSQ[1]@" + queryLimit);
put("limit", queryLimit);
}
};
assertEquals(backendAnnotations, backendQueryMetric.getAnnotations());
assertTrue(backendQueryMetric.getDuration(TimeUnit.MICROSECONDS) > 0);
limit = limit * 2;
}
}
Aggregations