Shrey Gupta
Shrey Gupta

Reputation: 5617

Extensions for Computationally-Intensive Cypher queries

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;

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

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.

Is there any extension I could use to help optimize this query?

Upvotes: 0

Views: 74

Answers (1)

Eve Freeman
Eve Freeman

Reputation: 33175

Give this one a try:

https://github.com/wfreeman/findpaths

You can query the extension like so:

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

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()
}

Upvotes: 1

Related Questions