【发布时间】:2017-02-23 15:58:11
【问题描述】:
titan-0.5.4中大约有10,000,000条记录(存储后端是hbase和es索引),我只想找到特定圆圈内的顶点并且还有标签“shop”。查询(查询成本)运行大约 1 秒,但获取顶点(迭代器成本)花费了太多时间。我想知道泰坦如何处理以下多种情况:
long start = System.currentTimeMillis();
Iterator<Vertex> iterator = graph.query().has("geo",Geo.WITHIN, circle(40, 116, 15)).has("label","shop").vertices().iterator();
long end = System.currentTimeMillis();
System.out.println("query cost(ms):" + (end - start));
Set<Vertex> targetVertices = new HashSet<Vertex>();
start = System.currentTimeMillis();
while (iterator.hasNext()){
targetVertices.add(iterator.next());
}
end = System.currentTimeMillis();
System.out.println("iterator cost(ms):" + (end - start));
System.out.println("vertices count): " + targetVertices.size());
为什么这么慢,如何提高查询性能?
【问题讨论】:
-
如果
query cost(ms)是1秒,那么iteration cost(ms)和vertices count是什么? -
像上面的代码一样,我只是在很长一段时间内(可能是 20 分钟)都无法得到结果。但是当我第一次只是使用循环条件,然后使用迭代器过滤“商店”标签时。而迭代器耗时约80s,圆条件得到约60000个顶点,有效顶点为100个。这是否证明标签条件不是基于圆条件?
-
您是否使用
geo和label键定义了索引?类似mgmt.buildIndex('geoAndLabel',Vertex.class).addKey(geo).addKey(label).buildMixedIndex("search")s3.thinkaurelius.com/docs/titan/0.5.4/indexes.html#index-mixed -
是的,我做到了。如果没有索引,则会打印警告。