计算密集型Cypher查询的扩展 [英] Extensions for Computationally-Intensive Cypher queries

查看:116
本文介绍了计算密集型Cypher查询的扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为对我之前的问题的跟踪,我想找到所有30条存在于深度为4的两个给定节点之间.

As a follow up to a previous question of mine, I want to find all 30 pathways that exist between two given nodes within a depth of 4. Something to the effect of this:

start startnode = node(1), endnode(1000)
match startnode-[r:rel_Type*1..4]->endnode
return r
limit 30;

我的数据库包含约5万个节点和2M关系.

My database contains ~50k nodes and 2M relationships.

预计,此查询的计算时间非常非常大;我什至以message.log文件中的以下GC消息结尾:GC Monitor: Application threads blocked for an additional 14813ms [total block time: 182.589s].该错误不断发生,并无限期地阻塞所有线程.因此,我正在寻找一种通过优化查询来降低服务器上该查询的计算负担的方法.

Expectedly, the computation time for this query is very, very large; I even ended up with the following GC message in the message.log file: GC Monitor: Application threads blocked for an additional 14813ms [total block time: 182.589s]. This error keeps occuring, and blocks all threads for an indefinite period of time. Therefore, I am looking for a way to lower the computational strain of this query on the server by optimizing the query.

我可以使用任何扩展名来优化此查询吗?

推荐答案

尝试一下:

https://github.com/wfreeman/findpaths

您可以像这样查询扩展名:

You can query the extension like so:

.../findpathslen/1/1000/4/30

.../findpathslen/1/1000/4/30

它会给您一个带有找到路径的json响应.希望对您有帮助.

And it will give you a json response with the paths found. Hopefully that helps you.

它的实质在这里,使用内置的图形算法来查找特定长度的路径:

The meat of it is here, using the built-in graph algorithm to find paths of a certain length:

@GET
@Path("/findpathslen/{id1}/{id2}/{len}/{count}")
@Produces(Array("application/json"))
def fof(@PathParam("id1") id1:Long, @PathParam("id2") id2:Long, @PathParam("len") len:Int, @PathParam("count") count:Int, @Context db:GraphDatabaseService) = {
  val node1 = db.getNodeById(id1)
  val node2 = db.getNodeById(id2)
  val pathFinder = GraphAlgoFactory.pathsWithLength(Traversal.pathExpanderForAllTypes(Direction.OUTGOING), len) 
  val pathIterator = pathFinder.findAllPaths(node1,node2).asScala
  val jsonMap = pathIterator.take(count).map(p => obj(p))
  Response.ok(compact(render(decompose(jsonMap))), MediaType.APPLICATION_JSON).build()
}

这篇关于计算密集型Cypher查询的扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆