【问题标题】:How to speed up "global" queries in Titan DB?如何加快 Titan DB 中的“全局”查询?
【发布时间】:2015-02-18 08:52:24
【问题描述】:

我们使用带有 Persistit 的 Titan 作为后端,用于具有大约 100.000 个顶点的图。我们的用例非常复杂,但可以用一个简单的例子来说明当前的问题。假设我们在图中存储 BooksAuthors。每个 Book 顶点都有一个 ISBN 号,对于整个图来说是唯一的。

我需要回答以下问题: 给我图表中所有图书的 ISBN 编号。

目前,我们正在这样做:

// retrieve graph instance
TitanGraph graph = getGraph(); 
// Start a Gremlin query (I omit the generics for brevity here)
GremlinPipeline gremlin = new GremlinPipeline().start(graph);
// get all vertices in the graph which represent books (we have author vertices, too!)
gremlin.V("type", "BOOK");
// the ISBN numbers are unique, so we use a Set here
Set<String> isbnNumbers = new HashSet<String>();
// iterate over the gremlin result and retrieve the vertex property
while(gremlin.hasNext()){
    Vertex v = gremlin.next();
    isbnNumbers.add(v.getProperty("ISBN"));
}
return isbnNumbers;

我的问题是:有没有更聪明的方法可以更快地做到这一点?我是 Gremlin 的新手,所以很可能我在这里做了一些非常愚蠢的事情。该查询目前需要 2.5 秒,这还不错,但如果可能的话,我想加快速度。请认为后端是固定的。

【问题讨论】:

    标签: titan gremlin tinkerpop


    【解决方案1】:

    我怀疑是否有更快的方法(您总是需要遍历所有书本顶点),但是使用 groovy/gremlin 可以为您的任务提供一个不太冗长的解决方案。 在sample graph 上,您可以运行例如以下查询:

    gremlin> namesOfJaveProjs = []; g.V('lang','java').name.store(namesOfJaveProjs)
    gremlin> namesOfJaveProjs
    ==>lop
    ==>ripple
    

    或为您的图书图表:

    isbnNumbers = []; g.V('type','BOOK').ISBN.store(isbnNumbers)
    

    【讨论】:

    • 感谢您的回答。至少我知道我正在按照它应该做的方式去做。我想我将不得不做一些应用程序级缓存以使其更快,这是一个以读取为主的图表,所以应该没什么大不了的。
    猜你喜欢
    • 2015-12-04
    • 1970-01-01
    • 2016-08-08
    • 2017-10-16
    • 1970-01-01
    • 2014-11-25
    • 2022-08-13
    • 2016-08-05
    • 2015-09-14
    相关资源
    最近更新 更多